+
    Q(i                         R t ^ RIHt ^ RIHt ^ RIHtHt ^ RIH	t	 ^ RI
HtHtHtHt ^ RI
Ht RtRtR	tRR R lltRR R lltR R ltR R lt. ROtR
# )a  OpenTelemetry instrumentation for FastMCP.

This module provides native OpenTelemetry integration for FastMCP servers and clients.
It uses only the opentelemetry-api package, so telemetry is a no-op unless the user
installs an OpenTelemetry SDK and configures exporters.

Example usage with SDK:
    ```python
    from opentelemetry import trace
    from opentelemetry.sdk.trace import TracerProvider
    from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor

    # Configure the SDK (user responsibility)
    provider = TracerProvider()
    provider.add_span_processor(SimpleSpanProcessor(ConsoleSpanExporter()))
    trace.set_tracer_provider(provider)

    # Now FastMCP will emit traces
    from fastmcp import FastMCP
    mcp = FastMCP("my-server")
    ```
)Any)context)	propagatetrace)Context)SpanStatus
StatusCodeTracer)
get_tracerfastmcptraceparent
tracestateNc                >    V ^8  d   QhR\         R,          R\        /# )   versionNreturn)strr
   )formats   "W/Users/agent/.openclaw/workspace/venv/lib/python3.14/site-packages/fastmcp/telemetry.py__annotate__r   &   s     	: 	:d
 	:f 	:    c                "    \        \        V 4      # )zGet the FastMCP tracer for creating spans.

Args:
    version: Optional version string for the instrumentation

Returns:
    A tracer instance. Returns a no-op tracer if no SDK is configured.
)otel_get_tracerINSTRUMENTATION_NAME)r   s   &r   r   r   &   s     /99r   c                    V ^8  d   QhR\         \        \        3,          R,          R\         \        \        3,          R,          /# r   metaNr   )dictr   r   )r   s   "r   r   r   2   s6      
sCx.4
	#s(^dr   c                    / p\         P                  ! V4       / pRV9   d   VR,          V\        &   RV9   d   VR,          V\        &   V'       d   / T ;'       g    / CVC# V # )a(  Inject current trace context into a meta dict for MCP request propagation.

Args:
    meta: Optional existing meta dict to merge with trace context

Returns:
    A new dict containing the original meta (if any) plus trace context keys,
    or None if no trace context to inject and meta was None
r   r   )r   injectTRACE_PARENT_KEYTRACE_STATE_KEY)r   carrier
trace_metas   &  r   inject_trace_contextr%   2   si     !GW!#J'.}'=
#$w&-l&;
?#-4::2-*--Kr   c                4    V ^8  d   QhR\         R\        RR/# )r   span	exceptionr   N)r   BaseException)r   s   "r   r   r   L   s!     . .D .] .t .r   c                x    V P                  V4       V P                  \        \        P                  4      4       R# )z3Record an exception on a span and set error status.N)record_exception
set_statusr   r	   ERROR)r'   r(   s   &&r   record_span_errorr.   L   s'    )$OOF:++,-r   c                `    V ^8  d   QhR\         \        \        3,          R,          R\        /# r   )r   r   r   r   )r   s   "r   r   r   R   s'     & &S#X 5 &' &r   c                   \         P                  ! 4       pVP                  4       P                  '       d   \        P
                  ! 4       # V '       g   \        P
                  ! 4       # / p\        V 9   d   \        V \        ,          4      VR&   \        V 9   d   \        V \        ,          4      VR&   V'       d   \        P                  ! V4      # \        P
                  ! 4       # )a  Extract trace context from an MCP request meta dict.

If already in a valid trace (e.g., from HTTP propagation), the existing
trace context is preserved and meta is not used.

Args:
    meta: The meta dict from an MCP request (ctx.request_context.meta)

Returns:
    An OpenTelemetry Context with the extracted trace context,
    or the current context if no trace context found or already in a trace
r   r   )r   get_current_spanget_span_contextis_validotel_contextget_currentr!   r   r"   r   extract)r   current_spanr#   s   &  r   extract_trace_contextr8   R   s     ))+L$$&///''))'')) G4!$T*:%;!<$ #D$9 :  ))##%%r   )N)r   r!   r"   r8   r   r%   r.   )__doc__typingr   opentelemetryr   r4   r   r   opentelemetry.contextr   opentelemetry.tracer   r   r	   r
   r   r   r   r!   r"   r%   r.   r8   __all__ r   r   <module>r@      sN   .  1 * ) @ @ =    	:4.&@r   