OpenTelemetry API Bridge
The Elastic APM OpenTelemetry bridge allows you to create Elastic APMTransactions
andSpans
, 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 APMTransaction
. Inner spans are mapped to Elastic APMSpan
.
The first step in getting started with the OpenTelemetry bridge is to install theopentelemetry
libraries:
pip install elastic-apm[opentelemetry]
Or if you already have installedelastic-apm
:
pip install opentelemetry-api opentelemetry-sdk
from elasticapm.contrib.opentelemetry import Tracertracer = Tracer(__name__)with tracer.start_as_current_span("test"): # Do some work
or
from elasticapm.contrib.opentelemetry import tracetracer = trace.get_tracer(__name__)with tracer.start_as_current_span("test"): # Do some work
Tracer
andget_tracer()
accept the following optional arguments:
elasticapm_client
: an already instantiated Elastic APM clientconfig
: a configuration dictionary, which will be used to instantiate a new Elastic APM client, e.g.{"SERVER_URL": "https://example.org"}
. Seeconfiguration for more information.
TheTracer
object mirrors the upstream interface on theOpenTelemetryTracer
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.