From c69ae2b8a97c36a012fd85cf07c85b34ec97d5c4 Mon Sep 17 00:00:00 2001 From: Ken Robbins Date: Thu, 9 Dec 2021 01:30:36 +0000 Subject: [PATCH] pyramid: Fix which package is the correct caller in _traced_init. --- .../opentelemetry/instrumentation/pyramid/__init__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/__init__.py b/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/__init__.py index bcde7eda74..58e8049f23 100644 --- a/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/__init__.py @@ -134,10 +134,12 @@ def _traced_init(wrapped, instance, args, kwargs): # to find the calling package. So if we let the original `__init__` # function call it, our wrapper will mess things up. if not kwargs.get("package", None): - # Get the package for the third frame up from this one. - # Default is `level=2` which will give us the package from `wrapt` - # instead of the desired package (the caller) - kwargs["package"] = caller_package(level=3) + # Get the package for the 2nd frame up from this one. + # Default is `level=2` one level down (in Configurator.__init__). + # We want the 3rd level from _there_. Since we are already 1 level above, + # we need the 2nd level up from here, which will give us the package from + # `wrapt` instead of the desired package (the caller) + kwargs["package"] = caller_package(level=2) wrapped(*args, **kwargs) instance.include("opentelemetry.instrumentation.pyramid.callbacks")