Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyramid: Fix which package is the correct caller in _traced_init. #830

Merged
merged 19 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

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

- `opentelemetry-instrumentation-flask` Flask: Capture custom request/response headers in span attributes
([#952])(https://github.com/open-telemetry/opentelemetry-python-contrib/pull/952)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
kenrobbins marked this conversation as resolved.
Show resolved Hide resolved

wrapped(*args, **kwargs)
instance.include("opentelemetry.instrumentation.pyramid.callbacks")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ def test_tween_list(self):
span_list = self.memory_exporter.get_finished_spans()
self.assertEqual(len(span_list), 1)

def test_registry_name_is_this_module(self):
config = Configurator()
self.assertEqual(config.registry.__name__, __name__.rsplit('.')[0])


class TestWrappedWithOtherFramework(
InstrumentationTest, TestBase, WsgiTestBase
Expand Down