@@ -20,29 +20,31 @@ import {
2020 RequestType ,
2121 SERVICE_FABRIC_ENV_VAR ,
2222 CORRELATION_CONTEXT_HEADER_NAME ,
23+ REPLICA_COUNT_KEY ,
2324 FAILOVER_REQUEST_TAG ,
2425 FEATURES_KEY ,
2526 LOAD_BALANCE_CONFIGURED_TAG
2627} from "./constants" ;
2728
29+ export interface RequestTracingOptions {
30+ enabled : boolean ;
31+ appConfigOptions : AzureAppConfigurationOptions | undefined ;
32+ initialLoadCompleted : boolean ;
33+ replicaCount : number ;
34+ isFailoverRequest : boolean ;
35+ }
36+
2837// Utils
2938export function listConfigurationSettingsWithTrace (
30- requestTracingOptions : {
31- requestTracingEnabled : boolean ;
32- initialLoadCompleted : boolean ;
33- appConfigOptions : AzureAppConfigurationOptions | undefined ;
34- isFailoverRequest : boolean ;
35- } ,
39+ requestTracingOptions : RequestTracingOptions ,
3640 client : AppConfigurationClient ,
3741 listOptions : ListConfigurationSettingsOptions
3842) {
39- const { requestTracingEnabled, initialLoadCompleted, appConfigOptions, isFailoverRequest } = requestTracingOptions ;
40-
4143 const actualListOptions = { ...listOptions } ;
42- if ( requestTracingEnabled ) {
44+ if ( requestTracingOptions . enabled ) {
4345 actualListOptions . requestOptions = {
4446 customHeaders : {
45- [ CORRELATION_CONTEXT_HEADER_NAME ] : createCorrelationContextHeader ( appConfigOptions , initialLoadCompleted , isFailoverRequest )
47+ [ CORRELATION_CONTEXT_HEADER_NAME ] : createCorrelationContextHeader ( requestTracingOptions )
4648 }
4749 } ;
4850 }
@@ -51,53 +53,61 @@ export function listConfigurationSettingsWithTrace(
5153}
5254
5355export function getConfigurationSettingWithTrace (
54- requestTracingOptions : {
55- requestTracingEnabled : boolean ;
56- initialLoadCompleted : boolean ;
57- appConfigOptions : AzureAppConfigurationOptions | undefined ;
58- isFailoverRequest : boolean ;
59- } ,
56+ requestTracingOptions : RequestTracingOptions ,
6057 client : AppConfigurationClient ,
6158 configurationSettingId : ConfigurationSettingId ,
6259 getOptions ?: GetConfigurationSettingOptions ,
6360) {
64- const { requestTracingEnabled, initialLoadCompleted, appConfigOptions, isFailoverRequest } = requestTracingOptions ;
6561 const actualGetOptions = { ...getOptions } ;
6662
67- if ( requestTracingEnabled ) {
63+ if ( requestTracingOptions . enabled ) {
6864 actualGetOptions . requestOptions = {
6965 customHeaders : {
70- [ CORRELATION_CONTEXT_HEADER_NAME ] : createCorrelationContextHeader ( appConfigOptions , initialLoadCompleted , isFailoverRequest )
66+ [ CORRELATION_CONTEXT_HEADER_NAME ] : createCorrelationContextHeader ( requestTracingOptions )
7167 }
7268 } ;
7369 }
7470
7571 return client . getConfigurationSetting ( configurationSettingId , actualGetOptions ) ;
7672}
7773
78- export function createCorrelationContextHeader ( options : AzureAppConfigurationOptions | undefined , isInitialLoadCompleted : boolean , isFailoverRequest : boolean ) : string {
74+ export function createCorrelationContextHeader ( requestTracingOptions : RequestTracingOptions ) : string {
7975 /*
8076 RequestType: 'Startup' during application starting up, 'Watch' after startup completed.
8177 Host: identify with defined envs
82- Env: identify by env `NODE_ENV` which is a popular but not standard.usually the value can be "development", "production".
78+ Env: identify by env `NODE_ENV` which is a popular but not standard. Usually, the value can be "development", "production".
79+ ReplicaCount: identify how many replicas are found
80+ Features: LB
8381 UsersKeyVault
82+ Failover
8483 */
8584 const keyValues = new Map < string , string | undefined > ( ) ;
86- keyValues . set ( REQUEST_TYPE_KEY , isInitialLoadCompleted ? RequestType . WATCH : RequestType . STARTUP ) ;
85+ const tags : string [ ] = [ ] ;
86+
87+ keyValues . set ( REQUEST_TYPE_KEY , requestTracingOptions . initialLoadCompleted ? RequestType . WATCH : RequestType . STARTUP ) ;
8788 keyValues . set ( HOST_TYPE_KEY , getHostType ( ) ) ;
8889 keyValues . set ( ENV_KEY , isDevEnvironment ( ) ? DEV_ENV_VAL : undefined ) ;
89- if ( options ?. loadBalancingEnabled ) {
90- keyValues . set ( FEATURES_KEY , LOAD_BALANCE_CONFIGURED_TAG ) ;
91- }
9290
93- const tags : string [ ] = [ ] ;
94- if ( options ?. keyVaultOptions ) {
95- const { credential, secretClients, secretResolver } = options . keyVaultOptions ;
91+ const appConfigOptions = requestTracingOptions . appConfigOptions ;
92+ if ( appConfigOptions ?. keyVaultOptions ) {
93+ const { credential, secretClients, secretResolver } = appConfigOptions . keyVaultOptions ;
9694 if ( credential !== undefined || secretClients ?. length || secretResolver !== undefined ) {
9795 tags . push ( KEY_VAULT_CONFIGURED_TAG ) ;
9896 }
9997 }
10098
99+ if ( requestTracingOptions . isFailoverRequest ) {
100+ tags . push ( FAILOVER_REQUEST_TAG ) ;
101+ }
102+ if ( requestTracingOptions . replicaCount > 0 ) {
103+ keyValues . set ( REPLICA_COUNT_KEY , requestTracingOptions . replicaCount . toString ( ) ) ;
104+ }
105+
106+ // Compact tags: Features=LB+...
107+ if ( appConfigOptions ?. loadBalancingEnabled ) {
108+ keyValues . set ( FEATURES_KEY , LOAD_BALANCE_CONFIGURED_TAG ) ;
109+ }
110+
101111 const contextParts : string [ ] = [ ] ;
102112 for ( const [ k , v ] of keyValues ) {
103113 if ( v !== undefined ) {
@@ -108,10 +118,6 @@ export function createCorrelationContextHeader(options: AzureAppConfigurationOpt
108118 contextParts . push ( tag ) ;
109119 }
110120
111- if ( isFailoverRequest ) {
112- contextParts . push ( FAILOVER_REQUEST_TAG ) ;
113- }
114-
115121 return contextParts . join ( "," ) ;
116122}
117123
0 commit comments