OpenTelemetry Datadog Exporter¶
pip install opentelemetry-exporter-datadog
The Datadog exporter provides a span processor that must be added along with the exporter. In addition, a formatter is provided to handle propagation of trace context between OpenTelemetry-instrumented and Datadog-instrumented services in a distributed trace.
from opentelemetry.propagate import set_global_textmap from opentelemetry import trace from opentelemetry.exporter.datadog import DatadogExportSpanProcessor, DatadogSpanExporter from opentelemetry.exporter.datadog.propagator import DatadogFormat from opentelemetry.sdk.trace import TracerProvider trace.set_tracer_provider(TracerProvider()) tracer = trace.get_tracer(__name__) exporter = DatadogSpanExporter( agent_url="http://agent:8126", service="my-helloworld-service" ) span_processor = DatadogExportSpanProcessor(exporter) trace.get_tracer_provider().add_span_processor(span_processor) # Optional: use Datadog format for propagation in distributed traces set_global_textmap(DatadogFormat()) with tracer.start_as_current_span("foo"): print("Hello world!")
The docs/examples/datadog_exporter includes examples for using the Datadog exporter with OpenTelemetry instrumented applications.
- class opentelemetry.exporter.datadog.DatadogExportSpanProcessor(span_exporter, schedule_delay_millis=5000, max_trace_size=4096)¶
Datadog exporter span processor
DatadogExportSpanProcessor is an implementation of
SpanProcessorthat batches all opened spans into a list per trace. When all spans for a trace are ended, the trace is queues up for export. This is required for exporting to the Datadog Agent which expects to received list of spans for each trace.
- on_start(span, parent_context=None)¶
Called when a
This method is called synchronously on the thread that starts the span, therefore it should not block or throw an exception.
Called when a
This method is called synchronously on the thread that ends the span, therefore it should not block or throw an exception.
Export all ended spans to the configured Exporter that have not yet been exported.
- class opentelemetry.exporter.datadog.DatadogSpanExporter(agent_url=None, service=None, env=None, version=None, tags=None)¶
Datadog span exporter for OpenTelemetry.
agent_url – The url of the Datadog Agent or use
service – The service name to be used for the application or use
env – Set the application’s environment or use
version – Set the application’s version or use
tags – A list (formatted as a comma-separated string) of default tags to be added to every span or use
- property agent_writer¶
Exports a batch of telemetry data.
spans – The list of
opentelemetry.trace.Spanobjects to be exported
The result of the export
Shuts down the exporter.
Called when the SDK is shut down.