# OpenTelemetry Zipkin Exporters

## OpenTelemetry Zipkin JSON Exporter

This library allows to export tracing data to Zipkin.

## Usage

The OpenTelemetry Zipkin JSON Exporter allows exporting of OpenTelemetry traces to Zipkin. This exporter sends traces to the configured Zipkin collector endpoint using JSON over HTTP and supports multiple versions (v1, v2).

    import requests

    from opentelemetry import trace
    from opentelemetry.exporter.zipkin.json import ZipkinExporter
    from opentelemetry.sdk.trace import TracerProvider
    from opentelemetry.sdk.trace.export import BatchSpanProcessor

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

    # create a ZipkinExporter
    zipkin_exporter = ZipkinExporter(
        # version=Protocol.V2
        # optional:
        # endpoint="http://localhost:9411/api/v2/spans",
        # local_node_ipv4="192.168.0.1",
        # local_node_ipv6="2001:db8::c001",
        # local_node_port=31313,
        # max_tag_value_length=256,
        # timeout=5 (in seconds),
        # session=requests.Session(),
    )

    # Create a BatchSpanProcessor and add the exporter to it
    span_processor = BatchSpanProcessor(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 variable for configuration:

- `OTEL_EXPORTER_ZIPKIN_ENDPOINT`

- `OTEL_EXPORTER_ZIPKIN_TIMEOUT`

## API

class opentelemetry.exporter.zipkin.json.ZipkinExporter(version=Protocol.V2, endpoint=None, local_node_ipv4=None, local_node_ipv6=None, local_node_port=None, max_tag_value_length=None, timeout=None, session=None)

  Bases: `SpanExporter`

  export(spans)

    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()

    Shuts down the exporter.

    Called when the SDK is shut down.

    Return type:

      `None`

  force_flush(timeout_millis=30000)

    Hint to ensure that the export of any spans the exporter has received prior to the call to ForceFlush SHOULD be completed as soon as possible, preferably before returning from this method.

    Return type:

      `bool`

## OpenTelemetry Zipkin Protobuf Exporter

This library allows to export tracing data to Zipkin.

## Usage

The OpenTelemetry Zipkin Exporter allows exporting of OpenTelemetry traces to Zipkin. This exporter sends traces to the configured Zipkin collector endpoint using HTTP and supports v2 protobuf.

    import requests

    from opentelemetry import trace
    from opentelemetry.exporter.zipkin.proto.http import ZipkinExporter
    from opentelemetry.sdk.trace import TracerProvider
    from opentelemetry.sdk.trace.export import BatchSpanProcessor

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

    # create a ZipkinExporter
    zipkin_exporter = ZipkinExporter(
        # optional:
        # endpoint="http://localhost:9411/api/v2/spans",
        # local_node_ipv4="192.168.0.1",
        # local_node_ipv6="2001:db8::c001",
        # local_node_port=31313,
        # max_tag_value_length=256,
        # timeout=5 (in seconds),
        # session=requests.Session()
    )

    # Create a BatchSpanProcessor and add the exporter to it
    span_processor = BatchSpanProcessor(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 variable for configuration:

- `OTEL_EXPORTER_ZIPKIN_ENDPOINT`

- `OTEL_EXPORTER_ZIPKIN_TIMEOUT`

## API

class opentelemetry.exporter.zipkin.proto.http.ZipkinExporter(endpoint=None, local_node_ipv4=None, local_node_ipv6=None, local_node_port=None, max_tag_value_length=None, timeout=None, session=None)

  Bases: `SpanExporter`

  export(spans)

    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()

    Shuts down the exporter.

    Called when the SDK is shut down.

    Return type:

      `None`

  force_flush(timeout_millis=30000)

    Hint to ensure that the export of any spans the exporter has received prior to the call to ForceFlush SHOULD be completed as soon as possible, preferably before returning from this method.

    Return type:

      `bool`