pyo3-python-tracing-subscriber
A tracing_subscriber
layer for native extensions that forwards tracing
data to a Python handler.
See the demo
folder for a working example.
Usage
Native extensions that use tracing
can expose a function to Python to initialize tracing
:
Python code can pass an implementation of tracing_subscriber::layer::Layer
(but slightly different) into initialize_tracing
and then future calls to instrumented Rust functions will forward tracing data to the Python layer.
pass
# `on_new_span` can return some state
return
# The state from `on_new_span` is passed back into other trait methods
Only a subset of Layer
trait methods are currently forwarded to Python.
Native extension quirks
Native extensions are self-contained with their own global variables and copies of dependencies. Because of this:
- Each native extension needs to initialize
tracing
separately to forward its data to Python pyo3-python-tracing-subscriber
itself is not a native extension and can't be used from Python- This is because the compiled code in its own native extension wouldn't be guaranteed to be ABI-compatible with the compiled code included in other native extensions that want to use it
- If
pyo3
+tracing_subscriber
support trait objects then this can change
Contributing
Test with:
$ cargo test