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