Investigative information
Please provide the following:
Test was run locally, but if needed can setup a "on cloud" reproduction.
Repro steps
- Create a Service Bus Triggered function (Topic -> Subscription)
- Connected with AppInsights
- Add some traces via
context.log
- throw an error so as the processed messages gets moved to the DLQ (makes it easier to debug)
- Fire a service bus event for subscription
Expected behavior
When a Service Bus triggered function is executed, I would expert the context.traceContext to be initialized using the Service Bus message Diagnostic-Id.
Actual behavior
The function seems to just initialize a brand new traceContext (not correlated to anything).
Known workarounds
Using the AppInsights wrapWithCorrelationContext, a traceContext can be initialized with the Diagnostic-Id being manually overridden as the traceParent.
// Default export wrapped with Application Insights FaaS context propagation
export default async function contextPropagatingHttpTrigger(context, message) {
// overwrite with the proper traceparent from the message.
const sbTraceParent = context.bindingData.applicationProperties['diagnostic-Id'];
if (sbTraceParent) {
context.traceContext.traceparent = sbTraceParent;
}
const correlationContext = appInsights.startOperation(context, req) as CorrelationContext;
// Wrap the Function runtime with correlationContext
return appInsights.wrapWithCorrelationContext(async () => {
try {
appInsights.defaultClient.trackTrace({
message: 'Correct Trace Context',
});
//wrong operation_Id
context.log('Incorrect Trace Context');
return await trigger(context, message);
} catch (e) {
context.log.error(e);
throw e;
} finally {
// Track Request on completion
appInsights.defaultClient.flush();
}
}, correlationContext)();
}
However, doing so only partially works.
- The "out of the box" request/response logging will still be done using the initial
traceContext
- Any calls to
context.log will still use the initial trace context.
Message In Service Bus

Request Logged Against Initial TraceContext

Traces from AppInsights Correlation Context

Investigative information
Please provide the following:
Test was run locally, but if needed can setup a "on cloud" reproduction.
Repro steps
context.logExpected behavior
When a Service Bus triggered function is executed, I would expert the
context.traceContextto be initialized using the Service Bus messageDiagnostic-Id.Actual behavior
The function seems to just initialize a brand new
traceContext(not correlated to anything).Known workarounds
Using the AppInsights
wrapWithCorrelationContext, a traceContext can be initialized with theDiagnostic-Idbeing manually overridden as thetraceParent.However, doing so only partially works.
traceContextcontext.logwill still use the initial trace context.Message In Service Bus

Request Logged Against Initial TraceContext
Traces from AppInsights Correlation Context
