You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
add tracing instrumentation to the pyo3 layer through ContextVars (#12026)
### What
As part of benchmark testing, we'd like to be able to have a single e2e
trace for each benchmark test. In order to do so, we need to pass trace
context across pyo3 boundary and it seems (per Gemini) that the
recommended way to do this is through ``ContextVar``s which is what
standard tracing libraries in python do.
This PR leverages that and adds a context extraction logic as well as an
API (per @abey79 suggestion) to the rerun sdk so that we can easily
access this trace context var and set it on the python side.
For now I've focused on the query paths and we can see both query and
fetching phase under a single trace thanks to changes in the dataframe
table provider and trace propagation between query execution phases.
Follow up will add instrumentation to the register and index creation
paths.
Example usage:
```
from rerun.catalog import _rerun_trace_context
from opentelemetry import context
from opentelemetry.propagate import get_global_textmap
trace_ctx = _rerun_trace_context()
with tracer.start_as_current_span("sample_index_values") as span:
# Add attributes to help identify this benchmark
span.set_attribute("benchmark.name", "sample_index_values")
span.set_attribute("dataset.name", self.dataset_name)
span.set_attribute("sample_count", 6)
wrist = self.dataset.dataframe_query_view(
index="log_tick",
contents="/camera/wrist/embedding /thumbnail/camera/wrist",
)
sampled_times = [0, 100, 200, 500, 1000, 2000]
current_ctx = context.get_current()
carrier = {}
get_global_textmap().inject(carrier, current_ctx)
if carrier:
token = trace_ctx.set(carrier)
result = (
(wrist.filter_index_values(sampled_times).fill_latest_at()).df().drop("rerun_partition_id").collect()
)
if carrier:
trace_ctx.reset(token)
span.set_attribute("result_rows", len(result))
``
0 commit comments