8
8
from collections .abc import Mapping
9
9
10
10
from ..log import logger
11
- from ..util .traceutils import get_active_tracer
11
+ from ..util .traceutils import get_tracer_tuple , tracing_is_off
12
12
13
13
14
14
@wrapt .patch_function_wrapper ('logging' , 'Logger._log' )
@@ -17,33 +17,34 @@ def log_with_instana(wrapped, instance, argv, kwargs):
17
17
# argv[1] = message
18
18
# argv[2] = args for message
19
19
try :
20
- active_tracer = get_active_tracer ()
20
+ tracer , parent_span , _ = get_tracer_tuple ()
21
21
22
22
# Only needed if we're tracing and serious log
23
- if active_tracer and argv [0 ] >= logging .WARN :
24
-
25
- msg = str (argv [1 ])
26
- args = argv [2 ]
27
- if args and len (args ) == 1 and isinstance (args [0 ], Mapping ) and args [0 ]:
28
- args = args [0 ]
29
-
30
- # get the formatted log message
31
- msg = msg % args
32
-
33
- # get additional information if an exception is being handled
34
- parameters = None
35
- (t , v , tb ) = sys .exc_info ()
36
- if t is not None and v is not None :
37
- parameters = '{} {}' .format (t , v )
38
-
39
- # create logging span
40
- with active_tracer .start_active_span ('log' , child_of = active_tracer .active_span ) as scope :
41
- scope .span .log_kv ({ 'message' : msg })
42
- if parameters is not None :
43
- scope .span .log_kv ({ 'parameters' : parameters })
44
- # extra tags for an error
45
- if argv [0 ] >= logging .ERROR :
46
- scope .span .mark_as_errored ()
23
+ if tracing_is_off () or argv [0 ] < logging .WARN :
24
+ return wrapped (* argv , ** kwargs )
25
+
26
+ msg = str (argv [1 ])
27
+ args = argv [2 ]
28
+ if args and len (args ) == 1 and isinstance (args [0 ], Mapping ) and args [0 ]:
29
+ args = args [0 ]
30
+
31
+ # get the formatted log message
32
+ msg = msg % args
33
+
34
+ # get additional information if an exception is being handled
35
+ parameters = None
36
+ (t , v , tb ) = sys .exc_info ()
37
+ if t is not None and v is not None :
38
+ parameters = '{} {}' .format (t , v )
39
+
40
+ # create logging span
41
+ with tracer .start_active_span ('log' , child_of = parent_span ) as scope :
42
+ scope .span .log_kv ({ 'message' : msg })
43
+ if parameters is not None :
44
+ scope .span .log_kv ({ 'parameters' : parameters })
45
+ # extra tags for an error
46
+ if argv [0 ] >= logging .ERROR :
47
+ scope .span .mark_as_errored ()
47
48
except Exception :
48
49
logger .debug ('log_with_instana:' , exc_info = True )
49
50
0 commit comments