microsoft / ApplicationInsights-node.js

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

Distributed tracing issues in Node.js Azure Function App - No Correlation #1038

Open He-Wolf opened 1 year ago

He-Wolf commented 1 year ago

I created a Azure Function App with two functions:

  1. [HttpTrigger] http-triggered function that sends an EventGrid event in CloudEvent schema to a topic
  2. [CloudEventsTrigger] http-triggered function that subscribes to the EventGrid topic using CloudEvent schema (webhook)

After triggering the first function, I see that the two functions have different Operation ID and traceparent.

What I understood from the documentation of App Insights is that these IDs should be identical. I used the example that can be found in the documentation.

I created a repo for my simple project. It also contains a deployment script so that you can test it yourself. I summarized my finding in the README.md. I think all the info needed for investigation can be found in the project.

Let me know if you need additional data.

hectorhdzg commented 1 year ago

@He-Wolf thank you for detailed repro of your issue, looking at your Application Insights SDK implementation code, the SDK will grab whatever context is available in the Azure Function including tracing context and it will be used for the telemetry generated in your trigger, the fact that the correlation is lost between the two function executions means Azure Function was not able to propagate, I suppose Azure Functions are using W3C headers to propagate the tracing context, maybe EventGrid Azure SDK is not including correct headers, it will be good for Azure SDK folks to take a look at this issue, you should be able to create another issue related to this one in their Github repo

He-Wolf commented 1 year ago

@hectorhdzg Thank you for your feedback. I created an issue in Azure SDK repo. I will continue the discussion there.