ó
    Ð]j  ã                  ó  • S r SSKJr  SSKJrJr  SSKJr  SSKJ	r	  SSK
Jr  SSKJrJrJr  SSKJr  SS	KrSS
KJr  \\\4   rSrSS jr\SS	S.       SS jj5       r\	 " S S\5      5       r " S S\5      r\	 " S S\5      5       rg	)a½  This module provides a thin wrapper around the OpenTelemetry propagate API to allow
the OpenTelemetry contexts (and therefore Logfire contexts) to be transferred between
different code running in different threads, processes or even services.

In general, you should not need to use this module since Logfire will automatically
patch [`ThreadPoolExecutor`][concurrent.futures.ThreadPoolExecutor] and
[`ProcessPoolExecutor`][concurrent.futures.ProcessPoolExecutor] to carry over the context.
And existing plugins exist to propagate the context with
[requests](https://pypi.org/project/opentelemetry-instrumentation-requests/) and
[httpx](https://pypi.org/project/opentelemetry-instrumentation-httpx/).
é    )Úannotations)ÚIteratorÚMapping)Úcontextmanager)Ú	dataclass)ÚAny)ÚcontextÚ	propagateÚtrace)ÚTextMapPropagatorN)Úwarn_at_user_stacklevel)Úget_contextÚattach_contextÚContextCarrierc                 ó6   • 0 n [         R                  " U 5        U $ )að  Create a new empty carrier dict and inject context into it.

Returns:
    A new dict with the context injected into it.

Usage:

```py
import logfire

logfire_context = logfire.get_context()

...

# later on in another thread, process or service
with logfire.attach_context(logfire_context):
    ...
```

You could also inject context into an existing mapping like headers with:

```py
import logfire

existing_headers = {'X-Foobar': 'baz'}
existing_headers.update(logfire.get_context())
...
```
)r
   Úinject©Úcarriers    ÚN/home/mande/repo/quber/.venv/lib/python3.13/site-packages/logfire/propagate.pyr   r       s   € ð< !€GÜ×Ò�WÔØ€Nó    F)Úthird_partyÚ
