@@ -94,7 +94,7 @@ def test_read_span_stack_config_from_env_with_no_env_vars
9494
9595 assert_equal "error" , subject [ :back_trace ] [ :stack_trace_level ]
9696 assert_equal 30 , subject [ :back_trace ] [ :stack_trace_length ]
97- assert_equal 'default ' , subject [ :back_trace ] [ :config_source ]
97+ assert_equal 'env ' , subject [ :back_trace ] [ :config_source ]
9898 end
9999
100100 def test_read_span_stack_config_from_env_converts_length_to_integer
@@ -248,7 +248,7 @@ def test_read_span_stack_config_yaml_missing_global_section
248248 ENV . delete ( 'INSTANA_CONFIG_PATH' )
249249 end
250250
251- def test_read_span_stack_config_yaml_takes_precedence_over_env
251+ def test_read_span_stack_config_env_takes_precedence_over_yaml
252252 yaml_content = <<~YAML
253253 tracing:
254254 global:
@@ -263,10 +263,10 @@ def test_read_span_stack_config_yaml_takes_precedence_over_env
263263
264264 subject = Instana ::Config . new ( logger : Logger . new ( '/dev/null' ) )
265265
266- # YAML should take precedence
267- assert_equal 'all ' , subject [ :back_trace ] [ :stack_trace_level ]
268- assert_equal 50 , subject [ :back_trace ] [ :stack_trace_length ]
269- assert_equal 'yaml ' , subject [ :back_trace ] [ :config_source ]
266+ # Environment variables should take precedence
267+ assert_equal 'none ' , subject [ :back_trace ] [ :stack_trace_level ]
268+ assert_equal 5 , subject [ :back_trace ] [ :stack_trace_length ]
269+ assert_equal 'env ' , subject [ :back_trace ] [ :config_source ]
270270 ensure
271271 File . unlink ( 'test_stack_config.yaml' ) if File . exist? ( 'test_stack_config.yaml' )
272272 ENV . delete ( 'INSTANA_CONFIG_PATH' )
@@ -376,9 +376,35 @@ def test_read_config_from_agent_with_nil_discovery
376376 assert_equal original_config , subject [ :back_trace ]
377377 end
378378
379- # Tests for configuration priority: YAML > Env > Agent > Default
379+ # Tests for configuration priority: Env > YAML > Agent > Default
380+
381+ def test_priority_env_over_yaml
382+ yaml_content = <<~YAML
383+ tracing:
384+ global:
385+ stack-trace: all
386+ stack-trace-length: 50
387+ YAML
388+
389+ File . write ( 'test_stack_config.yaml' , yaml_content )
390+ ENV [ 'INSTANA_CONFIG_PATH' ] = 'test_stack_config.yaml'
391+ ENV [ 'INSTANA_STACK_TRACE' ] = 'none'
392+ ENV [ 'INSTANA_STACK_TRACE_LENGTH' ] = '10'
393+
394+ subject = Instana ::Config . new ( logger : Logger . new ( '/dev/null' ) )
395+
396+ # Environment variables should take precedence over YAML
397+ assert_equal 'none' , subject [ :back_trace ] [ :stack_trace_level ]
398+ assert_equal 10 , subject [ :back_trace ] [ :stack_trace_length ]
399+ assert_equal 'env' , subject [ :back_trace ] [ :config_source ]
400+ ensure
401+ File . unlink ( 'test_stack_config.yaml' ) if File . exist? ( 'test_stack_config.yaml' )
402+ ENV . delete ( 'INSTANA_CONFIG_PATH' )
403+ ENV . delete ( 'INSTANA_STACK_TRACE' )
404+ ENV . delete ( 'INSTANA_STACK_TRACE_LENGTH' )
405+ end
380406
381- def test_priority_yaml_over_agent
407+ def test_priority_yaml_over_agent_when_no_env
382408 yaml_content = <<~YAML
383409 tracing:
384410 global:
@@ -402,7 +428,7 @@ def test_priority_yaml_over_agent
402428 }
403429 subject . read_config_from_agent ( discovery )
404430
405- # YAML should take precedence
431+ # YAML should take precedence over agent (when no env vars)
406432 assert_equal 'none' , subject [ :back_trace ] [ :stack_trace_level ]
407433 assert_equal 10 , subject [ :back_trace ] [ :stack_trace_length ]
408434 assert_equal 'yaml' , subject [ :back_trace ] [ :config_source ]
@@ -635,7 +661,7 @@ def test_read_config_from_agent_with_technology_specific_config
635661 assert_nil redis_config [ :stack_trace_length ]
636662 end
637663
638- def test_yaml_technology_config_not_overridden_by_agent
664+ def test_yaml_technology_config_not_overridden_by_agent_when_no_env
639665 yaml_content = <<~YAML
640666 tracing:
641667 global:
@@ -667,7 +693,7 @@ def test_yaml_technology_config_not_overridden_by_agent
667693 }
668694 subject . read_config_from_agent ( discovery )
669695
670- # YAML should take precedence for both global and technology-specific
696+ # YAML should take precedence for both global and technology-specific (when no env vars)
671697 assert_equal 'none' , subject [ :back_trace ] [ :stack_trace_level ]
672698 assert_equal 10 , subject [ :back_trace ] [ :stack_trace_length ]
673699 assert_equal 'yaml' , subject [ :back_trace ] [ :config_source ]
0 commit comments