+
    nDj                    2   R t ^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIHtH	t	 ^ RI
HtHtHt ]P                  ! ]4      t]! R]R]3,          R7      t0 RmtR R	 ltR
sR
sR R ltR R ltR R ltR R ltR R lt]P6                  R R l4       tR R ltR# )u  
OpenTelemetry tracing helpers shared across Rerun-based Python code.

Provides [`with_tracing`][rerun._tracing.with_tracing] (decorator) and
[`tracing_scope`][rerun._tracing.tracing_scope] (context manager), which both
create a Python OpenTelemetry span and bridge the trace context into Rerun's
Rust SDK so `#[instrument]` spans on the Rust side become children of the
Python span.

Active only when `TELEMETRY_ENABLED=true` is set in the environment AND an OTLP
endpoint is configured via `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` (or the umbrella
`OTEL_EXPORTER_OTLP_ENDPOINT`). Otherwise both helpers are pass-throughs.

This module is private — external callers should re-export these helpers from
the consumer package rather than importing `rerun._tracing` directly.
)annotationsN)CallableIterator)AnyTypeVarcastF.)boundc                    V ^8  d   QhRRRR/# )   namestrreturnbool )formats   "R/data/cameron/venvs/s3viz/lib/python3.14/site-packages/rerun_sdk/rerun/_tracing.py__annotate__r   "   s     ; ;C ;D ;    c                ~    \         P                  P                  V 4      ;'       g    R P                  4       \        9   # ) )osenvirongetlower_TRUTHY)r   s   &r   	_env_boolr   "   s+    JJNN4 &&B--/7::r   Fc                   V ^8  d   QhRR/# )r   r   Noner   )r   s   "r   r   r   *   s     "j "jD "jr   c                    \         '       d   R# Rs \        R4      '       g   R#  ^ RIHp  ^ RIHp ^ RIHp ^ RIH	p ^ RI
Hp \        P                   P#                  R
4      ;'       g     \        P                   P#                  R4      pT'       g   \        P%                  R4       R# \        P                   P#                  R4      ;'       g    RpT! TP'                  RT/4      R7      pTP)                  T! T! TR7      4      4       T P+                  T4       Rs\        P%                  RYe4       R#   \         d    \        P                  R	4        R# i ; i)zCSet up the Python OTel tracer provider the first time it is needed.NTTELEMETRY_ENABLEDtrace)OTLPSpanExporter)Resource)TracerProvider)BatchSpanProcessorzU`with_tracing` is a no-op: install OpenTelemetry via `pip install rerun-sdk[tracing]`"OTEL_EXPORTER_OTLP_TRACES_ENDPOINTOTEL_EXPORTER_OTLP_ENDPOINTzj`with_tracing` is a no-op: set OTEL_EXPORTER_OTLP_TRACES_ENDPOINT or OTEL_EXPORTER_OTLP_ENDPOINT to enableOTEL_SERVICE_NAMEzrerun-pyzservice.name)resource)endpointz>Python OpenTelemetry tracing enabled (service=%s, endpoint=%s))_initializedr   opentelemetryr"   5opentelemetry.exporter.otlp.proto.grpc.trace_exporterr#   opentelemetry.sdk.resourcesr$   opentelemetry.sdk.tracer%   opentelemetry.sdk.trace.exportr&   ImportErrorloggerwarningr   r   r   infocreateadd_span_processorset_tracer_provider_enabled)r"   r#   r$   r%   r&   r+   service_nameproviders           r   
_init_oncer<   *   s    |L())'Z8:E
 zz~~BCttrzz~~VsGtHx	
 	::>>"56DD*Lx7U'VWH 23CX3V WX	h'H
KKPR^i%  nos   D4 4 EEc                   V ^8  d   QhRR/# )r   r   dict[str, str] | Noner   )r   s   "r   r   r   O   s      4 r   c                     \        4        \        '       g   R# ^ RIHp  ^ RIHp / pV! 4       P                  W P                  4       4       T;'       g    R# )aF  
Capture the current OTel context as a W3C carrier dict.

Returns `None` if tracing is disabled or no context is active. The carrier
is safe to pickle and pass across process boundaries; pair with
[`attach_parent_carrier`][rerun._tracing.attach_parent_carrier] in the child
to make its spans children of the captured context.
Ncontextget_global_textmap)r<   r9   r-   rA   opentelemetry.propagaterC   injectget_current)rA   rC   carriers      r   current_trace_carrierrH   O   sB     L8%: G)<)<)>???dr   c                    V ^8  d   QhRRRR/# )r   rG   r>   r   r   r   )r   s   "r   r   r   d   s     : :#8 :T :r   c                    V '       g   R# \        4        \        '       g   R# ^ RIHp ^ RIHp VP                  V! 4       P                  V 4      4       R# )u  
Attach a W3C carrier as the ambient parent context for the current thread.

All subsequent spans created on this thread (via [`with_tracing`][rerun._tracing.with_tracing]
or otherwise) will be parented under the extracted context. The attachment
is intentionally not detached — call this once per worker thread/process on
entry, typically from `__setstate__` after unpickling.

