/opentelemetry-python

The OpenTelemetry Python Client

Primary LanguagePythonApache License 2.0Apache-2.0

OpenTelemetry Python

Gitter chat Build status

The Python OpenTelemetry client.

Installation

This repository includes multiple installable packages. The opentelemetry-api package includes abstract classes and no-op implementations that comprise the OpenTelemetry API following the specification. The opentelemetry-sdk package is the reference implementation of the API.

Libraries that produce telemetry data should only depend on opentelemetry-api, and defer the choice of the SDK to the application developer. Applications may depend on opentelemetry-sdk or another package that implements the API.

Please note that this library is currently in alpha, and shouldn't be used in production environments.

The API and SDK packages are available on PyPI, and can installed via pip:

pip install opentelemetry-api
pip install opentelemetry-sdk

The ext/ directory includes OpenTelemetry integration packages, which can be installed separately as:

pip install opentelemetry-ext-{integration}

To install the development versions of these packages instead, clone or fork this repo and do an editable install:

pip install -e ./opentelemetry-api
pip install -e ./opentelemetry-sdk
pip install -e ./ext/opentelemetry-ext-{integration}

Quick Start

Tracing

from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import ConsoleSpanExporter
from opentelemetry.sdk.trace.export import SimpleExportSpanProcessor

trace.set_preferred_tracer_provider_implementation(lambda T: TracerProvider())
trace.tracer_provider().add_span_processor(
    SimpleExportSpanProcessor(ConsoleSpanExporter())
)
tracer = trace.get_tracer(__name__)
with tracer.start_as_current_span('foo'):
    with tracer.start_as_current_span('bar'):
        with tracer.start_as_current_span('baz'):
            print("Hello world from OpenTelemetry Python!")

Metrics

from opentelemetry import metrics
from opentelemetry.sdk.metrics import Counter, MeterProvider
from opentelemetry.sdk.metrics.export import ConsoleMetricsExporter
from opentelemetry.sdk.metrics.export.controller import PushController

metrics.set_preferred_meter_provider_implementation(lambda _: MeterProvider())
meter = metrics.get_meter(__name__)
exporter = ConsoleMetricsExporter()
controller = PushController(meter, exporter, 5)

counter = meter.create_metric(
    "available memory",
    "available memory",
    "bytes",
    int,
    Counter,
    ("environment",),
)

label_values = ("staging",)
counter_handle = counter.get_handle(label_values)
counter_handle.add(100)

See the API documentation for more detail, and the examples folder for a more sample code.

Extensions

Third-party exporters

OpenTelemetry supports integration with the following third-party exporters.

Contributing

See CONTRIBUTING.md

We meet weekly on Thursday at 8AM PT. The meeting is subject to change depending on contributors' availability. Check the OpenTelemetry community calendar for specific dates.

Meetings take place via Zoom video conference.

Meeting notes are available as a public Google doc. For edit access, get in touch on Gitter.

Approvers (@open-telemetry/python-approvers):

Find more about the approver role in community repository.

Maintainers (@open-telemetry/python-maintainers):

Find more about the maintainer role in community repository.

Release Schedule

OpenTelemetry Python is under active development.

The library is not yet generally available, and releases aren't guaranteed to conform to a specific version of the specification. Future releases will not attempt to maintain backwards compatibility with previous releases. Each alpha release includes significant changes to the API and SDK packages, making them incompatible with each other.

The v0.1 alpha release includes:

  • Tracing API
  • Tracing SDK
  • Metrics API
  • Metrics SDK (Partial)
  • W3C Trace Context Propagation
  • B3 Context Propagation
  • HTTP Integrations

The v0.2 alpha release includes:

  • OpenTracing Bridge
  • Jaeger Trace Exporter
  • Trace Sampling

The v0.3 alpha release includes:

  • Metrics Instruments and Labels
  • Flask Integration
  • PyMongo Integration

The v0.4 alpha release includes:

  • Metrics MinMaxSumCount Aggregator
  • Context API
  • Full Metrics SDK Pipeline
  • Metrics STDOUT Exporter
  • Dbapi2 Integration
  • MySQL Integration
  • Psycopg2 Integration
  • Zipkin Exporter
  • Prometheus Metrics Exporter
  • New Examples and Improvements to Existing Examples

Thank you to the following individuals for contributing to this release:

  • Alex Boten
  • Chris Kleinknecht
  • Christian Neumüller
  • Daniel González
  • Diego Hurtado
  • Golovin Pavel
  • Hector Hernandez
  • Jake Malachowski
  • Joshua H Lang
  • Leighton Chen
  • Mauricio Vásquez
  • Yusuke Tsutsumi

See the project milestones for details on upcoming releases. The dates and features described here are estimates, and subject to change.

Future releases targets include:

Component Version Target Date
W3C Correlation Context Propagation Beta v1 March 16 2020
Support for Tags/Baggage Beta v1 March 16 2020
gRPC Integrations Beta v1 March 16 2020
OpenTelemetry Collector Exporter Beta v1 March 16 2020
OpenCensus Bridge Beta v1 March 16 2020
Metrics SDK (Complete) Beta v1 March 16 2020