Type to search.

OpenTelemetry API Bridge

Serverless Observability

Elastic Cloud Serverless projects are autoscaled environments, fully managed by Elastic and available on Elastic Cloud.

Availability

  • Generally available

    This functionality is generally available and ready for production usage.

Stack

The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats.

Availability

  • Generally available

    This functionality is generally available and ready for production usage.

Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments.

This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.

APM Agent Python

The Elastic APM Python agent enables you to trace the execution of operations in your Python applications, sending performance metrics and errors to the Elastic APM Server.

Availability

  • Generally available

    This functionality is generally available and ready for production usage.

This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.

The Elastic APM OpenTelemetry bridge allows you to create Elastic APM Transactions and Spans, using the OpenTelemetry API. This allows users to utilize the Elastic APM agent’s automatic instrumentations, while keeping custom instrumentations vendor neutral.

If a span is created while there is no transaction active, it will result in an Elastic APM Transaction. Inner spans are mapped to Elastic APM Span.

The first step in getting started with the OpenTelemetry bridge is to install the opentelemetry libraries:

Shell
pip install elastic-apm[opentelemetry]

Or if you already have installed elastic-apm:

Shell
pip install opentelemetry-api opentelemetry-sdk
Python
from elasticapm.contrib.opentelemetry import Tracer

tracer = Tracer(__name__)
with tracer.start_as_current_span("test"):
    # Do some work

or

Python
from elasticapm.contrib.opentelemetry import trace

tracer = trace.get_tracer(__name__)
with tracer.start_as_current_span("test"):
    # Do some work

Tracer and get_tracer() accept the following optional arguments:

  • elasticapm_client: an already instantiated Elastic APM client
  • config: a configuration dictionary, which will be used to instantiate a new Elastic APM client, e.g. {"SERVER_URL": "https://example.org"}. See configuration for more information.

The Tracer object mirrors the upstream interface on the OpenTelemetry Tracer object.

Not all features of the OpenTelemetry API are supported.

Processors, exporters, metrics, logs, span events, and span links are not supported.

Additionally, due to implementation details, the global context API only works when a span is included in the activated context, and tokens are not used. Instead, the global context works as a stack, and when a context is detached the previously-active context will automatically be activated.