1

So i used a few days to find this solution to Azure Functions and Application Insights not using the same Operation Id and Parent Id on Dependency and Exception. Im posting this hoping that others will have use of it

const appInsights = require('applicationinsights');
var appInsights.setup();
var operationAppInsight = context.traceContext.traceparent.split('-');
Object.assign(appInsights.defaultClient.context.tags, {
    'ai.operation.id': operationAppInsight[1],
    'ai.operation.parentId': operationAppInsight[2]
});
appInsights.start();

with this we add 'ai.operation.id' and 'ai.operation.parentId' to appInsights.defaultClient.context.tags, so that its populated then we start insights, note that you need access to the context object too be able run this, so parts of this needs to be in your functions trigger index.js module.export entry point

WizSileX
  • 11
  • 2

1 Answers1

1

Below are the step that can be followed to get the log tracked automatically and as well as correlated with operation id.

  1. Avoid this - if you want to update every log better we can normally use the telemetry processor the below line may cause issues.
var operationAppInsight = context.traceContext.traceparent.split('-');
Object.assign(appInsights.defaultClient.context.tags, {
    'ai.operation.id': operationAppInsight[1],
    'ai.operation.parentId': operationAppInsight[2]
});

Try this -

AppInsight Configurations

  1. [optional] Don't forget to connect your function app with a respective application insights
  2. Nodejs &Az func will not automatically correlate or track the calls. if you want to correlate all logs like trace , exception, **dependencies(HTTP), etc.., we should wrap the index file's top-level export with the app insight lib, Refrence Code.

** request we have to manually track
** dependencies of type HTTP request are automatically tracked (Eg: API calls) but we have manually track other dependecies like SQL connections(Eg: SQL TCP calls)

Hope it answers.

Regards,
Muhamed