Skip to content

Allow failing fast for auto-instrumentation problems #3550

Closed
@phillipuniverse

Description

@phillipuniverse
Contributor

What problem do you want to solve?

If there's an exception in an auto-instrumentation, we currently log the exception and continue. I would like an option to fail faster and immediately re-raise the exception to the caller.

Here's where we currently swallow any instrumentation exceptions:

def initialize():
"""Setup auto-instrumentation, called by the sitecustomize module"""
# prevents auto-instrumentation of subprocesses if code execs another python process
if "PYTHONPATH" in environ:
environ["PYTHONPATH"] = _python_path_without_directory(
environ["PYTHONPATH"], dirname(abspath(__file__)), pathsep
)
try:
distro = _load_distro()
distro.configure()
_load_configurators()
_load_instrumentors(distro)
except Exception: # pylint: disable=broad-except
_logger.exception("Failed to auto initialize OpenTelemetry")

With this, there's no way to say, fail startup of my service if there's an instrumentation problem.

Describe the solution you'd like

I'd like to be able to re-raise instrumentation exceptions and fail startup if there's a failure in this case:

from opentelemetry import autoinstrumentation

autoinstrumentation.initialize()

Describe alternatives you've considered

No response

Additional Context

No response

Would you like to implement a fix?

Yes

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @phillipuniverse

      Issue actions

        Allow failing fast for auto-instrumentation problems · Issue #3550 · open-telemetry/opentelemetry-python-contrib