Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 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
3 changes: 3 additions & 0 deletions src/requestTracing/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export const NODEJS_DEV_ENV_VAL = "development";
export const ENV_KEY = "Env";
export const DEV_ENV_VAL = "Dev";

// Node.js Version
export const NODE_VERSION_KEY = "NODE";

// Host Type
export const HOST_TYPE_KEY = "Host";
export enum HostType {
Expand Down
18 changes: 15 additions & 3 deletions src/requestTracing/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
FEATURE_FILTER_TYPE_KEY,
FF_MAX_VARIANTS_KEY,
FF_FEATURES_KEY,
NODE_VERSION_KEY,
HOST_TYPE_KEY,
HostType,
KEY_VAULT_CONFIGURED_TAG,
Expand Down Expand Up @@ -126,6 +127,7 @@ function createCorrelationContextHeader(requestTracingOptions: RequestTracingOpt
keyValues.set(REQUEST_TYPE_KEY, requestTracingOptions.initialLoadCompleted ? RequestType.WATCH : RequestType.STARTUP);
keyValues.set(HOST_TYPE_KEY, getHostType());
keyValues.set(ENV_KEY, isDevEnvironment() ? DEV_ENV_VAL : undefined);
keyValues.set(NODE_VERSION_KEY, getNodeVersion());

const appConfigOptions = requestTracingOptions.appConfigOptions;
if (appConfigOptions?.keyVaultOptions) {
Expand Down Expand Up @@ -198,7 +200,7 @@ function createFeaturesString(requestTracingOptions: RequestTracingOptions): str
return tags.join(DELIMITER);
}

function getEnvironmentVariable(name: string) {
function getEnvironmentVariable(name: string): string | undefined {
// Make it compatible with non-Node.js runtime
if (typeof process !== "undefined" && typeof process?.env === "object") {
return process.env[name];
Expand All @@ -207,6 +209,16 @@ function getEnvironmentVariable(name: string) {
}
}

function getNodeVersion(): string | undefined {
// Make it compatible with non-Node.js runtime
if (typeof process !== "undefined" && typeof process?.versions === "object") {
const version = process.versions.node;
return version ? version.split(".")[0] : undefined;
} else {
return undefined;
}
}

function getHostType(): string | undefined {
let hostType: string | undefined;
if (getEnvironmentVariable(AZURE_FUNCTION_ENV_VAR)) {
Expand Down Expand Up @@ -235,7 +247,7 @@ function isDevEnvironment(): boolean {
return false;
}

export function isBrowser() {
export function isBrowser(): boolean {
// https://developer.mozilla.org/en-US/docs/Web/API/Window
const isWindowDefinedAsExpected = typeof window === "object" && typeof Window === "function" && window instanceof Window;
// https://developer.mozilla.org/en-US/docs/Web/API/Document
Expand All @@ -244,7 +256,7 @@ export function isBrowser() {
return isWindowDefinedAsExpected && isDocumentDefinedAsExpected;
}

export function isWebWorker() {
export function isWebWorker(): boolean {
// https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope
const workerGlobalScopeDefined = typeof WorkerGlobalScope !== "undefined";
// https://developer.mozilla.org/en-US/docs/Web/API/WorkerNavigator
Expand Down
3 changes: 2 additions & 1 deletion test/requestTracing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ describe("request tracing", function () {
});
} catch (e) { /* empty */ }
expect(headerPolicy.headers).not.undefined;
expect(headerPolicy.headers.get("Correlation-Context")).eq("RequestType=Startup");
const correlationContext = headerPolicy.headers.get("Correlation-Context");
expect(correlationContext.includes("RequestType=Startup")).eq(true);
});

it("should have key vault tag in correlation-context header", async () => {
Expand Down