Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorhdzg committed Oct 18, 2024
1 parent 506bae1 commit 88e73f5
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/shim/correlationContextManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -82,7 +82,7 @@ export class CorrelationContextManager {
const ITraceState: ITracestate = {
fieldmap: tracestate?.serialize()?.split(",")
};

return {
operation: {
name: operationName,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 88e73f5

Please sign in to comment.