You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes I want to disable the instrumentation, and rather than override the ENTRYPOINT or CMD of the container from the Deployment (which requires copying the other parameters out into the kubernetes resource without opentelemetry-instrument) or adding additional complexity into the Dockerfile, I'd like an env-var to disable the auto-instrumentation.
Describe the solution you'd like
As it happens, there are appropriate env-vars: OTEL_PYTHON_TRACER_PROVIDER, OTEL_PYTHON_METER_PROVIDER, and OTEL_PYTHON_LOG_EMITTER_PROVIDER, which I would happily set to default, to use the NoOpXProvider entry-points from opentelemetry-api, rather than the default behaviour (equivalent to sdk from the opentelemetry-sdk entrypoints.
However, there's two issues there:
There's no NoOpLogEmitterProvider or even an ABC for LogEmitterProvider. This would need to be added to the opentelemetry-sdk package, since it's not part of the OpenTelemetry API.
_OTelSDKConfigurator._configure calls _initialize_components, and the functions the latter calls do not honour the *_PROVIDER env-vars as they call set_X_provider directly. The env-vars are processed by get_X_provider if set_X_provider has not already been called.
The latter point is interesting as, because of the way opentelemetry-instrument works, it offers those env-vars as command-line options. (Well, not the logger, right now, as the variable starts with _, as did the metrics env-var before 1.12).
Describe alternatives you've considered
Copying the command-line to run without OpenTelemetry into the kubernetes Deployment.
Generating a separate container image with stripped command-line, so that only the default ProxyXProviders are loaded. (I can then use the env-vars to specify default as described above.
Adding my own BaseDistro implementation that implements support for OTEL_PYTHON_X_PROVIDER, and using that instead.
Technically, what I would be adding is an _OTelSDKConfigurator subclass, as that's the thing that triggers _initialize_components. There's no actual tie between a distro entry point and a configurator entry point, so DefaultDistro would be fine as-is.
If I was doing that, I'd probably ignore OTEL_PYTHON_X_PROVIDER and just provide a big "Disable everything" switch instead which skips all setup.
Adding a command-line and env-var to opentelemetry-instrument which disables auto-instrumentation completely, somewhat along the lines of OTEL_PYTHON_DISABLED_INSTRUMENTATIONS but earlying-out of initialize in sitecustomize.py.
For logging, I see that OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED has just been added by Support logs SDK auto instrumentation enable/disable with env #2728 (and which defaults to false, and isn't visible in opentelemetry-instrumentation help), which has a similar effect, but inside _initialize_components. So maybe OTEL_PYTHON_AUTO_INSTRUMENTATION_ENABLED is the generalised version of that.
OpenTelemetryDistro should not set OTEL_TRACES_EXPORTER if it is not already set, but leave that to the user, as it does for logs and metrics, although with stabilisation of metrics in v1.12, I guess that'll change to enable OTEL_METRICS_EXPORTER instead.
I ended up doing this, but in-passing for creating a project-local OTel Distribution library as a temporary fix for other things.
Additional context
I also noticed an odd issue that the get_X_provider code is set up to use default_X if the environment variable is not set, but the callers all ensure the environment variable is set before calling it. Perhaps the default_X entrypoints should point at the ProxyXProvider (except for logging, where that doesn't make sense, and since the code lives in the SDK, it can declare its own provider as default), and a noop_X entry-point could be used for the no-op providers explicitly, then we could always call opentelemetry.util._providers._load_provider and let its env-var handling do the heavy lifting.
It also might make sense to make _load_provider take a default provider to use if the env-var is not set, rather than falling back to default_X if the env-var is not set. Or just remove the "env-var not set" support from _load_provider.
Is your feature request related to a problem?
I am auto-instrumenting a process in a container in kubernetes, and have this in my Dockerfile:
Sometimes I want to disable the instrumentation, and rather than override the
ENTRYPOINTorCMDof the container from the Deployment (which requires copying the other parameters out into the kubernetes resource withoutopentelemetry-instrument) or adding additional complexity into the Dockerfile, I'd like an env-var to disable the auto-instrumentation.Describe the solution you'd like
As it happens, there are appropriate env-vars:
OTEL_PYTHON_TRACER_PROVIDER,OTEL_PYTHON_METER_PROVIDER, andOTEL_PYTHON_LOG_EMITTER_PROVIDER, which I would happily set todefault, to use theNoOpXProviderentry-points from opentelemetry-api, rather than the default behaviour (equivalent tosdkfrom the opentelemetry-sdk entrypoints.However, there's two issues there:
NoOpLogEmitterProvideror even an ABC forLogEmitterProvider. This would need to be added to the opentelemetry-sdk package, since it's not part of the OpenTelemetry API._OTelSDKConfigurator._configurecalls_initialize_components, and the functions the latter calls do not honour the*_PROVIDERenv-vars as they callset_X_providerdirectly. The env-vars are processed byget_X_providerifset_X_providerhas not already been called.The latter point is interesting as, because of the way
opentelemetry-instrumentworks, it offers those env-vars as command-line options. (Well, not the logger, right now, as the variable starts with_, as did the metrics env-var before 1.12).Describe alternatives you've considered
ProxyXProvidersare loaded. (I can then use the env-vars to specifydefaultas described above.BaseDistroimplementation that implements support forOTEL_PYTHON_X_PROVIDER, and using that instead._OTelSDKConfiguratorsubclass, as that's the thing that triggers_initialize_components. There's no actual tie between a distro entry point and a configurator entry point, soDefaultDistrowould be fine as-is.OTEL_PYTHON_X_PROVIDERand just provide a big "Disable everything" switch instead which skips all setup.nonevalues for theOTEL_X_EXPORTERenv-var and using those to disable export instead.opentelemetry-instrumentwhich disables auto-instrumentation completely, somewhat along the lines ofOTEL_PYTHON_DISABLED_INSTRUMENTATIONSbut earlying-out ofinitializeinsitecustomize.py.OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLEDhas just been added by Support logs SDK auto instrumentation enable/disable with env #2728 (and which defaults to false, and isn't visible inopentelemetry-instrumentationhelp), which has a similar effect, but inside_initialize_components. So maybeOTEL_PYTHON_AUTO_INSTRUMENTATION_ENABLEDis the generalised version of that.OpenTelemetryDistroshould not setOTEL_TRACES_EXPORTERif it is not already set, but leave that to the user, as it does for logs and metrics, although with stabilisation of metrics in v1.12, I guess that'll change to enableOTEL_METRICS_EXPORTERinstead.Additional context
I also noticed an odd issue that the
get_X_providercode is set up to usedefault_Xif the environment variable is not set, but the callers all ensure the environment variable is set before calling it. Perhaps thedefault_Xentrypoints should point at theProxyXProvider(except for logging, where that doesn't make sense, and since the code lives in the SDK, it can declare its own provider asdefault), and anoop_Xentry-point could be used for the no-op providers explicitly, then we could always callopentelemetry.util._providers._load_providerand let its env-var handling do the heavy lifting.It also might make sense to make
_load_providertake a default provider to use if the env-var is not set, rather than falling back todefault_Xif the env-var is not set. Or just remove the "env-var not set" support from_load_provider.