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

Reading traceparent from request headers

Open matHope opened this issue 7 months ago • 2 comments

In my API when testing passing traceparent via request headers, the traceparent header was not being picked up and subsequently a new one was being generated.

It appears to be that when __call__ is triggered (Due to a request) in the ASGITracingMiddleware the headers are read as bytes rather than a string and as a result when attempting to match the header name in the headers it will evaulate as false, resulting in None being returned. Here is the code i'm referring to - https://github.com/elastic/apm-agent-python/blob/main/elasticapm/utils/disttracing.py#L142

Not sure if this is intentional or not, and if so if there's any workarounds here, I've not found anything in your docs with regards to configuration at least 🤔

In my API I am using ASGITracingMiddleware for a quart application.

Please let me know if you need anymore information

matHope avatar Jun 12 '25 13:06 matHope

@matHope thanks for reporting, what http header are you passing to the quart app?

xrmx avatar Jun 12 '25 14:06 xrmx

Its "traceparent" with whatever traceparentId you'd like to provide

matHope avatar Jun 12 '25 14:06 matHope

It appears to be that when call is triggered (Due to a request) in the ASGITracingMiddleware the headers are read as bytes rather than a string and as a result when attempting to match the header name in the headers it will evaulate as false, resulting in None being returned. Here is the code i'm referring to - https://github.com/elastic/apm-agent-python/blob/main/elasticapm/utils/disttracing.py#L142

That was it, good analysis!

xrmx avatar Jul 04 '25 12:07 xrmx