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