33
44import { AzureAppConfigurationOptions } from "../AzureAppConfigurationOptions" ;
55import {
6- AzureFunctionEnvironmentVariable ,
7- AzureWebAppEnvironmentVariable ,
8- ContainerAppEnvironmentVariable ,
9- DevEnvironmentValue ,
10- EnvironmentKey ,
6+ AZURE_FUNCTION_ENV_VAR ,
7+ AZURE_WEB_APP_ENV_VAR ,
8+ CONTAINER_APP_ENV_VAR ,
9+ DEV_ENV_VAL ,
10+ ENV_AZURE_APP_CONFIGURATION_TRACING_DISABLED ,
11+ ENV_KEY ,
12+ HOST_TYPE_KEY ,
1113 HostType ,
12- HostTypeKey ,
13- KeyVaultConfiguredTag ,
14- KubernetesEnvironmentVariable ,
15- NodeJSDevEnvironmentVariableValue ,
16- NodeJSEnvironmentVariable ,
17- RequestTracingDisabledEnvironmentVariable ,
14+ KEY_VAULT_CONFIGURED_TAG ,
15+ KUBERNETES_ENV_VAR ,
16+ NODEJS_DEV_ENV_VAL ,
17+ NODEJS_ENV_VAR ,
18+ REQUEST_TYPE_KEY ,
1819 RequestType ,
19- RequestTypeKey ,
20- ServiceFabricEnvironmentVariable
20+ SERVICE_FABRIC_ENV_VAR
2121} from "./constants" ;
2222
2323// Utils
@@ -29,15 +29,15 @@ export function createCorrelationContextHeader(options: AzureAppConfigurationOpt
2929 UsersKeyVault
3030 */
3131 const keyValues = new Map < string , string | undefined > ( ) ;
32- keyValues . set ( RequestTypeKey , isInitialLoadCompleted ? RequestType . Watch : RequestType . Startup ) ;
33- keyValues . set ( HostTypeKey , getHostType ( ) ) ;
34- keyValues . set ( EnvironmentKey , isDevEnvironment ( ) ? DevEnvironmentValue : undefined ) ;
32+ keyValues . set ( REQUEST_TYPE_KEY , isInitialLoadCompleted ? RequestType . WATCH : RequestType . STARTUP ) ;
33+ keyValues . set ( HOST_TYPE_KEY , getHostType ( ) ) ;
34+ keyValues . set ( ENV_KEY , isDevEnvironment ( ) ? DEV_ENV_VAL : undefined ) ;
3535
3636 const tags : string [ ] = [ ] ;
3737 if ( options ?. keyVaultOptions ) {
3838 const { credential, secretClients, secretResolver } = options . keyVaultOptions ;
3939 if ( credential !== undefined || secretClients ?. length || secretResolver !== undefined ) {
40- tags . push ( KeyVaultConfiguredTag ) ;
40+ tags . push ( KEY_VAULT_CONFIGURED_TAG ) ;
4141 }
4242 }
4343
@@ -55,7 +55,7 @@ export function createCorrelationContextHeader(options: AzureAppConfigurationOpt
5555}
5656
5757export function requestTracingEnabled ( ) : boolean {
58- const requestTracingDisabledEnv = getEnvironmentVariable ( RequestTracingDisabledEnvironmentVariable ) ;
58+ const requestTracingDisabledEnv = getEnvironmentVariable ( ENV_AZURE_APP_CONFIGURATION_TRACING_DISABLED ) ;
5959 const disabled = requestTracingDisabledEnv ?. toLowerCase ( ) === "true" ;
6060 return ! disabled ;
6161}
@@ -71,27 +71,27 @@ function getEnvironmentVariable(name: string) {
7171
7272function getHostType ( ) : string | undefined {
7373 let hostType : string | undefined ;
74- if ( getEnvironmentVariable ( AzureFunctionEnvironmentVariable ) ) {
75- hostType = HostType . AzureFunction ;
76- } else if ( getEnvironmentVariable ( AzureWebAppEnvironmentVariable ) ) {
77- hostType = HostType . AzureWebApp ;
78- } else if ( getEnvironmentVariable ( ContainerAppEnvironmentVariable ) ) {
79- hostType = HostType . ContainerApp ;
80- } else if ( getEnvironmentVariable ( KubernetesEnvironmentVariable ) ) {
81- hostType = HostType . Kubernetes ;
82- } else if ( getEnvironmentVariable ( ServiceFabricEnvironmentVariable ) ) {
83- hostType = HostType . ServiceFabric ;
74+ if ( getEnvironmentVariable ( AZURE_FUNCTION_ENV_VAR ) ) {
75+ hostType = HostType . AZURE_FUNCTION ;
76+ } else if ( getEnvironmentVariable ( AZURE_WEB_APP_ENV_VAR ) ) {
77+ hostType = HostType . AZURE_WEB_APP ;
78+ } else if ( getEnvironmentVariable ( CONTAINER_APP_ENV_VAR ) ) {
79+ hostType = HostType . CONTAINER_APP ;
80+ } else if ( getEnvironmentVariable ( KUBERNETES_ENV_VAR ) ) {
81+ hostType = HostType . KUBERNETES ;
82+ } else if ( getEnvironmentVariable ( SERVICE_FABRIC_ENV_VAR ) ) {
83+ hostType = HostType . SERVICE_FABRIC ;
8484 } else if ( isBrowser ( ) ) {
85- hostType = HostType . Browser ;
85+ hostType = HostType . BROWSER ;
8686 } else if ( isWebWorker ( ) ) {
87- hostType = HostType . WebWorker ;
87+ hostType = HostType . WEB_WORKER ;
8888 }
8989 return hostType ;
9090}
9191
9292function isDevEnvironment ( ) : boolean {
93- const envType = getEnvironmentVariable ( NodeJSEnvironmentVariable ) ;
94- if ( NodeJSDevEnvironmentVariableValue === envType ?. toLowerCase ( ) ) {
93+ const envType = getEnvironmentVariable ( NODEJS_ENV_VAR ) ;
94+ if ( NODEJS_DEV_ENV_VAL === envType ?. toLowerCase ( ) ) {
9595 return true ;
9696 }
9797 return false ;
0 commit comments