@@ -44,32 +44,32 @@ def wrapper( # type: ignore[misc]
4444 ** kwargs : typing .Dict [typing .Any , typing .Any ],
4545 ) -> typing .Optional [typing .Any ]:
4646 global _RUNTIME_CONTEXT # pylint: disable=global-statement
47-
48- with _RUNTIME_CONTEXT_LOCK :
49- if _RUNTIME_CONTEXT is None :
50- # FIXME use a better implementation of a configuration manager
51- # to avoid having to get configuration values straight from
52- # environment variables
53- default_context = "contextvars_context"
54-
55- configured_context = environ .get (
56- OTEL_PYTHON_CONTEXT , default_context
57- ) # type: str
58- try :
59-
60- _RUNTIME_CONTEXT = next ( # type: ignore
61- iter ( # type: ignore
62- entry_points ( # type: ignore
63- group = "opentelemetry_context" ,
64- name = configured_context ,
47+ if _RUNTIME_CONTEXT is None :
48+ with _RUNTIME_CONTEXT_LOCK :
49+ if _RUNTIME_CONTEXT is None :
50+ # FIXME use a better implementation of a configuration manager
51+ # to avoid having to get configuration values straight from
52+ # environment variables
53+ default_context = "contextvars_context"
54+
55+ configured_context = environ .get (
56+ OTEL_PYTHON_CONTEXT , default_context
57+ ) # type: str
58+ try :
59+
60+ _RUNTIME_CONTEXT = next ( # type: ignore
61+ iter ( # type: ignore
62+ entry_points ( # type: ignore
63+ group = "opentelemetry_context" ,
64+ name = configured_context ,
65+ )
6566 )
66- )
67- ).load ()()
67+ ).load ()()
6868
69- except Exception : # pylint: disable=broad-except
70- logger .exception (
71- "Failed to load context: %s" , configured_context
72- )
69+ except Exception : # pylint: disable=broad-except
70+ logger .exception (
71+ "Failed to load context: %s" , configured_context
72+ )
7373 return func (* args , ** kwargs ) # type: ignore[misc]
7474
7575 return typing .cast (_F , wrapper ) # type: ignore[misc]
0 commit comments