Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Application Insights operation id in javascript?

I have an Azure Function app written in javascript that has Application Insights integrated:

const AppInsights = require("applicationinsights");

AppInsights.setup(appInsightsInstrumentationKey);
AppInsights.defaultClient.context.tags[
    AppInsights.defaultClient.context.keys.cloudRole
        ] = "My back-end";
AppInsights.start();

The module version is 1.7.4.

I do need to access the current operation id to send it to my custom log for correlation with AI logs in Azure. In my functions I tried this:

var telemetry = appInsights.defaultClient;
var oid = telemetry.context.tags["ai.operation.id"]; // does not work
var oid = telemetry.context.operation.id; // does not work

Nevertheless, AI collects it somehow so I can see it in Azure portal:

enter image description here

How can I access operation_id value at run-time in my Azure functions?

like image 647
UserControl Avatar asked Oct 15 '22 03:10

UserControl


1 Answers

You can give it a try with this line of code:

//operation id
var s = client.context.keys["operationId"];

I found it via debug, the screenshot as below:

enter image description here

like image 87
Ivan Yang Avatar answered Nov 15 '22 08:11

Ivan Yang