Opentelemetry Zipkin Exporter

This library allows to export tracing data to Zipkin.

Usage

The OpenTelemetry Zipkin Exporter allows to export OpenTelemetry traces to Zipkin. This exporter always send traces to the configured Zipkin collector using HTTP.

OTEL_EXPORTER_ZIPKIN_ENDPOINT
OTEL_EXPORTER_ZIPKIN_TRANSPORT_FORMAT
from opentelemetry import trace
from opentelemetry.exporter import zipkin
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchExportSpanProcessor

trace.set_tracer_provider(TracerProvider())
tracer = trace.get_tracer(__name__)

# create a ZipkinSpanExporter
zipkin_exporter = zipkin.ZipkinSpanExporter(
    service_name="my-helloworld-service",
    # optional:
    # url="http://localhost:9411/api/v2/spans",
    # ipv4="",
    # ipv6="",
    # retry=False,
)

# Create a BatchExportSpanProcessor and add the exporter to it
span_processor = BatchExportSpanProcessor(zipkin_exporter)

# add to the tracer
trace.get_tracer_provider().add_span_processor(span_processor)

with tracer.start_as_current_span("foo"):
    print("Hello world!")

The exporter supports the following environment variables for configuration:

OTEL_EXPORTER_ZIPKIN_ENDPOINT: target to which the exporter will send data. This may include a path (e.g. http://example.com:9411/api/v2/spans).

OTEL_EXPORTER_ZIPKIN_TRANSPORT_FORMAT: transport interchange format to use when sending data. Currently only Zipkin’s v2 json and protobuf formats are supported, with v2 json being the default.

API

class opentelemetry.exporter.zipkin.ZipkinSpanExporter(service_name, url=None, ipv4=None, ipv6=None, retry=False, max_tag_value_length=128, transport_format=None)[source]

Bases: opentelemetry.sdk.trace.export.SpanExporter

Zipkin span exporter for OpenTelemetry.

Parameters
  • service_name – Service that logged an annotation in a trace.Classifier when query for spans.

  • url – The Zipkin endpoint URL

  • ipv4 – Primary IPv4 address associated with this connection.

  • ipv6 – Primary IPv6 address associated with this connection.

  • retry – Set to True to configure the exporter to retry on failure.

  • transport_format – transport interchange format to use

export(spans)[source]

Exports a batch of telemetry data.

Parameters

spans (Sequence[Span]) – The list of opentelemetry.trace.Span objects to be exported

Return type

SpanExportResult

Returns

The result of the export

shutdown()[source]

Shuts down the exporter.

Called when the SDK is shut down.

Return type

None

static format_pbuf_span_id(span_id)[source]
opentelemetry.exporter.zipkin.nsec_to_usec_round(nsec)[source]

Round nanoseconds to microseconds