Elasticsearch Java client version
8.11.1
Kibana version:
8.9.1
APM Elasticsearch version:
8.9.1
APM Server version:
8.9.1
APM Agent language and version:
Java, 1.46.0
Hello,
I originally wanted to create github issue, but your guidelines recommend creating post here first, so here we go:
Description of the problem including expected versus actual behavior. Please include screenshots (if relevant):
Java Elastic APM agent does not record OpenTelemetry spans for Elasticsearch client.
Prelude
Java Elasticsearch client >= v8.10 comes with its own instrumentation. Here I am talking specifically about ElasticsearchTransportBase
.
When no instrumentation is specified via constructor, then OpenTelemetryForElasticsearch.getDefault()
is called, which in turn calls GlobalOpenTelemetry.get()
, which Java Elastic APM agent hooks and makes the method return OpenTelemetry
object of implementation co.elastic.apm.agent.opentelemetry.global.ElasticOpenTelemetryWithMetrics
.
Finally, the the OpenTelemetry
instance is passed into OpenTelemetryForElasticsearch
constructor, which attempts to create Tracer
object via openTelemetry.tracerBuilder("elasticsearch-api")...build()
call. Therein lies a bug.
The bug - Actual behaviour
The TracerBuilder
, that is provided by calling getTracerProvider().tracerBuilder(instrumentationScopeName)
in the OpenTelemetry#tracerBuilder
, is instance of DefaultTracerBuilder
, because the co.elastic.apm.agent.opentelemetry.tracing.OTelTracerProvider
does not override method - io.opentelemetry.api.trace.TracerProvider#tracerBuilder
- which by default returns no-op instance. This I think causes the problem of Elasticsearch client spans not being recorded, since the OpenTelemetryForElasticsearch#tracer
ends up being no-op.
Here is a picture of the resulting types from mentioned methods.
Expected behaviour
ElasticOpenTelemetryWithMetrics#tracerBuilder(String)
should not produce no-op builder.
Thank you