propagatorc             #  óÄ  #   • [         R                  " 5       nUc`  [        R                  " 5       nU(       dD  [	        U[
        [        45      (       a)  UR                  n[	        U[
        [        45      (       a  M)  U(       d   eUR                  U S9n [         R                  " U5        Sv •  [         R                  " U5        g! [         R                  " U5        f = f7f)a®  Attach a context as generated by [`get_context`][logfire.propagate.get_context] to the current execution context.

Since `attach_context` is a context manager, it restores the previous context when exiting.

Set `third_party` to `True` if using this inside a library intended to be used by others.
This will respect the [`distributed_tracing` argument of `logfire.configure()`][logfire.configure(distributed_tracing)],
so users will be warned about unintentional distributed tracing by default and they can suppress it.
See [Unintentional Distributed Tracing](https://logfire.pydantic.dev/docs/how-to-guides/distributed-tracing/#unintentional-distributed-tracing) for more information.
Nr   )
Úotel_contextÚget_currentr
   Úget_global_textmapÚ
isinstanceÚ#WarnOnExtractTraceContextPropagatorÚNoExtractTraceContextPropagatorÚwrappedÚextractÚattach)r   r   r   Úold_contextÚnew_contexts        r   r   r   C   s®   é € ô" ×*Ò*Ó,€KØÑÜ×1Ò1Ó3ˆ
ÞÜ˜ZÔ*MÔOnÐ)o×pÑpØ'×/Ñ/�
ô ˜ZÔ*MÔOnÐ)o×pÓpæÐˆ:Ø×$Ñ$¨WÐ$Ð5€Kð)Ü×Ò˜KÔ(Ûä×Ò˜KÕ(øŒ×Ò˜KÕ(üs$   ‚A7C Á;C ÂC Â.C ÃCÃC c                  óH   • \ rS rSr% SrS\S'   S
S jrSS jr\S 5       r	Sr
g	)ÚWrapperPropagatoréc   z-Helper base class to wrap another propagator.r   r    c                ó:   • U R                   R                  " U0 UD6$ ©N)r    r!   ©ÚselfÚargsÚkwargss      r   r!   ÚWrapperPropagator.extracti   s   € Ø�|‰|×#Ò# TÐ4¨VÑ4Ð4r   c                ó:   • U R                   R                  " U0 UD6$ r)   )r    r   r*   s      r   r   ÚWrapperPropagator.injectl   s   € Ø�|‰|×"Ò" DÐ3¨FÑ3Ð3r   c                ó.   • U R                   R                  $ r)   )r    Úfields)r+   s    r   r2   ÚWrapperPropagator.fieldso   s   € à�|‰|×"Ñ"Ð"r   © N)r,   r   r-   r   Úreturnúotel_context.Context)r,   r   r-   r   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotations__r!   r   Úpropertyr2   Ú__static_attributes__r4   r   r   r&   r&   c   s)   ‡ á7àÓô5ô4ð ñ#ó ó#r   r&   c                  óH   ^ • \ rS rSrSr S         SU 4S jjjrSrU =r$ )r   ét   zŸA propagator that ignores any trace context that was extracted by the wrapped propagator.

Used when `logfire.configure(distributed_tracing=False)` is called.
c                ó�   >• [         TU ]  " X/UQ70 UD6nXR:X  a  U$ [        R                  " [        R                  " U5      U5      $ r)   )Úsuperr!   r   Úset_span_in_contextÚget_current_span)r+   r   r	   r,   r-   ÚresultÚ	__class__s         €r   r!   Ú'NoExtractTraceContextPropagator.extractz   sF   ø€ ô ‘’ ÐC°DÒC¸FÑCˆØÓàˆMÜ×(Ò(¬×)?Ò)?ÀÓ)HÈ&ÓQÐQr   r4   r)   ©
r   r   r	   zotel_context.Context | Noner,   r   r-   r   r5   r6   )r7   r8   r9   r:   r;   r!   r>   Ú__classcell__©rF   s   @r   r   r   t   sN   ø† ñð 04ðRàðRð -ðRð ð	Rð
 ðRð 
÷Rö Rr   r   c                  óX   ^ • \ rS rSr% SrSrS\S'    S         S	U 4S jjjrSrU =r	$ )
r   éˆ   zÄA propagator that warns the first time that trace context is extracted by the wrapped propagator.

Used when `logfire.configure(distributed_tracing=None)` is called. This is the default behavior.
FÚboolÚwarnedc                ó  >• [         TU ]  " X/UQ70 UD6nU R                  (       db  XR:w  a]  [        R                  " U5      [        R                  " U5      :w  a/  SU l        Sn[        U[        5        [        R                  " U5        U$ )NTz‹Found propagated trace context. See https://logfire.pydantic.dev/docs/how-to-guides/distributed-tracing/#unintentional-distributed-tracing.)	rB   r!   rN   r   rD   r   ÚRuntimeWarningÚlogfireÚwarn)r+   r   r	   r,   r-   rE   ÚmessagerF   s          €r   r!   Ú+WarnOnExtractTraceContextPropagator.extract‘   sw   ø€ ô ‘’ ÐC°DÒC¸FÑCˆØ�{�{˜vÓ0´U×5KÒ5KÈGÓ5TÔX]×XnÒXnÐouÓXvÓ5vØˆDŒKðzð ô $ G¬^Ô<Ü�LŠL˜Ô!Øˆr   )rN   r)   rH   )
r7   r8   r9   r:   r;   rN   r<   r!   r>   rI   rJ   s   @r   r   r   ˆ   sS   ø‡ ñð
 €FˆDÓð
 04ðàðð -ðð ð	ð
 ðð 
÷ö r   r   )r5   r   )r   r   r   rM   r   zTextMapPropagator | Noner5   zIterator[None])r;   Ú
__future__r   Úcollections.abcr   r   Ú
contextlibr   Údataclassesr   Útypingr   Úopentelemetryr	   r   r
   r   Ú!opentelemetry.propagators.textmapr   rQ   Úlogfire._internal.stack_infor   Ústrr   Ú__all__r   r   r&   r   r   r4   r   r   Ú<module>r_      sÎ   ðñ
õ #ç -Ý %Ý !Ý ç CÑ CÝ ?ã Ý @ð ˜˜c˜Ñ"€à
;€ô ðF ð Ø+/ñ	)Øð)ð ð)ð )ð	)ð
 ô)ó ð)ð> ô#Ð)ó #ó ð#ô RÐ&7ô Rð( ôÐ*;ó ó ñr   