@@ -115,6 +115,11 @@ def set_trace_configurations(self) -> None:
115115 "trace_correlation" , True
116116 )
117117
118+ if "INSTANA_ASYNCIO_TASK_CONTEXT_PROPAGATION" in os .environ :
119+ config ["asyncio_task_context_propagation" ]["enabled" ] = is_truthy (
120+ os .environ ["INSTANA_ASYNCIO_TASK_CONTEXT_PROPAGATION" ]
121+ )
122+
118123 self .set_disable_trace_configurations ()
119124 self .set_stack_trace_configurations ()
120125 self .set_span_filter_configurations ()
@@ -397,34 +402,10 @@ def set_tracing(self, tracing: Dict[str, Any]) -> None:
397402 @return: None
398403 """
399404 if "filter" in tracing and not self ._has_high_priority_span_filter_source ():
400- parsed = parse_filter_rules (tracing ["filter" ])
401- for policy in ("exclude" , "include" ):
402- rules = parsed .get (policy , [])
403- if rules :
404- if policy not in self .span_filters :
405- self .span_filters [policy ] = []
406- self .span_filters [policy ].extend (rules )
405+ self ._apply_agent_filter_config (tracing ["filter" ])
407406
408407 if "kafka" in tracing :
409- if (
410- "INSTANA_KAFKA_TRACE_CORRELATION" not in os .environ
411- and not (
412- isinstance (config .get ("tracing" ), dict )
413- and "kafka" in config ["tracing" ]
414- )
415- and "trace-correlation" in tracing ["kafka" ]
416- ):
417- self .kafka_trace_correlation = is_truthy (
418- tracing ["kafka" ].get ("trace-correlation" , True )
419- )
420-
421- if (
422- "header-format" in tracing ["kafka" ]
423- and tracing ["kafka" ]["header-format" ] == "binary"
424- ):
425- logger .warning (
426- "Binary header format for Kafka is deprecated. Please use string header format."
427- )
408+ self ._apply_agent_kafka_config (tracing ["kafka" ])
428409
429410 if "extra-http-headers" in tracing :
430411 self .extra_http_headers = tracing ["extra-http-headers" ]
@@ -436,6 +417,32 @@ def set_tracing(self, tracing: Dict[str, Any]) -> None:
436417 # Handle stack trace configuration from agent config
437418 self .set_stack_trace_from_agent (tracing )
438419
420+ def _apply_agent_filter_config (self , filter_config : Any ) -> None :
421+ """Apply span filter rules from agent config."""
422+ parsed = parse_filter_rules (filter_config )
423+ for policy in ("exclude" , "include" ):
424+ rules = parsed .get (policy , [])
425+ if rules :
426+ if policy not in self .span_filters :
427+ self .span_filters [policy ] = []
428+ self .span_filters [policy ].extend (rules )
429+
430+ def _apply_agent_kafka_config (self , kafka_config : Dict [str , Any ]) -> None :
431+ """Apply Kafka tracing configuration from agent config."""
432+ no_env_override = "INSTANA_KAFKA_TRACE_CORRELATION" not in os .environ
433+ no_code_override = not (
434+ isinstance (config .get ("tracing" ), dict ) and "kafka" in config ["tracing" ]
435+ )
436+ if no_env_override and no_code_override and "trace-correlation" in kafka_config :
437+ self .kafka_trace_correlation = is_truthy (
438+ kafka_config .get ("trace-correlation" , True )
439+ )
440+
441+ if kafka_config .get ("header-format" ) == "binary" :
442+ logger .warning (
443+ "Binary header format for Kafka is deprecated. Please use string header format."
444+ )
445+
439446 def _has_high_priority_span_filter_source (self ) -> bool :
440447 """Return True if a higher-priority span filter source (env var, YAML, or in-code config)
441448 has already been configured, in which case the agent-provided filter should be ignored."""
0 commit comments