Crates.io | pyo3-opentelemetry-macros |
lib.rs | pyo3-opentelemetry-macros |
version | 0.3.4 |
source | src |
created_at | 2023-09-07 20:27:16.42343 |
updated_at | 2024-10-07 22:51:28.512726 |
description | Macro for passing OpenTelemetry context from Python to Rust |
homepage | |
repository | https://github.com/rigetti/pyo3-opentelemetry |
max_upload_size | |
id | 966551 |
size | 25,415 |
pyo3_opentelemetry provides a macro to simply and easily instrument your PyO3 bindings so that OpenTelemetry contexts can be easily passed from a Python caller into a Rust library. The #[pypropagate]
macro instruments your Rust functions for you so that the global Python OpenTelemetry context is shared across the FFI boundary.
#[pypropagate]
attribute, Rust code is unaffected and will not attach the Python OpenTelemetry context.For a complete functioning example, see the
examples/pyo3-opentelemetry-lib/src/lib.rs
example within this crate's repository.
From Rust:
use pyo3_opentelemetry::prelude::*;
use pyo3::prelude::*;
use tracing::instrument;
#[pypropagate]
#[pyfunction]
#[instrument]
fn my_function() {
println!("span \"my_function\" is active and will share the Python OpenTelemetry context");
}
#[pymodule]
fn my_module(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_function(wrap_pyfunction!(my_function, m)?)?;
Ok(())
}
These features require no Python code changes, however, opentelemetry-api must be installed.