diff --git a/src/shim/correlationContextManager.ts b/src/shim/correlationContextManager.ts index ce1c6cfa..d0d40ede 100644 --- a/src/shim/correlationContextManager.ts +++ b/src/shim/correlationContextManager.ts @@ -52,13 +52,13 @@ export class CorrelationContextManager { let activeSpan: Span = trace.getSpan(context.active()) as Span; // If no active span exists, create a new one. This is needed if runWithContext() is executed without an active span - if (!activeSpan) { + if (!activeSpan) { activeSpan = trace.getTracer(CONTEXT_NAME).startSpan(CONTEXT_NAME) as Span; } const traceStateObj: TraceState = new TraceState(activeSpan?.spanContext()?.traceState?.serialize()); return this.spanToContextObject(activeSpan?.spanContext(), activeSpan?.parentSpanId, activeSpan?.name, traceStateObj); - } + } return null; } @@ -82,7 +82,7 @@ export class CorrelationContextManager { const ITraceState: ITracestate = { fieldmap: tracestate?.serialize()?.split(",") }; - + return { operation: { name: operationName, @@ -129,7 +129,7 @@ export class CorrelationContextManager { diag.warn("Error binding to session context", Util.getInstance().dumpObj(error)); } } - + /** * Patches a callback to restore the correct Context when getCurrentContext * is run within it. This is necessary if automatic correlation fails to work @@ -200,16 +200,14 @@ export class CorrelationContextManager { if (traceContext) { // Use the headers on the request from Azure Functions to set the active context const azureFnRequest = request as AzureFnRequest; - - // If the traceparent isn't defined on the azure function headers set it to the request-id - // If the headers are not an instance of Headers, we're using the old programming model, else use the v4 model - if (azureFnRequest?.headers && !(azureFnRequest.headers instanceof Headers)) { - // request-id is a GUID-based unique identifier for the request - traceparent = (azureFnRequest.headers as HttpRequestHeaders).traceparent ? (azureFnRequest.headers as HttpRequestHeaders).traceparent : (azureFnRequest.headers as HttpRequestHeaders)["request-id"]; - tracestate = (azureFnRequest.headers as HttpRequestHeaders).tracestate; - } else if (azureFnRequest?.headers && azureFnRequest?.headers instanceof Headers) { - traceparent = azureFnRequest.headers.get("traceparent") || azureFnRequest.headers.get("request-id"); - tracestate = azureFnRequest.headers.get("tracestate"); + // New programming model + if (azureFnRequest?.headers && azureFnRequest?.headers.get) { + traceparent = (azureFnRequest.headers as any).get("traceparent") || (azureFnRequest.headers as any).get("request-id"); + tracestate = (azureFnRequest.headers as any).get("tracestate"); + } else if (azureFnRequest?.headers){ // Old programming model + // request-id is a GUID-based unique identifier for the request + traceparent = (azureFnRequest.headers as HttpRequestHeaders).traceparent ? (azureFnRequest.headers as HttpRequestHeaders).traceparent : (azureFnRequest.headers as HttpRequestHeaders)["request-id"]; + tracestate = (azureFnRequest.headers as HttpRequestHeaders).tracestate; } if (!traceparent && traceContext.traceparent) {