Skip to content

Commit 62e0a31

Browse files
authored
Pyramid: only categorize 500 exceptions as errors (#1137)
1 parent f03bef2 commit 62e0a31

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
## [Unreleased](https://github.com/open-telemetry/opentelemetry-python/compare/v1.12.0rc1-0.31b0...HEAD)
9-
- Pyramid: Only categorize 400s and 500s exceptions as errors
9+
- Pyramid: Only categorize 500s server exceptions as errors
1010
([#1037](https://github.com/open-telemetry/opentelemetry-python-contrib/issues/1037))
1111

1212
### Fixed

instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/callbacks.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from logging import getLogger
1616

1717
from pyramid.events import BeforeTraversal
18-
from pyramid.httpexceptions import HTTPError, HTTPException
18+
from pyramid.httpexceptions import HTTPException, HTTPServerError
1919
from pyramid.settings import asbool
2020
from pyramid.tweens import EXCVIEW
2121

@@ -198,9 +198,9 @@ def trace_tween(request):
198198

199199
activation = request.environ.get(_ENVIRON_ACTIVATION_KEY)
200200

201-
# Only considering HTTPClientError and HTTPServerError
202-
# to make sure HTTPRedirection is not reported as error
203-
if isinstance(response, HTTPError):
201+
# Only considering HTTPServerError
202+
# to make sure 200, 300 and 400 exceptions are not reported as error
203+
if isinstance(response, HTTPServerError):
204204
activation.__exit__(
205205
type(response),
206206
response,

instrumentation/opentelemetry-instrumentation-pyramid/tests/pyramid_base_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ def _hello_endpoint(request):
2424
helloid = int(request.matchdict["helloid"])
2525
if helloid == 500:
2626
raise exc.HTTPInternalServerError()
27+
if helloid == 404:
28+
raise exc.HTTPNotFound()
2729
if helloid == 302:
2830
raise exc.HTTPFound()
2931
if helloid == 204:

instrumentation/opentelemetry-instrumentation-pyramid/tests/test_automatic.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,27 @@ def test_204_empty_response_is_not_an_error(self):
136136
span_list = self.memory_exporter.get_finished_spans()
137137
self.assertEqual(len(span_list), 1)
138138

139+
def test_400s_response_is_not_an_error(self):
140+
tween_list = "pyramid.tweens.excview_tween_factory"
141+
config = Configurator(settings={"pyramid.tweens": tween_list})
142+
self._common_initialization(config)
143+
resp = self.client.get("/hello/404")
144+
self.assertEqual(404, resp.status_code)
145+
span_list = self.memory_exporter.get_finished_spans()
146+
self.assertEqual(len(span_list), 1)
147+
self.assertEqual(span_list[0].status.status_code, StatusCode.UNSET)
148+
149+
PyramidInstrumentor().uninstrument()
150+
151+
self.config = Configurator()
152+
153+
self._common_initialization(self.config)
154+
155+
resp = self.client.get("/hello/404")
156+
self.assertEqual(404, resp.status_code)
157+
span_list = self.memory_exporter.get_finished_spans()
158+
self.assertEqual(len(span_list), 1)
159+
139160

140161
class TestWrappedWithOtherFramework(
141162
InstrumentationTest, TestBase, WsgiTestBase

0 commit comments

Comments
 (0)