-
Notifications
You must be signed in to change notification settings - Fork 4
Set User Agent and Correlation Context for requests #6
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
49522c4
add specific user-agent for requests
Eskibear 6aba2ca
Set Correlation-Context header via additional policy
Eskibear 6ccad91
address comments: use OperationOptions to set custom headers
Eskibear 38be524
add unit tests for custom headers
Eskibear 967cf1e
use wildcard import
Eskibear 66a84f4
fix typo
Eskibear 306986b
add data collection notice
Eskibear b531370
address comments: import constants for shorter names
Eskibear a29a77b
address comments:move version constant out
Eskibear 814febb
nit: change Load.ts to load.ts as it's not a type
Eskibear 52fa63c
Merge remote-tracking branch 'origin/main' into yanzh/telemetry
Eskibear fdba166
address comments: only set requestOptions when request tracing enabled
Eskibear ef54792
Merge remote-tracking branch 'origin/main' into yanzh/telemetry
Eskibear b671558
address comments
Eskibear cffbec8
add test cases for disabling request tracing
Eskibear File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| export { load } from "./Load"; | ||
| export { load } from "./load"; | ||
| export { AzureAppConfiguration } from "./AzureAppConfiguration"; | ||
| export { KeyFilter } from "./KeyFilter"; | ||
| export { LabelFilter } from "./LabelFilter"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| import { Version } from "../version"; | ||
|
|
||
| export const RequestTracingDisabledEnvironmentVariable = "AZURE_APP_CONFIGURATION_TRACING_DISABLED"; | ||
|
|
||
| // User Agent | ||
| export const UserAgentPrefix = `javascript-appconfiguration-provider/${Version}`; | ||
|
|
||
| // Correlation Context | ||
| export const CorrelationContextHeaderName = "Correlation-Context"; | ||
|
|
||
| // Env | ||
| export const NodeJSEnvironmentVariable = "NODE_ENV"; | ||
| export const NodeJSDevEnvironmentVariableValue = "development"; | ||
| export const EnvironmentKey = "Env"; | ||
| export const DevEnvironmentValue = "Dev"; | ||
|
|
||
| // Host Type | ||
| export const HostTypeKey = "Host"; | ||
| export enum HostType { | ||
| AzureFunction = "AzureFunction", | ||
| AzureWebApp = "AzureWebApp", | ||
| ContainerApp = "ContainerApp", | ||
| Kubernetes = "Kubernetes", | ||
| ServiceFabric = "ServiceFabric" | ||
| } | ||
|
|
||
| // Environment variables to identify Host type. | ||
| export const AzureFunctionEnvironmentVariable = "FUNCTIONS_EXTENSION_VERSION"; | ||
| export const AzureWebAppEnvironmentVariable = "WEBSITE_SITE_NAME"; | ||
| export const ContainerAppEnvironmentVariable = "CONTAINER_APP_NAME"; | ||
| export const KubernetesEnvironmentVariable = "KUBERNETES_PORT"; | ||
| export const ServiceFabricEnvironmentVariable = "Fabric_NodeName"; // See: https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-environment-variables-reference | ||
|
|
||
| // Request Type | ||
| export const RequestTypeKey = "RequestType"; | ||
| export enum RequestType { | ||
| Startup = "Startup", | ||
| Watch = "Watch" | ||
| } | ||
|
|
||
| // Tag names | ||
| export const KeyVaultConfiguredTag = "UsesKeyVault"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| import { AzureAppConfigurationOptions } from "../AzureAppConfigurationOptions"; | ||
| import { | ||
| AzureFunctionEnvironmentVariable, | ||
| AzureWebAppEnvironmentVariable, | ||
| ContainerAppEnvironmentVariable, | ||
| DevEnvironmentValue, | ||
| EnvironmentKey, | ||
| HostType, | ||
| HostTypeKey, | ||
| KeyVaultConfiguredTag, | ||
| KubernetesEnvironmentVariable, | ||
| NodeJSDevEnvironmentVariableValue, | ||
| NodeJSEnvironmentVariable, | ||
| RequestType, | ||
| RequestTypeKey, | ||
| ServiceFabricEnvironmentVariable | ||
| } from "./constants"; | ||
|
|
||
| // Utils | ||
| export function createCorrelationContextHeader(options: AzureAppConfigurationOptions | undefined): string { | ||
| /* | ||
| RequestType: 'Startup' during application starting up, 'Watch' after startup completed. | ||
| Host: identify with defined envs | ||
| Env: identify by env `NODE_ENV` which is a popular but not standard.usually the value can be "development", "production". | ||
| UsersKeyVault | ||
| */ | ||
| const keyValues = new Map<string, string | undefined>(); | ||
| keyValues.set(RequestTypeKey, RequestType.Startup); // TODO: now always "Startup", until refresh is supported. | ||
| keyValues.set(HostTypeKey, getHostType()); | ||
| keyValues.set(EnvironmentKey, isDevEnvironment() ? DevEnvironmentValue : undefined); | ||
|
|
||
| const tags: string[] = []; | ||
| if (options?.keyVaultOptions) { | ||
| const { credential, secretClients, secretResolver } = options.keyVaultOptions; | ||
| if (credential !== undefined || secretClients?.length || secretResolver !== undefined) { | ||
| tags.push(KeyVaultConfiguredTag); | ||
| } | ||
| } | ||
|
|
||
| const contextParts: string[] = []; | ||
| for (const [k, v] of keyValues) { | ||
| if (v !== undefined) { | ||
| contextParts.push(`${k}=${v}`); | ||
| } | ||
| } | ||
| for (const tag of tags) { | ||
| contextParts.push(tag); | ||
| } | ||
|
|
||
| return contextParts.join(","); | ||
| } | ||
|
|
||
| function getHostType(): string | undefined { | ||
| let hostType: string | undefined; | ||
| if (process.env[AzureFunctionEnvironmentVariable]) { | ||
| hostType = HostType.AzureFunction; | ||
| } else if (process.env[AzureWebAppEnvironmentVariable]) { | ||
| hostType = HostType.AzureWebApp; | ||
| } else if (process.env[ContainerAppEnvironmentVariable]) { | ||
| hostType = HostType.ContainerApp; | ||
| } else if (process.env[KubernetesEnvironmentVariable]) { | ||
| hostType = HostType.Kubernetes; | ||
| } else if (process.env[ServiceFabricEnvironmentVariable]) { | ||
| hostType = HostType.ServiceFabric; | ||
| } | ||
| return hostType; | ||
| } | ||
|
|
||
| function isDevEnvironment(): boolean { | ||
| const envType = process.env[NodeJSEnvironmentVariable]; | ||
| if (NodeJSDevEnvironmentVariableValue === envType?.toLowerCase()) { | ||
| return true; | ||
| } | ||
| return false; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| export const Version = "0.1.0-preview"; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.