xjM zddlmZddlZddlZddlZddlZddlZddlZddl m Z m Z m Z ddl mZmZddlmZdZej$eZdZej$eZdZej$d Zej$d ed ed Zej2eZd d ZGddej:ZGddeZ e jCZ"Gdde e#e#fZ$e$jCZ%ddzdz Z&dZ'Gdde(eee)dde)fZ*GddeZ+dZ,dZ-e*e-e,de"e%Z.e+e.Z/d!dZ0d"dZ1y)#) annotationsN)IteratorMappingSequence)Status StatusCode)typeszU[a-z][_0-9a-z\-\*\/]{0,255}|[a-z0-9][_0-9a-z\-\*\/]{0,240}@[a-z][_0-9a-z\-\*\/]{0,13}zA[\x20-\x2b\x2d-\x3c\x3e-\x7e]{0,255}[\x21-\x2b\x2d-\x3c\x3e-\x7e] z [ \t]*,[ \t]*(z)(=)(z)[ ]*ct|txrBtj|duxr)t|txrtj|duSN) isinstancestr _KEY_PATTERN fullmatch_VALUE_PATTERN)keyvalues l/mnt/ssd/data/Dropbox/adrian/sandbox/mcp-query/venv/lib/python3.12/site-packages/opentelemetry/trace/span.py_is_valid_pairr5sR3 8  " "3 't 3 8 uc " 8  $ $U +4 7 ceZdZdZej dddZej ddZej ddZej ddZ ej d ddZ d ddZ ej dd Z ej dd Z ej d dd Zej d dd Zdd Z ddZy)Spanz4A span represents a single operation within a trace.Ncy)a Sets the current time as the span's end time. The span's end time is the wall time at which the operation finished. Only the first call to `end` should modify the span, and implementations are free to ignore or raise on further calls. Nselfend_times rendzSpan.endArcy)aGets the span's SpanContext. Get an immutable, serializable identifier for this span that can be used to create new child spans. Returns: A :class:`opentelemetry.trace.SpanContext` with a copy of this span's immutable state. Nrrs rget_span_contextzSpan.get_span_contextKr rcy)aSets Attributes. Sets Attributes with the key and value passed as arguments dict. Note: The behavior of `None` value attributes is undefined, and hence strongly discouraged. It is also preferred to set attributes at span creation, instead of calling this method later since samplers can only consider information already present during span creation. Nrr attributess rset_attributeszSpan.set_attributesVr rcy)aSets an Attribute. Sets a single Attribute with the key and value passed as arguments. Note: The behavior of `None` value attributes is undefined, and hence strongly discouraged. It is also preferred to set attributes at span creation, instead of calling this method later since samplers can only consider information already present during span creation. Nrrrrs r set_attributezSpan.set_attributedr rcy)zAdds an `Event`. Adds a single `Event` with the name and, optionally, a timestamp and attributes passed as arguments. Implementations should generate a timestamp if the `timestamp` argument is omitted. Nrrnamer& timestamps r add_eventzSpan.add_eventpr rc.tjdy)aAdds a `Link`. Adds a single `Link` with the `SpanContext` of the span to link to and, optionally, attributes passed as arguments. Implementations may ignore calls with an invalid span context if both attributes and TraceState are empty. Note: It is preferred to add links at span creation, instead of calling this method later since samplers can only consider information already present during span creation. zsSpan.add_link() not implemented and will be a no-op. Use opentelemetry-sdk >= 1.23 to add links after span creationN)warningswarnrcontextr&s radd_linkz Span.add_link~s   M rcy)zUpdates the `Span` name. This will override the name provided via :func:`opentelemetry.trace.Tracer.start_span`. Upon this update, any sampling behavior based on Span name will depend on the implementation. Nrrr-s r update_namezSpan.update_namer rcy)zReturns whether this span will be recorded. Returns true if this Span is active and recording information like events with the add_event operation and attributes using set_attribute. Nrr"s r is_recordingzSpan.is_recordingr rcy)zbSets the Status of the Span. If used, this will override the default Span status. Nrrstatus descriptions r set_statuszSpan.set_statusr rcy)z%Records an exception as a span event.Nrr exceptionr&r.escapeds rrecord_exceptionzSpan.record_exceptionr rc|S)z^Invoked when `Span` is used as a context manager. Returns the `Span` itself. rr"s r __enter__zSpan.__enter__s  rc$|jy)z3Ends context manager and calls `end` on the `Span`.N)r)rexc_typeexc_valexc_tbs r__exit__z Span.__exit__s   rr r int | NonereturnNonerN SpanContextr&z"Mapping[str, types.AttributeValue]rNrOrrrztypes.AttributeValuerNrONNr-rr&types.Attributesr.rMrNrOr4rQr&rVrNrOr-rrNrOrNboolr=zStatus | StatusCoder>z str | NonerNrONNF rB BaseExceptionr&rVr.rMrCrZrNrO)rNr)rHztype[BaseException] | NonerIzBaseException | NonerJz!python_types.TracebackType | NonerNrO)__name__ __module__ __qualname____doc__abcabstractmethodrr#r'r*r/r5r8r:r?rDrFrKrrrrr>s>        <            (, $    %        (,  %    *       #' #        (, $ 4 4%4 4  4  44,&2   rrcReZdZdZdZdZdZed dZe d dZ e d dZ y) TraceFlagsaA bitmask that represents options specific to the trace. Supported flags: - "sampled" (``0x01``): Indicates the trace may have been sampled upstream. - "random-trace-id" (``0x02``): Indicates the trace ID was generated randomly, with at least the 7 rightmost bytes (56 bits) selected with uniform distribution. See the `W3C Trace Context - Traceparent`_ spec for details. .. _W3C Trace Context - Traceparent: https://www.w3.org/TR/trace-context-2/#trace-flags rc&||jSr )DEFAULTclss r get_defaultzTraceFlags.get_defaults3;;rc:t|tjzSr )rZrfSAMPLEDr"s rsampledzTraceFlags.sampledsD:---..rc:t|tjzSr )rZrfRANDOM_TRACE_IDr"s rrandom_trace_idzTraceFlags.random_trace_idsD:55566rNrNrfrY) r_r`rarbrjrorr classmethodrmpropertyrprsrrrrfrfsR GGO  //77rrfceZdZdZ d ddZddZddZddZddZddZ dd Z dd Z dd Z dd Z edd ZeddZddZddZddZy) TraceStateaA list of key-value pairs representing vendor-specific trace info. Keys and values are strings of up to 256 printable US-ASCII characters. Implementations should conform to the `W3C Trace Context - Tracestate`_ spec, which describes additional restrictions on valid field values. .. _W3C Trace Context - Tracestate: https://www.w3.org/TR/trace-context/#tracestate-field Nc6i|_|yt|tkDrtj dty|D]]\}}t ||r5||jvrtj d|7||j|<Gtj d||_y)Nz,There can't be more than %s key/value pairs.zDuplicate key: %s found.&Invalid key/value pair (%s, %s) found.)_dictlen%_TRACECONTEXT_MAXIMUM_TRACESTATE_KEYS_loggerwarningr)rentriesrrs r__init__zTraceState.__init__s ?  w<? ? OO>5  ! JCc5)$**$OO$>D"' 3z'TraceState.to_header..ysOjc5c E)Os)joinr{rr"s r to_headerzTraceState.to_headerrs&xxODJJ%2%*P$($(L!"#rrxrhrglceZdZdZeef ddZ ddZeddZ eddZ eddZ eddZ eddZ edd Zdd Zdd Zdd Zy )rQaThe state of a Span to propagate between processes. This class includes the immutable attributes of a :class:`.Span` that must be propagated to a span's children and across process boundaries. Args: trace_id: The ID of the trace that this span belongs to. span_id: This span's ID. is_remote: True if propagated from a remote parent. trace_flags: Trace options to propagate. trace_state: Tracing-system-specific info to propagate. c |t}|t}t|cxkxr tkncxrt|cxkxr t knc}t j|||||||fSr )DEFAULT_TRACE_OPTIONSDEFAULT_TRACE_STATEINVALID_TRACE_ID_TRACE_ID_MAX_VALUEINVALID_SPAN_ID_SPAN_ID_MAX_VALUEtuple__new__)rltrace_idspan_id is_remote trace_flags trace_stateis_valids rrzSpanContext.__new__si  /K  -K x >+> > @'?-??  }}  w ; X N  rct|j|j|j|j|jfSr rrrrrr"s r__getnewargs__zSpanContext.__getnewargs__s5 MM LL NN         rc |dS)Nrrr"s rrzSpanContext.trace_id Awrc |dS)Nrgrr"s rrzSpanContext.span_idrrc |dS)Nrhrr"s rrzSpanContext.is_remoterrc |dS)Nrr"s rrzSpanContext.trace_flagsrrc |dS)Nrr"s rrzSpanContext.trace_staterrc |dS)Nrr"s rrzSpanContext.is_validrrc2tjddyNz.Immutable type, ignoring call to set attributeT) stack_infor~debugrargss r __setattr__zSpanContext.__setattr__ <  rc2tjddyrrrs r __delattr__zSpanContext.__delattr__rrc t|jdt|jdt |j d|j dd|jd|jd S)Nz (trace_id=0xz , span_id=0xz, trace_flags=0x02xz, trace_state=z , is_remote=)) typer_format_trace_idrformat_span_idrrrrr"s rrzSpanContext.__repr__st*%%&l?4==3Q2RR^_mnrnznz_{^|}MNRN^N^_bMccqrvrBrBqEEQRVR`R`Qaabc crN) rrrrrrZrzTraceFlags | NonerzTraceState | NonerNrQ)rNz-tuple[int, int, bool, TraceFlags, TraceState]rrYrtr)rrrNrOr)r_r`rarbrrrrrvrrrrrrrrrrrrrQrQs $*?)<      '  '    .  6    crrQceZdZdZddZddZddZdddZ ddZddZ d dd Z d dd Z dd Z d dd Z d dd ZddZy)NonRecordingSpanz~The Span that is used when no Span implementation is available. All operations are no-op except context propagation. c||_yr _context)rr4s rrzNonRecordingSpan.__init__s  rc|jSr rr"s rr#z!NonRecordingSpan.get_span_contexts }}rcy)NFrr"s rr:zNonRecordingSpan.is_recordingsrNcyr rrs rrzNonRecordingSpan.end rcyr rr%s rr'zNonRecordingSpan.set_attributess rcyr rr)s rr*zNonRecordingSpan.set_attribute"rrcyr rr,s rr/zNonRecordingSpan.add_event%s rcyr rr3s rr5zNonRecordingSpan.add_link- rcyr rr7s rr8zNonRecordingSpan.update_name4rrcyr rr<s rr?zNonRecordingSpan.set_status7rrcyr rrAs rrDz!NonRecordingSpan.record_exception>s rc"d|jdS)NzNonRecordingSpan(rrr"s rrzNonRecordingSpan.__repr__Gs"4=="3155r)r4rQrNrOrPrYr rLrRrSrTrUrWrXr[r\r]r)r_r`rarbrr#r:rr'r*r/r5r8r?rDrrrrrr s    <   (, $   %     (,  %     #' #      (, $    %       6rrFrct|dS)zConvenience trace ID formatting method Args: trace_id: Trace ID int Returns: The trace ID (16 bytes) cast to a 32-character hexadecimal string 032xformat)rs rrrWs (F ##rct|dS)zConvenience span ID formatting method Args: span_id: Span ID int Returns: The span ID (8 bytes) cast to a 16-character hexadecimal string 016xr)rs rrrbs '6 ""r)rrrrrNrZ)rrrNr)rrrNr)2 __future__rrcloggingrr python_typestypingr1collections.abcrrropentelemetry.trace.statusrropentelemetry.util _KEY_FORMATcompiler _VALUE_FORMATrr}rr getLoggerr_r~rABCrrrfrmrrrxrrrrrZrQrrrINVALID_SPAN_CONTEXT INVALID_SPANrrrrrrs#   779$A rzz+& IM*)+%RZZ 01"**q U=/IJ '  H %J377JZ77@#..0#c"#D!,,.fqjSc%S$ lDHIScl=6t=6@%5"  %#  45 $#r