apm-agent-go icon indicating copy to clipboard operation
apm-agent-go copied to clipboard

Issue in converting between OTEL and APM context

Open rubvs opened this issue 10 months ago • 5 comments

Describe the bug

Information seems to be getting lost between converting from an APM context to OTEL context.

  1. If we have a OTEL parent span and APM child span, we can see full relationship in Kibana. The figure below shows how we go from elasticHandler (otel) -> Streaming (apm) -> Semaphore.Acquire (apm) Image

  2. The issue arises when we want to go from an APM span back to an OTEL span. In this case, we do not observe the last span (Semaphore.Acquire) in Kibana. Image

To Reproduce

  1. Create an OTEL parent span. Then an APM child span, followed by another APM child span. View in Kibana
  2. Create an OTEL parent span. Then an APM child span, followed by an OTEL child span. View in Kibana

Expected behavior

Spans and Span Links that go from OTEL context to APM context doesn't work.

rubvs avatar Jan 24 '25 18:01 rubvs

Nice find. It looks like this is because the APM span is a child span. We only look for transactions when checking parent spans from apm. https://github.com/elastic/apm-agent-go/blob/2b38f4b760d1998800da0c05b9a654e867395afd/module/apmotel/tracer.go#L77-L79

dmathieu avatar Jan 25 '25 11:01 dmathieu

My bad. We actually connect the span when it's created within the apm agent, through the wrapper. https://github.com/elastic/apm-agent-go/blob/2b38f4b760d1998800da0c05b9a654e867395afd/module/apmotel/wrapper.go#L45

How are you creating the Stream span? Are you assigning it to the context?

dmathieu avatar Jan 27 '25 08:01 dmathieu

@rubvs ping?

dmathieu avatar Feb 14 '25 08:02 dmathieu

@dmathieu Sorry, I was on PTO for 2 weeks. Here is how the Stream span is created, see Code. The context passed to this span is from an OTEL parent span.

rubvs avatar Feb 14 '25 21:02 rubvs

I'm not seeing apmotel being required in apm-data (nor the service using it). In order to be able to properly link spans together, apmotel need to be imported into the application, and the tracer provider needs to be configured, as is documented here: https://www.elastic.co/guide/en/apm/agent/go/current/opentelemetry.html

dmathieu avatar Feb 26 '25 10:02 dmathieu