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.

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:
    # host_name="localhost",
    # port=9411,
    # endpoint="/api/v2/spans",
    # protocol="http",
    # 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!")

API

class opentelemetry.exporter.zipkin.ZipkinSpanExporter(service_name, host_name='localhost', port=9411, endpoint='/api/v2/spans', protocol='http', ipv4=None, ipv6=None, retry=False)[source]

Bases: opentelemetry.sdk.trace.export.SpanExporter

Zipkin span exporter for OpenTelemetry.

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

  • host_name (str) – The host name of the Zipkin server

  • port (int) – The port of the Zipkin server

  • endpoint (str) – The endpoint of the Zipkin server

  • protocol (str) – The protocol used for the request.

  • ipv4 (Optional[str]) – Primary IPv4 address associated with this connection.

  • ipv6 (Optional[str]) – Primary IPv6 address associated with this connection.

  • retry (Optional[str]) – Set to True to configure the exporter to retry on failure.

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