@@ -392,7 +392,15 @@ function normalizeTracingHttp({ userConfig = {}, defaultConfig = {}, finalConfig
392392
393393 const userHeaders = userHttp ?. extraHttpHeadersToCapture ;
394394
395- // 1. Check in-code configuration first
395+ // 1. Check environment variable
396+ if ( process . env . INSTANA_EXTRA_HTTP_HEADERS ) {
397+ const fromEnvVar = parseHeadersEnvVar ( process . env . INSTANA_EXTRA_HTTP_HEADERS ) ;
398+ finalConfig . tracing . http . extraHttpHeadersToCapture = fromEnvVar ;
399+ logger . debug ( `[config] env:INSTANA_EXTRA_HTTP_HEADERS = ${ process . env . INSTANA_EXTRA_HTTP_HEADERS } ` ) ;
400+ return ;
401+ }
402+
403+ // 2. Check in-code configuration
396404 if ( userHeaders !== undefined ) {
397405 if ( ! Array . isArray ( userHeaders ) ) {
398406 logger . warn (
@@ -408,14 +416,6 @@ function normalizeTracingHttp({ userConfig = {}, defaultConfig = {}, finalConfig
408416 }
409417 }
410418
411- // 2. Check environment variable
412- if ( process . env . INSTANA_EXTRA_HTTP_HEADERS ) {
413- const fromEnvVar = parseHeadersEnvVar ( process . env . INSTANA_EXTRA_HTTP_HEADERS ) ;
414- finalConfig . tracing . http . extraHttpHeadersToCapture = fromEnvVar ;
415- logger . debug ( `[config] env:INSTANA_EXTRA_HTTP_HEADERS = ${ process . env . INSTANA_EXTRA_HTTP_HEADERS } ` ) ;
416- return ;
417- }
418-
419419 // 3. Use default configuration
420420 finalConfig . tracing . http . extraHttpHeadersToCapture = defaultConfig . tracing . http . extraHttpHeadersToCapture ;
421421}
@@ -448,6 +448,7 @@ function normalizeTracingStackTrace({ userConfig = {}, defaultConfig = {}, final
448448 const envStackTrace = process . env . INSTANA_STACK_TRACE ;
449449 const envStackTraceLength = process . env . INSTANA_STACK_TRACE_LENGTH ;
450450
451+ // Priority 1: Environment variable
451452 if ( envStackTrace !== undefined ) {
452453 const result = validateStackTraceMode ( envStackTrace ) ;
453454
@@ -463,6 +464,7 @@ function normalizeTracingStackTrace({ userConfig = {}, defaultConfig = {}, final
463464 finalConfig . tracing . stackTrace = defaultConfig . tracing . stackTrace ;
464465 }
465466 } else if ( userGlobal ?. stackTrace !== undefined ) {
467+ // Priority 2: In-code configuration
466468 const result = validateStackTraceMode ( userGlobal . stackTrace ) ;
467469
468470 if ( result . isValid ) {
@@ -483,6 +485,7 @@ function normalizeTracingStackTrace({ userConfig = {}, defaultConfig = {}, final
483485 const isLegacyLengthDefined = userTracingConfig ?. stackTraceLength !== undefined ;
484486 const stackTraceConfigValue = userGlobal ?. stackTraceLength || userTracingConfig ?. stackTraceLength ;
485487
488+ // Priority 1: Environment variable
486489 if ( envStackTraceLength !== undefined ) {
487490 const result = validateStackTraceLength ( envStackTraceLength ) ;
488491
@@ -498,6 +501,7 @@ function normalizeTracingStackTrace({ userConfig = {}, defaultConfig = {}, final
498501 finalConfig . tracing . stackTraceLength = defaultConfig . tracing . stackTraceLength ;
499502 }
500503 } else if ( stackTraceConfigValue !== undefined ) {
504+ // Priority 2: In-code configuration
501505 if ( isLegacyLengthDefined ) {
502506 logger . warn (
503507 // eslint-disable-next-line max-len
0 commit comments