Azure-functions-host: Custom telemetry not being linked to request in Javascript functions

Created on 30 Oct 2019  路  5Comments  路  Source: Azure/azure-functions-host

I am using javascript functions version 2.0.12763.0
application insights node sdk v 1.5.0

If i follow the code example in
https://docs.microsoft.com/en-us/azure/azure-functions/functions-monitoring#log-custom-telemetry-in-javascript-functions

const appInsights = require("applicationinsights");
appInsights.setup();
const client = appInsights.defaultClient;

module.exports = function (context, req) {
    context.log('JavaScript HTTP trigger function processed a request.');

    client.trackEvent({name: "my custom event", tagOverrides:{"ai.operation.id": context.invocationId}, properties: {customProperty2: "custom property value"}});
    client.trackException({exception: new Error("handled exceptions can be logged with this method"), tagOverrides:{"ai.operation.id": context.invocationId}});
    client.trackMetric({name: "custom metric", value: 3, tagOverrides:{"ai.operation.id": context.invocationId}});
    client.trackTrace({message: "trace message", tagOverrides:{"ai.operation.id": context.invocationId}});
    client.trackDependency({target:"http://dbname", name:"select customers proc", data:"SELECT * FROM Customers", duration:231, resultCode:0, success: true, dependencyTypeName: "ZSQL", tagOverrides:{"ai.operation.id": context.invocationId}});
    client.trackRequest({name:"GET /customers", url:"http://myserver/customers", duration:309, resultCode:200, success:true, tagOverrides:{"ai.operation.id": context.invocationId}});

    context.done();
};

then the custom telemetry is linked together but nothing was linked to the original request. Removing the invocationid override doesn't solve the issue. We would like to see the custom telemetry linked to the original request as it was in functions v1

I thought this issue would have been fixed with
https://github.com/Azure/azure-functions-host/issues/3747 but perhaps I misunderstood

Has this issue been resolved? If so, is there some example code?

image

Httptrigger request not linked to custom telemetry

image

Most helpful comment

Hi there @yojagad we were just looking at this issue today, to correlate across requests. Has there been doc updates for this?

All 5 comments

@yojagad -- do you have a sample of how to use this now? I believe that instead of context.invocationId you now need to use context.traceContext.tracestate (but let's have Yogesh confirm).

We need to update the official docs now that this has changed for v2.

@HShather We do have a way to link custom telemetry with original request through context.traceContext like @brettsam mentioned but the changes have not been released for node functions yet. Will update this thread and docs with relevant examples once released.

Hi there @yojagad we were just looking at this issue today, to correlate across requests. Has there been doc updates for this?

Any update on this?

Hey @ruifelixpereira and @yojagad , my team has been working on a reference architecture sample that does distributed telemetry in Typescript Azure Functions, using some code that we ripped out of the nodejs sdk and the techniques described further above. Here's the main repo: https://github.com/hannesne/projectnewcastle and I did a specific writeup in here: https://github.com/hannesne/projectnewcastle/blob/master/docs/DistributedTelemetry.md

Was this page helpful?
0 / 5 - 0 ratings