Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused undici import #1387

Merged
merged 8 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions package-lock.json
hectorhdzg marked this conversation as resolved.
Show resolved Hide resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 15 additions & 16 deletions src/shim/correlationContextManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import { Util } from "../shared/util";
import { HttpRequestHeaders } from "@azure/functions-old";
import { HttpRequest as AzureFnHttpRequest } from "@azure/functions";
import { Headers } from "undici";


const CONTEXT_NAME = "ApplicationInsights-Context";
Expand Down Expand Up @@ -53,13 +52,13 @@
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 @@ -83,7 +82,7 @@
const ITraceState: ITracestate = {
fieldmap: tracestate?.serialize()?.split(",")
};

return {
operation: {
name: operationName,
Expand All @@ -94,8 +93,8 @@
},
// Headers are not being used so custom properties will always be stubbed out
customProperties: {
getProperty(prop: string) { return "" },

Check warning on line 96 in src/shim/correlationContextManager.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 16.x)

'prop' is defined but never used

Check warning on line 96 in src/shim/correlationContextManager.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.x)

'prop' is defined but never used
setProperty(prop: string) { return "" },

Check warning on line 97 in src/shim/correlationContextManager.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 16.x)

'prop' is defined but never used

Check warning on line 97 in src/shim/correlationContextManager.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.x)

'prop' is defined but never used
} as ICustomProperties,
}
}
Expand Down Expand Up @@ -130,7 +129,7 @@
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 @@ -178,7 +177,7 @@
const traceContext = (input && (input as AzureFnContext).traceContext || null) as AzureFnTraceContext;
const span = input && (input as Span).spanContext ? input as Span : null;
const spanContext = input && (input as SpanContext).traceId ? input as SpanContext : null;
const headers = input && (input as http.IncomingMessage | AzureFnRequest).headers;
const headers = input && (input as any).headers;

if (span) {
trace.setSpanContext(context.active(), span.spanContext());
Expand All @@ -201,16 +200,16 @@
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)) {
// 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");
}
// Old programming model
else if (azureFnRequest?.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");
}

if (!traceparent && traceContext.traceparent) {
Expand All @@ -231,9 +230,9 @@
if (headers && (headers as HttpRequestHeaders).traceparent) {
traceparent = (headers as HttpRequestHeaders).traceparent ? (headers as HttpRequestHeaders).traceparent.toString() : null;
tracestate = (headers as HttpRequestHeaders).tracestate ? (headers as HttpRequestHeaders).tracestate.toString() : tracestate;
} else if (headers && headers instanceof Headers) {
traceparent = headers.get("traceparent") || headers.get("request-id");
tracestate = headers.get("tracestate");
} else if (headers && headers.get) {
traceparent = (headers as any).get("traceparent") || (headers as any).get("request-id");
tracestate = (headers as any).get("tracestate");
}

const traceArray: string[] = traceparent?.split("-");
Expand Down
Loading