nat.plugins.opentelemetry.otel_span_exporter#
Attributes#
Classes#
Processor that converts a Span to an OtelSpan. |
|
Processor that batches OtelSpans with explicit type information. |
|
Abstract base class for OpenTelemetry exporters. |
Functions#
Get the OpenTelemetry SDK version dynamically. |
Module Contents#
- logger#
- get_opentelemetry_sdk_version() str#
Get the OpenTelemetry SDK version dynamically.
- Returns:
The version of the opentelemetry-sdk package, or ‘unknown’ if not found.
- class SpanToOtelProcessor#
Bases:
nat.observability.processor.processor.Processor[nat.data_models.span.Span,nat.plugins.opentelemetry.otel_span.OtelSpan]Processor that converts a Span to an OtelSpan.
- async process(
- item: nat.data_models.span.Span,
Process an item and return a potentially different type.
- Args:
item (InputT): The item to process
- Returns:
OutputT: The processed item
- class OtelSpanBatchProcessor(
- batch_size: int = 100,
- flush_interval: float = 5.0,
- max_queue_size: int = 1000,
- drop_on_overflow: bool = False,
- shutdown_timeout: float = 10.0,
Bases:
nat.observability.processor.batching_processor.BatchingProcessor[nat.plugins.opentelemetry.otel_span.OtelSpan]Processor that batches OtelSpans with explicit type information.
This class provides explicit type information for the TypeIntrospectionMixin by overriding the type properties directly.
- class OtelSpanExporter(
- context_state: nat.builder.context.ContextState | None = None,
- batch_size: int = 100,
- flush_interval: float = 5.0,
- max_queue_size: int = 1000,
- drop_on_overflow: bool = False,
- shutdown_timeout: float = 10.0,
- resource_attributes: dict[str, str] | None = None,
Bases:
nat.observability.exporter.span_exporter.SpanExporter[nat.data_models.span.Span,nat.plugins.opentelemetry.otel_span.OtelSpan]Abstract base class for OpenTelemetry exporters.
This class provides a specialized implementation for OpenTelemetry exporters. It builds upon SpanExporter’s span construction logic and automatically adds a SpanToOtelProcessor to transform Span objects into OtelSpan objects.
The processing flow is: IntermediateStep → Span → OtelSpan → Export
Key Features: - Automatic span construction from IntermediateStep events (via SpanExporter) - Built-in Span to OtelSpan conversion (via SpanToOtelProcessor) - Support for additional processing steps if needed - Type-safe processing pipeline with enhanced TypeVar compatibility - Batching support for efficient export
Inheritance Hierarchy: - BaseExporter: Core functionality + TypeIntrospectionMixin - ProcessingExporter: Processor pipeline support - SpanExporter: Span creation and lifecycle management - OtelExporter: OpenTelemetry-specific span transformation
Generic Types: - InputSpanT: Always Span (from IntermediateStep conversion) - OutputSpanT: Always OtelSpan (for OpenTelemetry compatibility)
Initialize the OpenTelemetry exporter.
- Args:
context_state: The context state to use for the exporter. batch_size: The batch size for exporting spans. flush_interval: The flush interval in seconds for exporting spans. max_queue_size: The maximum queue size for exporting spans. drop_on_overflow: Whether to drop spans on overflow. shutdown_timeout: The shutdown timeout in seconds. resource_attributes: Additional resource attributes for spans.
- _resource#
- async export_processed(
- item: nat.plugins.opentelemetry.otel_span.OtelSpan | list[nat.plugins.opentelemetry.otel_span.OtelSpan],
Export the processed span(s).
This method handles the common logic for all OTEL exporters: - Normalizes single spans vs. batches - Sets resource attributes on spans - Delegates to the abstract export_otel_spans method
- Args:
- item (OtelSpan | list[OtelSpan]): The processed span(s) to export.
Can be a single span or a batch of spans from BatchingProcessor.