Skip to content

Commit 80d8cda

Browse files
author
Ken Robbins
committed
pyramid: Fix which package is the correct caller in _traced_init.
1 parent 2f5bbc4 commit 80d8cda

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

Diff for: CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
- `opentelemetry-instrumentation-wsgi` Capture custom request/response headers in span attributes
1111
([#925])(https://github.com/open-telemetry/opentelemetry-python-contrib/pull/925)
12+
- `opentelemetry-instrumentation-pyramid` Fixed which package is the correct caller in _traced_init.
13+
([#830](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/830))
1214

1315
### Added
1416

Diff for: instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/__init__.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,12 @@ def _traced_init(wrapped, instance, args, kwargs):
134134
# to find the calling package. So if we let the original `__init__`
135135
# function call it, our wrapper will mess things up.
136136
if not kwargs.get("package", None):
137-
# Get the package for the third frame up from this one.
138-
# Default is `level=2` which will give us the package from `wrapt`
139-
# instead of the desired package (the caller)
140-
kwargs["package"] = caller_package(level=3)
137+
# Get the package for the 2nd frame up from this one.
138+
# Default is `level=2` one level down (in Configurator.__init__).
139+
# We want the 3rd level from _there_. Since we are already 1 level above,
140+
# we need the 2nd level up from here, which will give us the package from
141+
# `wrapt` instead of the desired package (the caller)
142+
kwargs["package"] = caller_package(level=2)
141143

142144
wrapped(*args, **kwargs)
143145
instance.include("opentelemetry.instrumentation.pyramid.callbacks")

Diff for: instrumentation/opentelemetry-instrumentation-pyramid/tests/test_automatic.py

+4
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ def test_tween_list(self):
7979
span_list = self.memory_exporter.get_finished_spans()
8080
self.assertEqual(len(span_list), 1)
8181

82+
def test_registry_name_is_this_module(self):
83+
config = Configurator()
84+
self.assertEqual(config.registry.__name__, __name__.rsplit('.')[0])
85+
8286

8387
class TestWrappedWithOtherFramework(
8488
InstrumentationTest, TestBase, WsgiTestBase

0 commit comments

Comments
 (0)