otel#
- register(*, project_name=None, batch=False, set_global_tracer_provider=True, headers=None, verbose=True)#
Creates an OpenTelemetry TracerProvider for enabling OpenInference tracing.
For futher configuration, the phoenix.otel module provides drop-in replacements for OpenTelemetry TracerProvider, SimpleSpanProcessor, BatchSpanProcessor, HTTPSpanExporter, and GRPCSpanExporter objects with Phoenix-aware defaults. Documentation on how to configure tracing can be found at https://opentelemetry.io/docs/specs/otel/trace/sdk/.
- Parameters:
endpoint (str, optional) – The collector endpoint to which spans will be exported. If not provided, the PHOENIX_OTEL_COLLECTOR_ENDPOINT environment variable will be used. The export protocol will be inferred from the endpoint.
project_name (str, optional) – The name of the project to which spans will be associated. If not provided, the PHOENIX_PROJECT_NAME environment variable will be used.
batch (bool) – If True, spans will be processed using a BatchSpanprocessor. If False, spans will be processed one at a time using a SimpleSpanProcessor.
set_global_tracer_provider (bool) – If False, the TracerProvider will not be set as the global tracer provider. Defaults to True.
headers (dict, optional) – Optional headers to include in the request to the collector. If not provided, the PHOENIX_CLIENT_HEADERS environment variable will be used.
verbose (bool) – If True, configuration details will be printed to stdout.
- class TracerProvider(*args, endpoint=None, verbose=True, **kwargs)#
Bases:
TracerProvider
An extension of opentelemetry.sdk.trace.TracerProvider with Phoenix-aware defaults.
Extended keyword arguments are documented in the Args section. For further documentation, see the OpenTelemetry documentation at https://opentelemetry.io/docs/specs/otel/trace/sdk/.
- Parameters:
endpoint (str, optional) – The collector endpoint to which spans will be exported. If specified, a default SpanProcessor will be created and added to this TracerProvider. If not provided, the PHOENIX_OTEL_COLLECTOR_ENDPOINT environment variable will be used to infer which collector endpoint to use, defaults to the gRPC endpoint. When specifying the endpoint, the transport method (HTTP or gRPC) will be inferred from the URL.
verbose (bool) – If True, configuration details will be printed to stdout.
- add_span_processor(*args, **kwargs)#
Registers a new SpanProcessor for this TracerProvider.
If this TracerProvider has a default processor, it will be removed.
- class BatchSpanProcessor(span_exporter=None, endpoint=None, headers=None)#
Bases:
BatchSpanProcessor
Batch SpanProcessor implementation.
BatchSpanProcessor is an implementation of SpanProcessor that batches ended spans and pushes them to the configured SpanExporter.
BatchSpanProcessor is configurable with the following environment variables which correspond to constructor parameters:
OTEL_BSP_SCHEDULE_DELAY
OTEL_BSP_MAX_QUEUE_SIZE
OTEL_BSP_MAX_EXPORT_BATCH_SIZE
OTEL_BSP_EXPORT_TIMEOUT
- Parameters:
span_exporter (SpanExporter, optional) – The SpanExporter to which ended spans will be passed.
endpoint (str, optional) – The collector endpoint to which spans will be exported. If not provided, the PHOENIX_OTEL_COLLECTOR_ENDPOINT environment variable will be used to infer which collector endpoint to use, defaults to the gRPC endpoint. When specifying the endpoint, the transport method (HTTP or gRPC) will be inferred from the URL.
headers (dict, optional) – Optional headers to include in the request to the collector. If not provided, the PHOENIX_CLIENT_HEADERS or OTEL_EXPORTER_OTLP_HEADERS environment variable will be used.
max_queue_size (int, optional) – The maximum queue size.
schedule_delay_millis (float, optional) – The delay between two consecutive exports in milliseconds.
max_export_batch_size (int, optional) – The maximum batch size.
export_timeout_millis (float, optional) – The batch timeout in milliseconds.
- class GRPCSpanExporter(*args, **kwargs)#
Bases:
OTLPSpanExporter
OTLP span exporter using gRPC.
For more information, see: - opentelemetry.exporter.otlp.proto.grpc.trace_exporter.OTLPSpanExporter
- Parameters:
endpoint (str, optional) – OpenTelemetry Collector receiver endpoint. If not provided, the PHOENIX_OTEL_COLLECTOR_ENDPOINT environment variable will be used to infer which collector endpoint to use, defaults to the gRPC endpoint.
insecure – Connection type
credentials – Credentials object for server authentication
headers – Headers to send when exporting. If not provided, the PHOENIX_CLIENT_HEADERS or OTEL_EXPORTER_OTLP_HEADERS environment variables will be used.
timeout – Backend request timeout in seconds
compression – gRPC compression method to use
- class HTTPSpanExporter(*args, **kwargs)#
Bases:
OTLPSpanExporter
OTLP span exporter using HTTP.
For more information, see: - opentelemetry.exporter.otlp.proto.http.trace_exporter.OTLPSpanExporter
- Parameters:
endpoint (str, optional) – OpenTelemetry Collector receiver endpoint. If not provided, the PHOENIX_OTEL_COLLECTOR_ENDPOINT environment variable will be used to infer which collector endpoint to use, defaults to the HTTP endpoint.
headers – Headers to send when exporting. If not provided, the PHOENIX_CLIENT_HEADERS or OTEL_EXPORTER_OTLP_HEADERS environment variables will be used.
- class Resource(attributes, schema_url=None)#
Bases:
object
A Resource is an immutable representation of the entity producing telemetry as Attributes.
- static create(attributes=None, schema_url=None)#
Creates a new Resource from attributes.
- Parameters:
attributes – Optional zero or more key-value pairs.
schema_url – Optional URL pointing to the schema
- Returns:
The newly-created Resource.
- merge(other)#
Merges this resource and an updating resource into a new Resource.
If a key exists on both the old and updating resource, the value of the updating resource will override the old resource value.
The updating resource’s schema_url will be used only if the old schema_url is empty. Attempting to merge two resources with different, non-empty values for schema_url will result in an error and return the old resource.
- Parameters:
other – The other resource to be merged.
- Returns:
The newly-created Resource.
- class SimpleSpanProcessor(span_exporter=None, endpoint=None, headers=None)#
Bases:
SimpleSpanProcessor
Simple SpanProcessor implementation.
SimpleSpanProcessor is an implementation of SpanProcessor that passes ended spans directly to the configured SpanExporter.
- Parameters:
span_exporter (SpanExporter, optional) – The SpanExporter to which ended spans will be passed.
endpoint (str, optional) – The collector endpoint to which spans will be exported. If not provided, the PHOENIX_OTEL_COLLECTOR_ENDPOINT environment variable will be used to infer which collector endpoint to use, defaults to the gRPC endpoint. When specifying the endpoint, the transport method (HTTP or gRPC) will be inferred from the URL.
headers (dict, optional) – Optional headers to include in the request to the collector. If not provided, the PHOENIX_CLIENT_HEADERS or OTEL_EXPORTER_OTLP_HEADERS environment variable will be used.