1616from instana .log import logger
1717from instana .singletons import agent , get_tracer
1818from instana .span .span import get_current_span
19+ from instana .span .span import InstanaSpan
1920
2021if TYPE_CHECKING :
21- from instana .span .span import InstanaSpan
2222 from instana .tracer import InstanaTracer
2323
2424
@@ -62,22 +62,6 @@ def extract_custom_headers(
6262 logger .debug ("extract_custom_headers: " , exc_info = True )
6363
6464
65- def get_active_tracer () -> Optional ["InstanaTracer" ]:
66- """Get the currently active tracer if one exists."""
67- try :
68- current_span = get_current_span ()
69- if current_span :
70- # asyncio Spans are used as NonRecording Spans solely for context propagation
71- if current_span .is_recording () or current_span .name == "asyncio" :
72- return get_tracer ()
73- return None
74- return None
75- except Exception :
76- # Do not try to log this with instana, as there is no active tracer and there will be an infinite loop at least
77- # for PY2
78- return None
79-
80-
8165def get_tracer_tuple () -> (
8266 Tuple [
8367 Optional ["InstanaTracer" ],
@@ -86,15 +70,17 @@ def get_tracer_tuple() -> (
8670 ]
8771):
8872 """Get a tuple of (tracer, span, span_name) for the current context."""
89- active_tracer = get_active_tracer ()
90- current_span = get_current_span ()
91- if active_tracer :
92- return (active_tracer , current_span , current_span .name )
93- elif agent .options .allow_exit_as_root :
94- return (get_tracer (), None , None )
95- return (None , None , None )
96-
97-
98- def tracing_is_off () -> bool :
99- """Check if tracing is currently disabled."""
100- return not (bool (get_active_tracer ()) or agent .options .allow_exit_as_root )
73+ try :
74+ active_tracer = get_tracer ()
75+ current_span = get_current_span ()
76+ # asyncio Spans are used as NonRecording Spans solely for context propagation
77+ if current_span and isinstance (current_span , InstanaSpan ):
78+ if current_span .is_recording () or current_span .name == "asyncio" :
79+ return (active_tracer , current_span , current_span .name )
80+ elif agent .options .allow_exit_as_root :
81+ return (active_tracer , None , None )
82+ return (None , None , None )
83+ except Exception :
84+ # Do not try to log this with instana, as there is no active tracer and there will be an infinite loop at least
85+ # for PY2
86+ return (None , None , None )
0 commit comments