2020from newrelic .api .transaction import Sentinel , current_transaction
2121from newrelic .common .object_wrapper import wrap_function_wrapper
2222from newrelic .common .signature import bind_args
23+ from newrelic .core .config import global_settings
2324
2425_logger = logging .getLogger (__name__ )
2526_TRACER_PROVIDER = None
3435
3536
3637def wrap_set_tracer_provider (wrapped , instance , args , kwargs ):
38+ settings = global_settings ()
39+
40+ if not settings .otel_bridge .enabled :
41+ return wrapped (* args , ** kwargs )
42+
3743 global _TRACER_PROVIDER
3844 bound_args = bind_args (wrapped , args , kwargs )
3945 tracer_provider = bound_args .get ("tracer_provider" , None )
@@ -44,6 +50,11 @@ def wrap_set_tracer_provider(wrapped, instance, args, kwargs):
4450
4551
4652def wrap_get_tracer_provider (wrapped , instance , args , kwargs ):
53+ settings = global_settings ()
54+
55+ if not settings .otel_bridge .enabled :
56+ return wrapped (* args , ** kwargs )
57+
4758 from newrelic .api .opentelemetry import TracerProvider
4859
4960 # This needs to act as a singleton, like the agent instance.
@@ -70,6 +81,13 @@ def wrap_get_current_span(wrapped, instance, args, kwargs):
7081 if not transaction or isinstance (trace , Sentinel ):
7182 return wrapped (* args , ** kwargs )
7283
84+ # Do not allow the wrapper to continue if
85+ # the Hybrid Agent setting is not enabled
86+ settings = transaction .settings or global_settings ()
87+
88+ if not settings .otel_bridge .enabled :
89+ return wrapped (* args , ** kwargs )
90+
7391 # If a NR trace does exist, check to see if the current
7492 # OTel span corresponds to the current NR trace. If so,
7593 # return the original function's result.
@@ -119,6 +137,13 @@ def wrap_start_internal_or_server_span(wrapped, instance, args, kwargs):
119137 # and put that into the attributes. Keep the original
120138 # context_carrier intact.
121139
140+ # Do not allow the wrapper to continue if
141+ # the Hybrid Agent setting is not enabled
142+ settings = global_settings ()
143+
144+ if not settings .otel_bridge .enabled :
145+ return wrapped (* args , ** kwargs )
146+
122147 bound_args = bind_args (wrapped , args , kwargs )
123148 context_carrier = bound_args .get ("context_carrier" , None )
124149 attributes = bound_args .get ("attributes" , {})
0 commit comments