2020 # immediately patch logging if trace id injected
2121 from ddtrace import patch ; patch (logging = True ) # noqa
2222
23- debug = os .environ .get (" DATADOG_TRACE_DEBUG" )
23+ debug = os .environ .get (' DATADOG_TRACE_DEBUG' )
2424
2525# Set here a default logging format for basicConfig
2626
2727# DEV: Once basicConfig is called here, future calls to it cannot be used to
2828# change the formatter since it applies the formatter to the root handler only
2929# upon initializing it the first time.
3030# See https://github.com/python/cpython/blob/112e4afd582515fcdcc0cde5012a4866e5cfda12/Lib/logging/__init__.py#L1550
31- if debug and debug .lower () == " true" :
31+ if debug and debug .lower () == ' true' :
3232 logging .basicConfig (level = logging .DEBUG , format = DD_LOG_FORMAT )
3333else :
3434 logging .basicConfig (format = DD_LOG_FORMAT )
3535
3636log = get_logger (__name__ )
3737
3838EXTRA_PATCHED_MODULES = {
39- " bottle" : True ,
40- " django" : True ,
41- " falcon" : True ,
42- " flask" : True ,
43- " pylons" : True ,
44- " pyramid" : True ,
39+ ' bottle' : True ,
40+ ' django' : True ,
41+ ' falcon' : True ,
42+ ' flask' : True ,
43+ ' pylons' : True ,
44+ ' pyramid' : True ,
4545}
4646
4747
4848def update_patched_modules ():
49- modules_to_patch = os .environ .get (" DATADOG_PATCH_MODULES" )
49+ modules_to_patch = os .environ .get (' DATADOG_PATCH_MODULES' )
5050 if not modules_to_patch :
5151 return
5252 for patch in modules_to_patch .split (',' ):
5353 if len (patch .split (':' )) != 2 :
54- log .debug (" skipping malformed patch instruction" )
54+ log .debug (' skipping malformed patch instruction' )
5555 continue
5656
5757 module , should_patch = patch .split (':' )
5858 if should_patch .lower () not in ['true' , 'false' ]:
59- log .debug (" skipping malformed patch instruction for %s" , module )
59+ log .debug (' skipping malformed patch instruction for %s' , module )
6060 continue
6161
6262 EXTRA_PATCHED_MODULES .update ({module : should_patch .lower () == 'true' })
@@ -81,22 +81,22 @@ def add_global_tags(tracer):
8181 # Respect DATADOG_* environment variables in global tracer configuration
8282 # TODO: these variables are deprecated; use utils method and update our documentation
8383 # correct prefix should be DD_*
84- enabled = os .environ .get (" DATADOG_TRACE_ENABLED" )
84+ enabled = os .environ .get (' DATADOG_TRACE_ENABLED' )
8585 hostname = os .environ .get ('DD_AGENT_HOST' , os .environ .get ('DATADOG_TRACE_AGENT_HOSTNAME' ))
86- port = os .environ .get (" DATADOG_TRACE_AGENT_PORT" )
87- priority_sampling = os .environ .get (" DATADOG_PRIORITY_SAMPLING" )
86+ port = os .environ .get (' DATADOG_TRACE_AGENT_PORT' )
87+ priority_sampling = os .environ .get (' DATADOG_PRIORITY_SAMPLING' )
8888
8989 opts = {}
9090
91- if enabled and enabled .lower () == " false" :
92- opts [" enabled" ] = False
91+ if enabled and enabled .lower () == ' false' :
92+ opts [' enabled' ] = False
9393 patch = False
9494 if hostname :
95- opts [" hostname" ] = hostname
95+ opts [' hostname' ] = hostname
9696 if port :
97- opts [" port" ] = int (port )
97+ opts [' port' ] = int (port )
9898 if priority_sampling :
99- opts [" priority_sampling" ] = asbool (priority_sampling )
99+ opts [' priority_sampling' ] = asbool (priority_sampling )
100100
101101 opts ['collect_metrics' ] = asbool (get_env ('runtime_metrics' , 'enabled' ))
102102
@@ -110,12 +110,12 @@ def add_global_tags(tracer):
110110 update_patched_modules ()
111111 from ddtrace import patch_all ; patch_all (** EXTRA_PATCHED_MODULES ) # noqa
112112
113- debug = os .environ .get (" DATADOG_TRACE_DEBUG" )
114- if debug and debug .lower () == " true" :
113+ debug = os .environ .get (' DATADOG_TRACE_DEBUG' )
114+ if debug and debug .lower () == ' true' :
115115 tracer .debug_logging = True
116116
117117 if 'DATADOG_ENV' in os .environ :
118- tracer .set_tags ({" env" : os .environ [" DATADOG_ENV" ]})
118+ tracer .set_tags ({' env' : os .environ [' DATADOG_ENV' ]})
119119
120120 if 'DD_TRACE_GLOBAL_TAGS' in os .environ :
121121 add_global_tags (tracer )
@@ -145,4 +145,4 @@ def add_global_tags(tracer):
145145 loaded = True
146146except Exception as e :
147147 loaded = False
148- log .warn (" error configuring Datadog tracing" , exc_info = True )
148+ log .warn (' error configuring Datadog tracing' , exc_info = True )
0 commit comments