microsoft / ApplicationInsights-node.js

Microsoft Application Insights SDK for Node.js
MIT License
324 stars 141 forks source link

Question: outgoing traceparent header change unexpected? #1145

Open vkstrm opened 1 year ago

vkstrm commented 1 year ago

We are having an issue with Azure(?) changing the traceparent header in the HTTP requests (sent using node-fetch) from an App Service to external non-Azure backends. I am expecting that the traceparent set as a header in a HTTP request is the same traceparent received at the endpoint, but this is not the case.

We are using OpenTelemetry to correlate between Service A and Service B. After manually creating a span using OpenTelemetry we use this span's ID as the span ID in the outgoing traceparent. However, the traceparent span ID received in Service B has the same ID as the Application Insights dependency trace. Turning off automatic dependency tracing does not help, it only means that I can't see that dependency trace. Because of this I assume that manual dependency tracing also wouldn't help, even if I haven't tried that.

Probably not directly related to this library but I guess I'm wondering if there is a way to control this behaviour, or if I'm misunderstanding how this tracing/correlation works? What component could be changing the traceparent on the way out?

distributedTracingMode is set to AI_AND_W3C, but no difference if it isn't.

JacksonWeber commented 1 year ago

Hi @vkstrm, the setup you're describing should work. I'm curious which nodes in your architecture are using AppInsights and which are using OpenTelemetry. It would be especially helpful if you could provide a simple reproducible environment so I can try to reproduce your issue.

vkstrm commented 1 year ago

We are using Application Insights for our App Service, but in the same App Service we are sending some OpenTelemetry traces to an external collector. I know there are ways to integrate OpenTelemetry more with AppInsights but we are using them separately.

I have created a repository with an example that reproduces the issue: https://github.com/vkstrm/appi-traceparent-issue I hope it makes sense and works for you. The OpenTelemetry bit here is only using the Console exporter so it won't show up anywhere, but the concept is the same with the creation of the spans.