Skip to content

Commit d7a9c04

Browse files
committed
feat: Add stack trace support to technology-specific configuration overrides
Signed-off-by: Varsha GS <[email protected]>
1 parent ec422c0 commit d7a9c04

File tree

2 files changed

+97
-4
lines changed

2 files changed

+97
-4
lines changed

src/instana/span/stack_trace.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,21 +136,23 @@ def add_stack_trace_if_needed(span: "InstanaSpan") -> None:
136136
Add stack trace to span based on configuration before span ends.
137137
138138
This function checks if the span is an EXIT span and if so, captures
139-
a stack trace based on the configured level and limit.
139+
a stack trace based on the configured level and limit. It supports
140+
technology-specific configuration overrides via get_stack_trace_config().
140141
141142
Args:
142143
span: The InstanaSpan to potentially add stack trace to
143144
"""
144145
if span.name in EXIT_SPANS:
145-
# Get configuration from agent options
146+
# Get configuration from agent options (with technology-specific overrides)
146147
options = span._span_processor.agent.options
148+
level, limit = options.get_stack_trace_config(span.name)
147149

148150
# Check if span is errored
149151
is_errored = span.attributes.get("ec", 0) > 0
150152

151153
# Capture stack trace using add_stack function
152154
span.stack = add_stack(
153-
level=options.stack_trace_level,
154-
limit=options.stack_trace_length,
155+
level=level,
156+
limit=limit,
155157
is_errored=is_errored
156158
)

src/instana/util/config.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)