@@ -319,4 +319,95 @@ def get_disable_trace_configurations_from_local() -> Tuple[List[str], List[str]]
319319 return [], []
320320
321321
322+ def get_stack_trace_config_from_yaml () -> Tuple [str , int , Dict [str , Dict [str , Union [str , int ]]]]:
323+ """
324+ Get stack trace configuration from YAML file specified by INSTANA_CONFIG_PATH.
325+
326+ Returns:
327+ Tuple of (level, length, tech_config) where:
328+ - level: "all", "error", or "none"
329+ - length: positive integer
330+ - tech_config: Dict of technology-specific overrides
331+ Format: {"kafka": {"level": "all", "length": 35}, "redis": {"level": "none"}}
332+ """
333+ config_reader = ConfigReader (os .environ .get ("INSTANA_CONFIG_PATH" , "" ))
334+
335+ level = "all"
336+ length = 30
337+ tech_config = {}
338+
339+ if "tracing" in config_reader .data :
340+ root_key = "tracing"
341+ elif "com.instana.tracing" in config_reader .data :
342+ logger .warning (
343+ 'Please use "tracing" instead of "com.instana.tracing" for local configuration file.'
344+ )
345+ root_key = "com.instana.tracing"
346+ else :
347+ return level , length , tech_config
348+
349+ tracing_data = config_reader .data [root_key ]
350+
351+ # Read global configuration
352+ if "global" in tracing_data :
353+ global_config = tracing_data ["global" ]
354+
355+ if "stack-trace" in global_config :
356+ config_level = global_config ["stack-trace" ].lower ()
357+ if config_level in ["all" , "error" , "none" ]:
358+ level = config_level
359+ else :
360+ logger .warning (
361+ f"Invalid stack-trace value in config: { config_level } . Must be 'all', 'error', or 'none'. Using default 'all'"
362+ )
363+
364+ if "stack-trace-length" in global_config :
365+ try :
366+ config_length = int (global_config ["stack-trace-length" ])
367+ if config_length >= 1 :
368+ length = config_length
369+ else :
370+ logger .warning (
371+ "stack-trace-length must be positive. Using default 30"
372+ )
373+ except (ValueError , TypeError ):
374+ logger .warning (
375+ "Invalid stack-trace-length in config. Must be an integer. Using default 30"
376+ )
377+
378+ # Read technology-specific overrides
379+ for tech_name , tech_data in tracing_data .items ():
380+ if tech_name == "global" or not isinstance (tech_data , dict ):
381+ continue
382+
383+ tech_stack_config = {}
384+
385+ if "stack-trace" in tech_data :
386+ tech_level = str (tech_data ["stack-trace" ]).lower ()
387+ if tech_level in ["all" , "error" , "none" ]:
388+ tech_stack_config ["level" ] = tech_level
389+ else :
390+ logger .warning (
391+ f"Invalid stack-trace value for { tech_name } in YAML: { tech_level } . Ignoring."
392+ )
393+
394+ if "stack-trace-length" in tech_data :
395+ try :
396+ tech_length = int (tech_data ["stack-trace-length" ])
397+ if tech_length >= 1 :
398+ tech_stack_config ["length" ] = tech_length
399+ else :
400+ logger .warning (
401+ f"stack-trace-length for { tech_name } must be positive. Ignoring."
402+ )
403+ except (ValueError , TypeError ):
404+ logger .warning (
405+ f"Invalid stack-trace-length for { tech_name } in YAML. Must be an integer. Ignoring."
406+ )
407+
408+ if tech_stack_config :
409+ tech_config [tech_name ] = tech_stack_config
410+
411+ return level , length , tech_config
412+
322413# Made with Bob
0 commit comments