nat.plugins.opentelemetry.otel_span#
Attributes#
Classes#
Module Contents#
- logger#
- class MimeTypes(*args, **kwds)#
Bases:
enum.EnumMime types for the span.
- TEXT = 'text/plain'#
- JSON = 'application/json'#
- class OtelSpan(
- name: str,
- context: opentelemetry.trace.Context | opentelemetry.trace.SpanContext | None,
- parent: opentelemetry.trace.span.Span | None = None,
- attributes: dict[str, Any] | None = None,
- events: list | None = None,
- links: list | None = None,
- kind: int | opentelemetry.trace.SpanKind | None = None,
- start_time: int | None = None,
- end_time: int | None = None,
- status: opentelemetry.trace.Status | None = None,
- resource: opentelemetry.sdk.resources.Resource | None = None,
- instrumentation_scope: opentelemetry.sdk.trace.InstrumentationScope | None = None,
Bases:
opentelemetry.trace.span.SpanA manually created OpenTelemetry span.
This class is a wrapper around the OpenTelemetry Span class. It provides a more convenient interface for creating and manipulating spans.
- Args:
name (str): The name of the span. context (Context | SpanContext | None): The context of the span. parent (Span | None): The parent span. attributes (dict[str, Any] | None): The attributes of the span. events (list | None): The events of the span. links (list | None): The links of the span. kind (int | None): The kind of the span. start_time (int | None): The start time of the span in nanoseconds. end_time (int | None): The end time of the span in nanoseconds. status (Status | None): The status of the span. resource (Resource | None): The resource of the span. instrumentation_scope (InstrumentationScope | None): The instrumentation scope of the span.
Initialize the OtelSpan with the specified values.
- _name#
- _parent = None#
- _attributes#
- _events = []#
- _links = []#
- _kind#
- _start_time#
- _end_time = None#
- _status#
- _ended = False#
- _resource#
- _instrumentation_scope#
- _dropped_attributes = 0#
- _dropped_events = 0#
- _dropped_links = 0#
- _status_description = None#
- property resource: opentelemetry.sdk.resources.Resource#
Get the resource associated with this span.
- Returns:
Resource: The resource.
- set_resource(resource: opentelemetry.sdk.resources.Resource) None#
Set the resource associated with this span.
- Args:
resource (Resource): The resource to set.
- property instrumentation_scope: opentelemetry.sdk.trace.InstrumentationScope#
Get the instrumentation scope associated with this span.
- Returns:
InstrumentationScope: The instrumentation scope.
- property parent: opentelemetry.trace.span.Span | None#
Get the parent span.
- Returns:
Span | None: The parent span.
- property kind: int | opentelemetry.trace.SpanKind#
Get the kind of the span.
- Returns:
int | SpanKind: The kind of the span.
- property start_time: int#
Get the start time of the span in nanoseconds.
- Returns:
int: The start time of the span in nanoseconds.
- property end_time: int | None#
Get the end time of the span in nanoseconds.
- Returns:
int | None: The end time of the span in nanoseconds.
- property attributes: dict[str, Any]#
Get all attributes of the span.
- Returns:
dict[str, Any]: The attributes of the span.
- property status: opentelemetry.trace.Status#
Get the status of the span.
- Returns:
Status: The status of the span.
- property dropped_attributes: int#
Get the number of dropped attributes.
- Returns:
int: The number of dropped attributes.
- property dropped_events: int#
Get the number of dropped events.
- Returns:
int: The number of dropped events.
- property dropped_links: int#
Get the number of dropped links.
- Returns:
int: The number of dropped links.
- property is_remote: bool#
Get whether this span is remote.
- Returns:
bool: True if the span is remote, False otherwise.
- end(end_time: int | None = None) None#
End the span.
- Args:
end_time (int | None): The end time of the span in nanoseconds.
- is_recording() bool#
Check if the span is recording.
- Returns:
bool: True if the span is recording, False otherwise.
- get_span_context() opentelemetry.trace.SpanContext#
Get the span context.
- Returns:
SpanContext: The span context.
- set_attribute(key: str, value: Any) None#
Set an attribute on the span.
- Args:
key (str): The key of the attribute. value (Any): The value of the attribute.
- set_attributes(attributes: dict[str, Any]) None#
Set multiple attributes on the span.
- Args:
attributes (dict[str, Any]): The attributes to set.
- add_event( ) None#
Add an event to the span.
- Args:
name (str): The name of the event. attributes (dict[str, Any] | None): The attributes of the event. timestamp (int | None): The timestamp of the event in nanoseconds.
- set_status( ) None#
Set the span status.
- Args:
status (Status): The status to set. description (str | None): The description of the status.
- get_end_time() int | None#
Get the end time of the span.
- Returns:
int | None: The end time of the span in nanoseconds.
- get_status() opentelemetry.trace.Status#
Get the status of the span.
- Returns:
Status: The status of the span.
- get_parent() opentelemetry.trace.span.Span | None#
Get the parent span.
- Returns:
Span | None: The parent span.
- record_exception(
- exception: Exception,
- attributes: dict[str, Any] | None = None,
- timestamp: int | None = None,
- escaped: bool = False,
Record an exception on the span.
- Args:
exception: The exception to record attributes: Optional dictionary of attributes to add to the event timestamp: Optional timestamp for the event escaped: Whether the exception was escaped
- copy() OtelSpan#
Create a new OtelSpan instance with the same values as this one. Note that this is not a deep copy - mutable objects like attributes, events, and links will be shared between the original and the copy.
- Returns:
A new OtelSpan instance with the same values
- static _format_attributes(
- attributes: opentelemetry.util.types.Attributes,
- static _format_events(
- events: collections.abc.Sequence[opentelemetry.sdk.trace.Event],
- static _format_links(
- links: collections.abc.Sequence[opentelemetry.trace.Link],