getCorrelationContext() returns different traceparent in same operation before/after dependency call
Hi,
I have a regular express API, which executes some simple flow involving a call to some dependency.
I make use of the traceparent object available from appInsights.getCorrelationContext() and I've noticed that it changes after making a dependency call.
Here's the simple code I've used to track the changes:
logger.info(JSON.stringify(appInsights.getCorrelationContext()));
const integrations = await apiClient.getIntegrations();
logger.info(JSON.stringify(appInsights.getCorrelationContext()));
See below picture for the actual diff.
- Is this the expected behavior?
- What is the motivation of altering the
spanIdafter each dependency call?
My setup is:
- node v16
- application insights v2.3.3
Thank you
@johnib spanId will end as part of the "id" of the telemetry generated by the SDK, allowing us to differentiate between all other operations in the same trace, what are you trying to achieve here and why spanId changing is a problem?
Getting the current traceparent is useful for manual correlating of async events (i.e. I put a traceparent field into the event and the processing code is visible as a part of the same logical operation).
I'd expect CorrelationContextManager.getCurrentContext().operation to represent current operation, as the name suggest (and not the most recently called dependency).
Having a new id for each telemetry entry of course makes sense, but it could be generated on the fly, without modifying current traceparent. Does modifying it have any benefits?
@johnib spanId will end as part of the "id" of the telemetry generated by the SDK, allowing us to differentiate between all other operations in the same trace, what are you trying to achieve here and why spanId changing is a problem?
I'm trying to achieve manual correlation with my other micro services (which are not APIs), by providing the correct traceparent value on the dependency call, so the receiver (my micro service) can correlate correctly it's telemetry items.
Updating the spanId of the existing correlation context, after each dependency call being made as part of this request, makes my manual correlation inconsistent and often wrong.
If the first dependency call on the root request was to my second micro service, then the traceparent I get, is accurate✅.
However, if there's some dependency call to some endpoint (Google.com), because the SDK changes the spanId of the correlation context of the root request, then later on when another dependency call is made to my second micro service, the traceparent considers the span of the first dependency call (Google.com) as the parent of the request on my second micro service, which is wrong❌.