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.ext 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.ext.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 serverport (
int
) – The port of the Zipkin serverendpoint (
str
) – The endpoint of the Zipkin serverprotocol (
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 ofopentelemetry.trace.Span
objects to be exported- Return type
- Returns
The result of the export