microsoft / ApplicationInsights-node.js

Microsoft Application Insights SDK for Node.js
MIT License
321 stars 138 forks source link

Corellation Context cannot be accessed during azure functions preInvocation hooks #1255

Closed GravlLift closed 2 months ago

GravlLift commented 5 months ago

I'm using this package in azure functions and I'm attempting to set a custom property in the correlation context using Azure Functions preInvocation hook. However, the way this package works is that correlation contexts are only associated with the function handler via the wrapCallback function:

https://github.com/microsoft/ApplicationInsights-node.js/blob/0217324c477a96b5dd659510bbccad27934084a3/AutoCollection/AzureFunctionsHook.ts#L67-L99

So if I attempt to call getCorrelationContext or startOperation from my hook, I get a correllation context that only exists for the lifetime of my hook and is then lost.

Do you have any suggestions on how I might accomplish my objective (outside of explicitly setting custom properties at the start of all of my functions)?

JacksonWeber commented 2 months ago

@GravlLift We recently moved to an OpenTelemetry based solution for this package so features like correlation context are expected to behave differently. Could you give it a try with the upgraded package version?