Skip to content

Commit

Permalink
fix: use explicit extension-module features
Browse files Browse the repository at this point in the history
  • Loading branch information
erichulburd committed Jun 4, 2024
1 parent 87c2989 commit 0b65f49
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 9 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ thiserror = "1.0.57"
serde = { version = "1.0.145", features = ["derive"] }
opentelemetry = { version = "0.23.0" }
opentelemetry_sdk = { version = "0.23.0" }
pyo3 = { version = "0.20.0", features = ["macros", "extension-module"] }
pyo3 = { version = "0.20.0", features = ["macros"] }
pyo3-asyncio = { version = "0.20.0", features = ["tokio-runtime"] }
pyo3-build-config = "0.20.0"
rstest = "0.17.0"
Expand Down
2 changes: 2 additions & 0 deletions crates/opentelemetry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ tracing-opentelemetry = { workspace = true }
tracing-subscriber = { workspace = true }

[features]
extension-module = ["pyo3/extension-module"]
default = ["extension-module"]

7 changes: 5 additions & 2 deletions crates/tracing-subscriber/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ rust-version = "1.67.0"

[dependencies]
handlebars = { version = "4.4.0", optional = true }
pyo3 = { workspace = true }
pyo3 = { workspace = true, optional = true }
opentelemetry = { workspace = true }
opentelemetry-otlp = { version = "0.16.0", features = ["grpc-tonic", "trace", "tls-roots"], optional = true }
opentelemetry-proto = { version = "0.6.0", optional = true, features = ["tonic"] }
opentelemetry-stdout = { version = "0.4.0", optional = true, features = ["trace"] }
opentelemetry_sdk = { workspace = true, features = ["rt-tokio", "rt-tokio-current-thread"] }
pyo3-asyncio = { workspace = true, features = ["tokio-runtime"] }
pyo3-asyncio = { workspace = true, features = ["tokio-runtime"], optional = true }
serde = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true, features = ["rt-multi-thread"] }
Expand All @@ -31,6 +31,9 @@ tracing-subscriber = { workspace = true, features = ["env-filter", "fmt", "json"
layer-otel-otlp = ["dep:opentelemetry-otlp", "dep:opentelemetry-proto", "dep:tonic"]
layer-otel-otlp-file = ["dep:opentelemetry-stdout"]
stubs = ["dep:handlebars"]
pyo3 = ["dep:pyo3", "dep:pyo3-asyncio"]
extension-module = ["pyo3", "pyo3/extension-module"]
default = ["extension-module"]

[dev-dependencies]
rstest = { workspace = true }
Expand Down
17 changes: 15 additions & 2 deletions crates/tracing-subscriber/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@
//!
//! # Features
//!
//! * `pyo3` - enables the Python bindings for the tracing subscriber. This feature is enabled by default.
//! * `extension-module` - enables the Python extension module for the tracing subscriber. This feature is enabled by default.
//! * `layer-otel-otlp-file` - exports trace data with `opentelemetry-stdout`. See `crate::layers::otel_otlp_file`.
//! * `layer-otel-otlp` - exports trace data with `opentelemetry-otlp`. See `crate::layers::otel_otlp`.
//! * `stubs` - supports writing stub files in your Python source code from your Rust build scripts. See `crates::stubs`
//! * `stubs` - supports writing stub files in your Python source code from your Rust build scripts. See `crates::stubs`. This should only be used in build scripts with default features disabled.
//!
//! # Requirements and Limitations
//!
Expand Down Expand Up @@ -110,7 +112,8 @@
//!
//! async main():
//! async with Tracing():
//! # do stuff
//!
//! # do stuff
//! pass
//!
//!
Expand All @@ -121,22 +124,31 @@
//! # Related Crates
//!
//! * `pyo3-opentelemetry` - propagates `OpenTelemetry` contexts from Python into Rust.
#[cfg(feature = "pyo3")]
use pyo3::{types::PyModule, PyResult, Python};

#[cfg(feature = "pyo3")]
use self::{
contextmanager::{CurrentThreadTracingConfig, GlobalTracingConfig, TracingContextManagerError},
export_process::{BatchConfig, SimpleConfig, TracingShutdownError, TracingStartError},
};
#[cfg(feature = "pyo3")]
pub use contextmanager::Tracing;

#[cfg(feature = "pyo3")]
pub(crate) mod common;
#[cfg(feature = "pyo3")]
mod contextmanager;
#[cfg(feature = "pyo3")]
mod export_process;
#[cfg(feature = "pyo3")]
pub(crate) mod layers;
#[cfg(feature = "stubs")]
pub mod stubs;
#[cfg(feature = "pyo3")]
pub(crate) mod subscriber;

#[cfg(feature = "pyo3")]
create_init_submodule! {
classes: [
Tracing,
Expand All @@ -152,6 +164,7 @@ create_init_submodule! {
],
}

#[cfg(feature = "pyo3")]
/// Add the tracing submodule to the given module. This will add the submodule to the `sys.modules`
/// dictionary so that it can be imported from Python.
///
Expand Down
2 changes: 1 addition & 1 deletion examples/pyo3-opentelemetry-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ tracing-subscriber = { version = "0.3.17", features = ["env-filter"], optional =
[features]

[build-dependencies]
pyo3-tracing-subscriber = { path = "../../crates/tracing-subscriber", features = ["layer-otel-otlp-file", "layer-otel-otlp", "stubs"] }
pyo3-tracing-subscriber = { path = "../../crates/tracing-subscriber", features = ["layer-otel-otlp-file", "layer-otel-otlp", "stubs"], default-features = false }
pyo3-build-config.workspace = true

0 comments on commit 0b65f49

Please sign in to comment.