mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-07-30 13:43:03 +08:00
pyramid: Fix which package is the correct caller in _traced_init. (#830)
This commit is contained in:
@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
## [Unreleased](https://github.com/open-telemetry/opentelemetry-python/compare/v1.10.0-0.29b0...HEAD)
|
## [Unreleased](https://github.com/open-telemetry/opentelemetry-python/compare/v1.10.0-0.29b0...HEAD)
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
- `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-tornado` Fix Tornado errors mapping to 500
|
- `opentelemetry-instrumentation-tornado` Fix Tornado errors mapping to 500
|
||||||
([#1048])(https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1048)
|
([#1048])(https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1048)
|
||||||
- `opentelemetry-instrumentation-urllib` make span attributes available to sampler
|
- `opentelemetry-instrumentation-urllib` make span attributes available to sampler
|
||||||
|
@ -144,7 +144,7 @@ Note:
|
|||||||
API
|
API
|
||||||
---
|
---
|
||||||
"""
|
"""
|
||||||
|
import platform
|
||||||
from typing import Collection
|
from typing import Collection
|
||||||
|
|
||||||
from pyramid.config import Configurator
|
from pyramid.config import Configurator
|
||||||
@ -166,6 +166,11 @@ from opentelemetry.instrumentation.utils import unwrap
|
|||||||
# from importing an unused symbol.
|
# from importing an unused symbol.
|
||||||
trace_tween_factory # pylint: disable=pointless-statement
|
trace_tween_factory # pylint: disable=pointless-statement
|
||||||
|
|
||||||
|
if platform.python_implementation() == "PyPy":
|
||||||
|
CALLER_LEVELS = 3
|
||||||
|
else:
|
||||||
|
CALLER_LEVELS = 2
|
||||||
|
|
||||||
|
|
||||||
def _traced_init(wrapped, instance, args, kwargs):
|
def _traced_init(wrapped, instance, args, kwargs):
|
||||||
settings = kwargs.get("settings", {})
|
settings = kwargs.get("settings", {})
|
||||||
@ -185,10 +190,12 @@ def _traced_init(wrapped, instance, args, kwargs):
|
|||||||
# to find the calling package. So if we let the original `__init__`
|
# to find the calling package. So if we let the original `__init__`
|
||||||
# function call it, our wrapper will mess things up.
|
# function call it, our wrapper will mess things up.
|
||||||
if not kwargs.get("package", None):
|
if not kwargs.get("package", None):
|
||||||
# Get the package for the third frame up from this one.
|
# Get the package for the 2nd frame up from this one.
|
||||||
# Default is `level=2` which will give us the package from `wrapt`
|
# Default is `level=2` one level down (in Configurator.__init__).
|
||||||
# instead of the desired package (the caller)
|
# We want the 3rd level from _there_. Since we are already 1 level above,
|
||||||
kwargs["package"] = caller_package(level=3)
|
# 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=CALLER_LEVELS)
|
||||||
|
|
||||||
wrapped(*args, **kwargs)
|
wrapped(*args, **kwargs)
|
||||||
instance.include("opentelemetry.instrumentation.pyramid.callbacks")
|
instance.include("opentelemetry.instrumentation.pyramid.callbacks")
|
||||||
|
@ -87,6 +87,12 @@ class TestAutomatic(InstrumentationTest, TestBase, WsgiTestBase):
|
|||||||
span_list = self.memory_exporter.get_finished_spans()
|
span_list = self.memory_exporter.get_finished_spans()
|
||||||
self.assertEqual(len(span_list), 1)
|
self.assertEqual(len(span_list), 1)
|
||||||
|
|
||||||
|
def test_registry_name_is_this_module(self):
|
||||||
|
config = Configurator()
|
||||||
|
self.assertEqual(
|
||||||
|
config.registry.__name__, __name__.rsplit(".", maxsplit=1)[0]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestWrappedWithOtherFramework(
|
class TestWrappedWithOtherFramework(
|
||||||
InstrumentationTest, TestBase, WsgiTestBase
|
InstrumentationTest, TestBase, WsgiTestBase
|
||||||
|
Reference in New Issue
Block a user