No-op when `carrier` is `None` or tracing is disabled.
Nr@   rB   )r<   r9   r-   rA   rD   rC   attachextract)rG   rA   rC   s   &  r   attach_parent_carrierrM   d   s8     L8%:NN%'//89r   c                   V ^8  d   QhRR/# )r   r   tuple[Any, Any] | Noner   )r   s   "r   r   r   {   s     - -5 -r   c                 l    ^ RI Hp  V ! 4       pVf   R# \        4       pVf   R# WP                  V4      3# )z
Write the current OTel context into Rerun's `ContextVar` so Rust can read it.

Returns `(context_var, token)` to pass to [`_pop_carrier_from_rust`][], or
`None` if Rust was built without `perf_telemetry` or no OTel context is active.
)_get_trace_context_varN)rerun_bindingsrQ   rH   set)rQ   	trace_ctxrG   s      r   _push_carrier_to_rustrU   {   s:     6&(I#%GmmG,,,r   c                    V ^8  d   QhRRRR/# )r   
attachmentrO   r   r   r   )r   s   "r   r   r      s      '= $ r   c                <    V f   R # V w  rVP                  V4       R # N)reset)rW   rT   tokens   &  r   _pop_carrier_from_rustr\      s    !IOOEr   c                    V ^8  d   QhRRRR/# )r   r   r   r   zIterator[None]r   )r   s   "r   r   r      s     !/ !/ !/ !/r   c              #  2  "   \        4        \        '       g   Rx  R# ^ RIHp VP	                  R4      P                  V 4      ;_uu_ 4        \        4       p Rx  \        V4        RRR4       R#   \        T4       i ; i  + '       g   i     R# ; i5i)u  
Open an OpenTelemetry span for the duration of a `with` block and propagate trace context into Rerun's Rust SDK.

Context-manager counterpart to [`with_tracing`][rerun._tracing.with_tracing] —
use it to scope arbitrary blocks of code without extracting them into a
function. Any Rust-side `#[instrument]` spans triggered from within will be
parented under this span in Jaeger.

No-op unless `TELEMETRY_ENABLED=true` and an OTLP endpoint is configured
(`OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` or `OTEL_EXPORTER_OTLP_ENDPOINT`).

Examples
--------
```python
for epoch in range(num_epochs):
    with tracing_scope(f"epoch {epoch}"):
        train_one_epoch(...)
```

Nr!   rerun)r<   r9   r-   r"   
get_tracerstart_as_current_spanrU   r\   )r   r"   rW   s   &  r   tracing_scoperb      sm     , L8#			'	"	8	8	>	>*,
	/":. 
?	>
 #:. 
?	>	>s6   ABBA3B)
B3B  BB		Bc                    V ^8  d   QhRRRR/# )r   r   r   r   zCallable[[F], F]r   )r   s   "r   r   r      s      s / r   c                   a  R V 3R llpV# )az  
Wrap a function in an OpenTelemetry span and propagate trace context into Rerun's Rust SDK.

When enabled, creates a span named `name`, injects the W3C `traceparent` header into
Rerun's shared `ContextVar`, and runs the wrapped function. Any Rust-side
`#[instrument]` spans triggered from within (e.g. catalog queries) will be
parented under this span in Jaeger.

For ad-hoc blocks that don't belong in a dedicated function, use
[`tracing_scope`][rerun._tracing.tracing_scope] instead.

No-op unless `TELEMETRY_ENABLED=true` and an OTLP endpoint is configured
(`OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` or `OTEL_EXPORTER_OTLP_ENDPOINT`).
c                    V ^8  d   QhRRRR/# )r   funcr   r   r   )r   s   "r   r   "with_tracing.<locals>.__annotate__   s     " " "a "r   c                d   <a  \         P                  ! S 4      R  V V3R ll4       p\        RV4      # )c               $    V ^8  d   QhRRRRRR/# )r   argsr   kwargsr   r   )r   s   "r   r   5with_tracing.<locals>.decorator.<locals>.__annotate__   s!     	- 	-3 	-# 	-# 	-r   c                 x   < \        S4      ;_uu_ 4        S! V / VB uuR R R 4       #   + '       g   i     R # ; irY   )rb   )rj   rk   rf   r   s   *,r   wrapper0with_tracing.<locals>.decorator.<locals>.wrapper   s*    t$$T,V, %$$$s   (9	r   )	functoolswrapsr   )rf   rn   r   s   f r   	decoratorwith_tracing.<locals>.decorator   s2    			- 	- 
	- C!!r   r   )r   rr   s   f r   with_tracingrt      s     " " r   >   1onyestrue)__doc__
__future__r   
contextlibrp   loggingr   collections.abcr   r   typingr   r   r   	getLogger__name__r3   r   r   r   r,   r9   r<   rH   rM   rU   r\   contextmanagerrb   rt   r   r   r   <module>r      s   " #    	 . % %			8	$CxS)*
$; "jJ*:.-( !/ !/Hr   