From c2c7aa98a407b1d89b0a47b5d972b9e9d5657041 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Mon, 15 May 2023 11:36:06 +0200 Subject: [PATCH 01/12] Save http status code everywhere in same format --- sentry_sdk/consts.py | 6 ++++++ sentry_sdk/integrations/httpx.py | 2 -- sentry_sdk/integrations/stdlib.py | 1 - sentry_sdk/tracing.py | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/sentry_sdk/consts.py b/sentry_sdk/consts.py index 33f72651e3..726bfb9177 100644 --- a/sentry_sdk/consts.py +++ b/sentry_sdk/consts.py @@ -101,6 +101,12 @@ class SPANDATA: Example: GET """ + HTTP_STATUS_CODE = "http.status_code" + """ + The integer HTTP status code. + Example: 418 + """ + class OP: CACHE_GET_ITEM = "cache.get_item" diff --git a/sentry_sdk/integrations/httpx.py b/sentry_sdk/integrations/httpx.py index a7319d9d72..358562f791 100644 --- a/sentry_sdk/integrations/httpx.py +++ b/sentry_sdk/integrations/httpx.py @@ -64,7 +64,6 @@ def send(self, request, **kwargs): rv = real_send(self, request, **kwargs) - span.set_data("status_code", rv.status_code) span.set_http_status(rv.status_code) span.set_data("reason", rv.reason_phrase) @@ -105,7 +104,6 @@ async def send(self, request, **kwargs): rv = await real_send(self, request, **kwargs) - span.set_data("status_code", rv.status_code) span.set_http_status(rv.status_code) span.set_data("reason", rv.reason_phrase) diff --git a/sentry_sdk/integrations/stdlib.py b/sentry_sdk/integrations/stdlib.py index 17b30102b9..0add046bf8 100644 --- a/sentry_sdk/integrations/stdlib.py +++ b/sentry_sdk/integrations/stdlib.py @@ -120,7 +120,6 @@ def getresponse(self, *args, **kwargs): rv = real_getresponse(self, *args, **kwargs) - span.set_data("status_code", rv.status) span.set_http_status(int(rv.status)) span.set_data("reason", rv.reason) span.finish() diff --git a/sentry_sdk/tracing.py b/sentry_sdk/tracing.py index 35d77ae46e..738db45a7e 100644 --- a/sentry_sdk/tracing.py +++ b/sentry_sdk/tracing.py @@ -7,6 +7,7 @@ from sentry_sdk.consts import INSTRUMENTER from sentry_sdk.utils import is_valid_sample_rate, logger, nanosecond_time from sentry_sdk._compat import PY2 +from sentry_sdk.consts import SPANDATA from sentry_sdk._types import TYPE_CHECKING @@ -370,7 +371,7 @@ def set_status(self, value): def set_http_status(self, http_status): # type: (int) -> None - self.set_tag("http.status_code", str(http_status)) + self.set_data(SPANDATA.HTTP_STATUS_CODE, http_status) if http_status < 400: self.set_status("ok") From 815d724b50579df9cb3b5cf1d95ab677de0dcb96 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Mon, 15 May 2023 11:45:22 +0200 Subject: [PATCH 02/12] Fixed some tests --- tests/integrations/httpx/test_httpx.py | 2 +- tests/integrations/requests/test_requests.py | 2 +- tests/integrations/stdlib/test_httplib.py | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/integrations/httpx/test_httpx.py b/tests/integrations/httpx/test_httpx.py index dd5e752c32..c948901588 100644 --- a/tests/integrations/httpx/test_httpx.py +++ b/tests/integrations/httpx/test_httpx.py @@ -46,7 +46,7 @@ def before_breadcrumb(crumb, hint): SPANDATA.HTTP_METHOD: "GET", SPANDATA.HTTP_FRAGMENT: "", SPANDATA.HTTP_QUERY: "", - "status_code": 200, + SPANDATA.HTTP_STATUS_CODE: 200, "reason": "OK", "extra": "foo", } diff --git a/tests/integrations/requests/test_requests.py b/tests/integrations/requests/test_requests.py index 324379fc9d..9c77b290d1 100644 --- a/tests/integrations/requests/test_requests.py +++ b/tests/integrations/requests/test_requests.py @@ -28,6 +28,6 @@ def test_crumb_capture(sentry_init, capture_events): SPANDATA.HTTP_METHOD: "GET", SPANDATA.HTTP_FRAGMENT: "", SPANDATA.HTTP_QUERY: "", - "status_code": response.status_code, + SPANDATA.HTTP_STATUS_CODE: response.status_code, "reason": response.reason, } diff --git a/tests/integrations/stdlib/test_httplib.py b/tests/integrations/stdlib/test_httplib.py index 959ad1658b..769d3dfef5 100644 --- a/tests/integrations/stdlib/test_httplib.py +++ b/tests/integrations/stdlib/test_httplib.py @@ -49,7 +49,7 @@ def test_crumb_capture(sentry_init, capture_events): assert crumb["data"] == { "url": url, SPANDATA.HTTP_METHOD: "GET", - "status_code": 200, + SPANDATA.HTTP_STATUS_CODE: 200, "reason": "OK", SPANDATA.HTTP_FRAGMENT: "", SPANDATA.HTTP_QUERY: "", @@ -76,7 +76,7 @@ def before_breadcrumb(crumb, hint): assert crumb["data"] == { "url": url, SPANDATA.HTTP_METHOD: "GET", - "status_code": 200, + SPANDATA.HTTP_STATUS_CODE: 200, "reason": "OK", "extra": "foo", SPANDATA.HTTP_FRAGMENT: "", @@ -134,7 +134,7 @@ def test_httplib_misuse(sentry_init, capture_events, request): assert crumb["data"] == { "url": "http://localhost:{}/200".format(PORT), SPANDATA.HTTP_METHOD: "GET", - "status_code": 200, + SPANDATA.HTTP_STATUS_CODE: 200, "reason": "OK", SPANDATA.HTTP_FRAGMENT: "", SPANDATA.HTTP_QUERY: "", From 47d42e5e072042acb26f34fb8e94414989573202 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Mon, 15 May 2023 11:50:01 +0200 Subject: [PATCH 03/12] Fixed some tests --- tests/integrations/opentelemetry/test_span_processor.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/integrations/opentelemetry/test_span_processor.py b/tests/integrations/opentelemetry/test_span_processor.py index 0467da7673..d691c33c29 100644 --- a/tests/integrations/opentelemetry/test_span_processor.py +++ b/tests/integrations/opentelemetry/test_span_processor.py @@ -190,7 +190,6 @@ def test_update_span_with_otel_data_http_method(): assert sentry_span.op == "http.client" assert sentry_span.description == "GET example.com /" - assert sentry_span._tags["http.status_code"] == "429" assert sentry_span.status == "resource_exhausted" assert sentry_span._data["http.method"] == "GET" @@ -220,7 +219,6 @@ def test_update_span_with_otel_data_http_method2(): assert sentry_span.op == "http.server" assert sentry_span.description == "GET https://example.com/status/403" - assert sentry_span._tags["http.status_code"] == "429" assert sentry_span.status == "resource_exhausted" assert sentry_span._data["http.method"] == "GET" From 6a236307204922cf6bb7107cf6ca277a11c65b31 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Tue, 23 May 2023 13:47:04 +0200 Subject: [PATCH 04/12] Made http status code a string and kept the tag for backwards compatibility --- sentry_sdk/consts.py | 4 ++-- sentry_sdk/tracing.py | 6 +++++- tests/integrations/httpx/test_httpx.py | 2 +- tests/integrations/stdlib/test_httplib.py | 6 +++--- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/sentry_sdk/consts.py b/sentry_sdk/consts.py index a026c8dc95..badd4f54bd 100644 --- a/sentry_sdk/consts.py +++ b/sentry_sdk/consts.py @@ -103,8 +103,8 @@ class SPANDATA: HTTP_STATUS_CODE = "http.status_code" """ - The integer HTTP status code. - Example: 418 + The HTTP status code as string. + Example: "418" """ diff --git a/sentry_sdk/tracing.py b/sentry_sdk/tracing.py index 738db45a7e..867621f162 100644 --- a/sentry_sdk/tracing.py +++ b/sentry_sdk/tracing.py @@ -5,6 +5,7 @@ import sentry_sdk from sentry_sdk.consts import INSTRUMENTER +from sentry_sdk._compat import text_type from sentry_sdk.utils import is_valid_sample_rate, logger, nanosecond_time from sentry_sdk._compat import PY2 from sentry_sdk.consts import SPANDATA @@ -371,7 +372,10 @@ def set_status(self, value): def set_http_status(self, http_status): # type: (int) -> None - self.set_data(SPANDATA.HTTP_STATUS_CODE, http_status) + self.set_tag( + SPANDATA.HTTP_STATUS_CODE, str(http_status) + ) # we keep this for backwards compatability + self.set_data(SPANDATA.HTTP_STATUS_CODE, text_type(http_status)) if http_status < 400: self.set_status("ok") diff --git a/tests/integrations/httpx/test_httpx.py b/tests/integrations/httpx/test_httpx.py index c948901588..49af94765b 100644 --- a/tests/integrations/httpx/test_httpx.py +++ b/tests/integrations/httpx/test_httpx.py @@ -46,7 +46,7 @@ def before_breadcrumb(crumb, hint): SPANDATA.HTTP_METHOD: "GET", SPANDATA.HTTP_FRAGMENT: "", SPANDATA.HTTP_QUERY: "", - SPANDATA.HTTP_STATUS_CODE: 200, + SPANDATA.HTTP_STATUS_CODE: "200", "reason": "OK", "extra": "foo", } diff --git a/tests/integrations/stdlib/test_httplib.py b/tests/integrations/stdlib/test_httplib.py index 769d3dfef5..716bcc9e8a 100644 --- a/tests/integrations/stdlib/test_httplib.py +++ b/tests/integrations/stdlib/test_httplib.py @@ -49,7 +49,7 @@ def test_crumb_capture(sentry_init, capture_events): assert crumb["data"] == { "url": url, SPANDATA.HTTP_METHOD: "GET", - SPANDATA.HTTP_STATUS_CODE: 200, + SPANDATA.HTTP_STATUS_CODE: "200", "reason": "OK", SPANDATA.HTTP_FRAGMENT: "", SPANDATA.HTTP_QUERY: "", @@ -76,7 +76,7 @@ def before_breadcrumb(crumb, hint): assert crumb["data"] == { "url": url, SPANDATA.HTTP_METHOD: "GET", - SPANDATA.HTTP_STATUS_CODE: 200, + SPANDATA.HTTP_STATUS_CODE: "200", "reason": "OK", "extra": "foo", SPANDATA.HTTP_FRAGMENT: "", @@ -134,7 +134,7 @@ def test_httplib_misuse(sentry_init, capture_events, request): assert crumb["data"] == { "url": "http://localhost:{}/200".format(PORT), SPANDATA.HTTP_METHOD: "GET", - SPANDATA.HTTP_STATUS_CODE: 200, + SPANDATA.HTTP_STATUS_CODE: "200", "reason": "OK", SPANDATA.HTTP_FRAGMENT: "", SPANDATA.HTTP_QUERY: "", From f40da08cfd52290fa896684bef6b9929517ba5f0 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Tue, 23 May 2023 13:52:57 +0200 Subject: [PATCH 05/12] Fixed some tests --- tests/integrations/opentelemetry/test_span_processor.py | 8 ++++---- tests/integrations/requests/test_requests.py | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/integrations/opentelemetry/test_span_processor.py b/tests/integrations/opentelemetry/test_span_processor.py index d691c33c29..f97ec3908d 100644 --- a/tests/integrations/opentelemetry/test_span_processor.py +++ b/tests/integrations/opentelemetry/test_span_processor.py @@ -178,7 +178,7 @@ def test_update_span_with_otel_data_http_method(): otel_span.kind = SpanKind.CLIENT otel_span.attributes = { "http.method": "GET", - "http.status_code": 429, + "http.status_code": "429", "http.status_text": "xxx", "http.user_agent": "curl/7.64.1", "net.peer.name": "example.com", @@ -193,7 +193,7 @@ def test_update_span_with_otel_data_http_method(): assert sentry_span.status == "resource_exhausted" assert sentry_span._data["http.method"] == "GET" - assert sentry_span._data["http.status_code"] == 429 + assert sentry_span._data["http.status_code"] == "429" assert sentry_span._data["http.status_text"] == "xxx" assert sentry_span._data["http.user_agent"] == "curl/7.64.1" assert sentry_span._data["net.peer.name"] == "example.com" @@ -208,7 +208,7 @@ def test_update_span_with_otel_data_http_method2(): otel_span.kind = SpanKind.SERVER otel_span.attributes = { "http.method": "GET", - "http.status_code": 429, + "http.status_code": "429", "http.status_text": "xxx", "http.user_agent": "curl/7.64.1", "http.url": "https://example.com/status/403?password=123&username=test@example.com&author=User123&auth=1234567890abcdef", @@ -222,7 +222,7 @@ def test_update_span_with_otel_data_http_method2(): assert sentry_span.status == "resource_exhausted" assert sentry_span._data["http.method"] == "GET" - assert sentry_span._data["http.status_code"] == 429 + assert sentry_span._data["http.status_code"] == "429" assert sentry_span._data["http.status_text"] == "xxx" assert sentry_span._data["http.user_agent"] == "curl/7.64.1" assert ( diff --git a/tests/integrations/requests/test_requests.py b/tests/integrations/requests/test_requests.py index 9c77b290d1..e2abe50ca6 100644 --- a/tests/integrations/requests/test_requests.py +++ b/tests/integrations/requests/test_requests.py @@ -4,6 +4,7 @@ requests = pytest.importorskip("requests") from sentry_sdk import capture_message +from sentry_sdk._compat import text_type from sentry_sdk.consts import SPANDATA from sentry_sdk.integrations.stdlib import StdlibIntegration @@ -28,6 +29,6 @@ def test_crumb_capture(sentry_init, capture_events): SPANDATA.HTTP_METHOD: "GET", SPANDATA.HTTP_FRAGMENT: "", SPANDATA.HTTP_QUERY: "", - SPANDATA.HTTP_STATUS_CODE: response.status_code, + SPANDATA.HTTP_STATUS_CODE: text_type(response.status_code), "reason": response.reason, } From 8984fb16437425452b149469c874c16573bf84fc Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Tue, 23 May 2023 14:00:16 +0200 Subject: [PATCH 06/12] Fixed typing --- sentry_sdk/integrations/opentelemetry/span_processor.py | 2 +- tests/integrations/opentelemetry/test_span_processor.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sentry_sdk/integrations/opentelemetry/span_processor.py b/sentry_sdk/integrations/opentelemetry/span_processor.py index 2c50082ff2..4ab9b1968f 100644 --- a/sentry_sdk/integrations/opentelemetry/span_processor.py +++ b/sentry_sdk/integrations/opentelemetry/span_processor.py @@ -279,7 +279,7 @@ def _update_span_with_otel_data(self, sentry_span, otel_span): SpanAttributes.HTTP_STATUS_CODE, None ) if status_code: - sentry_span.set_http_status(status_code) + sentry_span.set_http_status(int(status_code)) elif db_query: op = "db" diff --git a/tests/integrations/opentelemetry/test_span_processor.py b/tests/integrations/opentelemetry/test_span_processor.py index f97ec3908d..7ccaca0c59 100644 --- a/tests/integrations/opentelemetry/test_span_processor.py +++ b/tests/integrations/opentelemetry/test_span_processor.py @@ -208,7 +208,7 @@ def test_update_span_with_otel_data_http_method2(): otel_span.kind = SpanKind.SERVER otel_span.attributes = { "http.method": "GET", - "http.status_code": "429", + "http.status_code": 429, "http.status_text": "xxx", "http.user_agent": "curl/7.64.1", "http.url": "https://example.com/status/403?password=123&username=test@example.com&author=User123&auth=1234567890abcdef", From 98da5697f94d8c7d0803d7faf1e00c4d01c3c681 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Mon, 5 Jun 2023 12:31:41 +0200 Subject: [PATCH 07/12] Renamed statuc_code field and made it int to make it like otel has it. --- sentry_sdk/consts.py | 6 +++--- sentry_sdk/tracing.py | 3 +-- tests/integrations/httpx/test_httpx.py | 2 +- tests/integrations/requests/test_requests.py | 3 +-- tests/integrations/stdlib/test_httplib.py | 6 +++--- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/sentry_sdk/consts.py b/sentry_sdk/consts.py index badd4f54bd..4108082a09 100644 --- a/sentry_sdk/consts.py +++ b/sentry_sdk/consts.py @@ -101,10 +101,10 @@ class SPANDATA: Example: GET """ - HTTP_STATUS_CODE = "http.status_code" + HTTP_STATUS_CODE = "http.response.status_code" """ - The HTTP status code as string. - Example: "418" + The HTTP status code an integer. + Example: 418 """ diff --git a/sentry_sdk/tracing.py b/sentry_sdk/tracing.py index 867621f162..2915e80cc7 100644 --- a/sentry_sdk/tracing.py +++ b/sentry_sdk/tracing.py @@ -5,7 +5,6 @@ import sentry_sdk from sentry_sdk.consts import INSTRUMENTER -from sentry_sdk._compat import text_type from sentry_sdk.utils import is_valid_sample_rate, logger, nanosecond_time from sentry_sdk._compat import PY2 from sentry_sdk.consts import SPANDATA @@ -375,7 +374,7 @@ def set_http_status(self, http_status): self.set_tag( SPANDATA.HTTP_STATUS_CODE, str(http_status) ) # we keep this for backwards compatability - self.set_data(SPANDATA.HTTP_STATUS_CODE, text_type(http_status)) + self.set_data(SPANDATA.HTTP_STATUS_CODE, http_status) if http_status < 400: self.set_status("ok") diff --git a/tests/integrations/httpx/test_httpx.py b/tests/integrations/httpx/test_httpx.py index 49af94765b..c948901588 100644 --- a/tests/integrations/httpx/test_httpx.py +++ b/tests/integrations/httpx/test_httpx.py @@ -46,7 +46,7 @@ def before_breadcrumb(crumb, hint): SPANDATA.HTTP_METHOD: "GET", SPANDATA.HTTP_FRAGMENT: "", SPANDATA.HTTP_QUERY: "", - SPANDATA.HTTP_STATUS_CODE: "200", + SPANDATA.HTTP_STATUS_CODE: 200, "reason": "OK", "extra": "foo", } diff --git a/tests/integrations/requests/test_requests.py b/tests/integrations/requests/test_requests.py index e2abe50ca6..9c77b290d1 100644 --- a/tests/integrations/requests/test_requests.py +++ b/tests/integrations/requests/test_requests.py @@ -4,7 +4,6 @@ requests = pytest.importorskip("requests") from sentry_sdk import capture_message -from sentry_sdk._compat import text_type from sentry_sdk.consts import SPANDATA from sentry_sdk.integrations.stdlib import StdlibIntegration @@ -29,6 +28,6 @@ def test_crumb_capture(sentry_init, capture_events): SPANDATA.HTTP_METHOD: "GET", SPANDATA.HTTP_FRAGMENT: "", SPANDATA.HTTP_QUERY: "", - SPANDATA.HTTP_STATUS_CODE: text_type(response.status_code), + SPANDATA.HTTP_STATUS_CODE: response.status_code, "reason": response.reason, } diff --git a/tests/integrations/stdlib/test_httplib.py b/tests/integrations/stdlib/test_httplib.py index 716bcc9e8a..769d3dfef5 100644 --- a/tests/integrations/stdlib/test_httplib.py +++ b/tests/integrations/stdlib/test_httplib.py @@ -49,7 +49,7 @@ def test_crumb_capture(sentry_init, capture_events): assert crumb["data"] == { "url": url, SPANDATA.HTTP_METHOD: "GET", - SPANDATA.HTTP_STATUS_CODE: "200", + SPANDATA.HTTP_STATUS_CODE: 200, "reason": "OK", SPANDATA.HTTP_FRAGMENT: "", SPANDATA.HTTP_QUERY: "", @@ -76,7 +76,7 @@ def before_breadcrumb(crumb, hint): assert crumb["data"] == { "url": url, SPANDATA.HTTP_METHOD: "GET", - SPANDATA.HTTP_STATUS_CODE: "200", + SPANDATA.HTTP_STATUS_CODE: 200, "reason": "OK", "extra": "foo", SPANDATA.HTTP_FRAGMENT: "", @@ -134,7 +134,7 @@ def test_httplib_misuse(sentry_init, capture_events, request): assert crumb["data"] == { "url": "http://localhost:{}/200".format(PORT), SPANDATA.HTTP_METHOD: "GET", - SPANDATA.HTTP_STATUS_CODE: "200", + SPANDATA.HTTP_STATUS_CODE: 200, "reason": "OK", SPANDATA.HTTP_FRAGMENT: "", SPANDATA.HTTP_QUERY: "", From 2d5579f6e1c65070f55082bc89808d893c307f35 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Mon, 5 Jun 2023 14:41:24 +0200 Subject: [PATCH 08/12] Fixed tests --- tests/integrations/opentelemetry/test_span_processor.py | 8 ++++---- tests/tracing/test_noop_span.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/integrations/opentelemetry/test_span_processor.py b/tests/integrations/opentelemetry/test_span_processor.py index 7ccaca0c59..a3984713ca 100644 --- a/tests/integrations/opentelemetry/test_span_processor.py +++ b/tests/integrations/opentelemetry/test_span_processor.py @@ -178,7 +178,7 @@ def test_update_span_with_otel_data_http_method(): otel_span.kind = SpanKind.CLIENT otel_span.attributes = { "http.method": "GET", - "http.status_code": "429", + "http.response.status_code": 429, "http.status_text": "xxx", "http.user_agent": "curl/7.64.1", "net.peer.name": "example.com", @@ -193,7 +193,7 @@ def test_update_span_with_otel_data_http_method(): assert sentry_span.status == "resource_exhausted" assert sentry_span._data["http.method"] == "GET" - assert sentry_span._data["http.status_code"] == "429" + assert sentry_span._data["http.response.status_code"] == 429 assert sentry_span._data["http.status_text"] == "xxx" assert sentry_span._data["http.user_agent"] == "curl/7.64.1" assert sentry_span._data["net.peer.name"] == "example.com" @@ -208,7 +208,7 @@ def test_update_span_with_otel_data_http_method2(): otel_span.kind = SpanKind.SERVER otel_span.attributes = { "http.method": "GET", - "http.status_code": 429, + "http.response.status_code": 429, "http.status_text": "xxx", "http.user_agent": "curl/7.64.1", "http.url": "https://example.com/status/403?password=123&username=test@example.com&author=User123&auth=1234567890abcdef", @@ -222,7 +222,7 @@ def test_update_span_with_otel_data_http_method2(): assert sentry_span.status == "resource_exhausted" assert sentry_span._data["http.method"] == "GET" - assert sentry_span._data["http.status_code"] == "429" + assert sentry_span._data["http.response.status_code"] == 429 assert sentry_span._data["http.status_text"] == "xxx" assert sentry_span._data["http.user_agent"] == "curl/7.64.1" assert ( diff --git a/tests/tracing/test_noop_span.py b/tests/tracing/test_noop_span.py index 92cba75a35..9896afb007 100644 --- a/tests/tracing/test_noop_span.py +++ b/tests/tracing/test_noop_span.py @@ -27,7 +27,7 @@ def test_noop_start_span(sentry_init): assert isinstance(span, NoOpSpan) assert sentry_sdk.Hub.current.scope.span is span - span.set_tag("http.status_code", "418") + span.set_tag("http.response.status_code", 418) span.set_data("http.entity_type", "teapot") From 6a3da24aa9d814da3bb81d408010394376c85fad Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Mon, 5 Jun 2023 14:48:18 +0200 Subject: [PATCH 09/12] Fixed tests --- tests/integrations/opentelemetry/test_span_processor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integrations/opentelemetry/test_span_processor.py b/tests/integrations/opentelemetry/test_span_processor.py index a3984713ca..8659e548a1 100644 --- a/tests/integrations/opentelemetry/test_span_processor.py +++ b/tests/integrations/opentelemetry/test_span_processor.py @@ -178,7 +178,7 @@ def test_update_span_with_otel_data_http_method(): otel_span.kind = SpanKind.CLIENT otel_span.attributes = { "http.method": "GET", - "http.response.status_code": 429, + "http.status_code": 429, "http.status_text": "xxx", "http.user_agent": "curl/7.64.1", "net.peer.name": "example.com", @@ -208,7 +208,7 @@ def test_update_span_with_otel_data_http_method2(): otel_span.kind = SpanKind.SERVER otel_span.attributes = { "http.method": "GET", - "http.response.status_code": 429, + "http.status_code": 429, "http.status_text": "xxx", "http.user_agent": "curl/7.64.1", "http.url": "https://example.com/status/403?password=123&username=test@example.com&author=User123&auth=1234567890abcdef", From dc0d8f7e270b045074cecea65be382e938a54544 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Mon, 5 Jun 2023 15:11:55 +0200 Subject: [PATCH 10/12] Backwards compatibility --- sentry_sdk/tracing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentry_sdk/tracing.py b/sentry_sdk/tracing.py index 2915e80cc7..97c3277b65 100644 --- a/sentry_sdk/tracing.py +++ b/sentry_sdk/tracing.py @@ -372,7 +372,7 @@ def set_status(self, value): def set_http_status(self, http_status): # type: (int) -> None self.set_tag( - SPANDATA.HTTP_STATUS_CODE, str(http_status) + "http.status_code", str(http_status) ) # we keep this for backwards compatability self.set_data(SPANDATA.HTTP_STATUS_CODE, http_status) From 19835d23564eea4189d2f8b55144dc957473b708 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Mon, 5 Jun 2023 15:13:18 +0200 Subject: [PATCH 11/12] Cleanup --- sentry_sdk/integrations/opentelemetry/span_processor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentry_sdk/integrations/opentelemetry/span_processor.py b/sentry_sdk/integrations/opentelemetry/span_processor.py index e2e99fc4f9..9b74d993dc 100644 --- a/sentry_sdk/integrations/opentelemetry/span_processor.py +++ b/sentry_sdk/integrations/opentelemetry/span_processor.py @@ -279,7 +279,7 @@ def _update_span_with_otel_data(self, sentry_span, otel_span): SpanAttributes.HTTP_STATUS_CODE, None ) if status_code: - sentry_span.set_http_status(int(status_code)) + sentry_span.set_http_status(status_code) elif db_query: op = "db" From e3b04e16b4c3e09323a8887caa67c6e2e64fb79d Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Tue, 6 Jun 2023 10:05:08 +0200 Subject: [PATCH 12/12] Update sentry_sdk/consts.py Co-authored-by: Ivana Kellyerova --- sentry_sdk/consts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentry_sdk/consts.py b/sentry_sdk/consts.py index 285ac2f288..0fc94686ea 100644 --- a/sentry_sdk/consts.py +++ b/sentry_sdk/consts.py @@ -103,7 +103,7 @@ class SPANDATA: HTTP_STATUS_CODE = "http.response.status_code" """ - The HTTP status code an integer. + The HTTP status code as an integer. Example: 418 """