Skip to content

Commit 73c0543

Browse files
committed
Merge branch 'ivana/potel/port-sample-rate-update' of github.com:getsentry/sentry-python into ivana/potel/port-sample-rate-update
2 parents d2351e7 + 9968358 commit 73c0543

File tree

13 files changed

+52
-52
lines changed

13 files changed

+52
-52
lines changed

.github/workflows/release-comment-issues.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ jobs:
1717
steps:
1818
- name: Get version
1919
id: get_version
20-
run: echo "version=${{ github.event.inputs.version || github.event.release.tag_name }}" >> $GITHUB_OUTPUT
20+
env:
21+
INPUTS_VERSION: ${{ github.event.inputs.version }}
22+
RELEASE_TAG_NAME: ${{ github.event.release.tag_name }}
23+
run: echo "version=${$INPUTS_VERSION:-$RELEASE_TAG_NAME}" >> "$GITHUB_OUTPUT"
2124

2225
- name: Comment on linked issues that are mentioned in release
2326
if: |
@@ -28,4 +31,4 @@ jobs:
2831
uses: getsentry/release-comment-issues-gh-action@v1
2932
with:
3033
github_token: ${{ secrets.GITHUB_TOKEN }}
31-
version: ${{ steps.get_version.outputs.version }}
34+
version: ${{ steps.get_version.outputs.version }}

sentry_sdk/integrations/aiohttp.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
capture_internal_exceptions,
2828
ensure_integration_enabled,
2929
event_from_exception,
30+
http_client_status_to_breadcrumb_level,
3031
logger,
3132
parse_url,
3233
parse_version,
@@ -277,13 +278,15 @@ async def on_request_end(session, trace_config_ctx, params):
277278
return
278279

279280
span_data = trace_config_ctx.span_data or {}
280-
span_data[SPANDATA.HTTP_STATUS_CODE] = int(params.response.status)
281+
status_code = int(params.response.status)
282+
span_data[SPANDATA.HTTP_STATUS_CODE] = status_code
281283
span_data["reason"] = params.response.reason
282284

283285
sentry_sdk.add_breadcrumb(
284286
type="http",
285287
category="httplib",
286288
data=span_data,
289+
level=http_client_status_to_breadcrumb_level(status_code),
287290
)
288291

289292
span = trace_config_ctx.span

sentry_sdk/integrations/asgi.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,12 @@ def event_processor(self, event, hint, asgi_scope):
255255
event["request"] = deepcopy(request_data)
256256

257257
# Only set transaction name if not already set by Starlette or FastAPI (or other frameworks)
258+
transaction = event.get("transaction")
259+
transaction_source = (event.get("transaction_info") or {}).get("source")
258260
already_set = (
259-
"transaction" in event
260-
and event["transaction"] != _DEFAULT_TRANSACTION_NAME
261-
and "transaction_info" in event
262-
and "source" in event["transaction_info"]
263-
and event["transaction_info"]["source"]
261+
transaction is not None
262+
and transaction != _DEFAULT_TRANSACTION_NAME
263+
and transaction_source
264264
in [
265265
TransactionSource.COMPONENT,
266266
TransactionSource.ROUTE,

sentry_sdk/integrations/httpx.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
SENSITIVE_DATA_SUBSTITUTE,
88
capture_internal_exceptions,
99
ensure_integration_enabled,
10+
http_client_status_to_breadcrumb_level,
1011
logger,
1112
parse_url,
1213
)
@@ -101,6 +102,7 @@ def send(self, request, **kwargs):
101102
type="http",
102103
category="httplib",
103104
data=data,
105+
level=http_client_status_to_breadcrumb_level(rv.status_code),
104106
)
105107

106108
return rv

sentry_sdk/integrations/opentelemetry/span_processor.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,6 @@ def _span_to_json(self, span):
261261
}
262262
)
263263

264-
if status:
265-
span_json.setdefault("tags", {})["status"] = status
266-
267264
if parent_span_id:
268265
span_json["parent_span_id"] = parent_span_id
269266

sentry_sdk/integrations/stdlib.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
capture_internal_exceptions,
1515
ensure_integration_enabled,
1616
get_current_thread_meta,
17+
http_client_status_to_breadcrumb_level,
1718
is_sentry_url,
1819
logger,
1920
safe_repr,
@@ -144,14 +145,16 @@ def getresponse(self, *args, **kwargs):
144145
span_data[SPANDATA.HTTP_STATUS_CODE] = int(rv.status)
145146
span_data["reason"] = rv.reason
146147

148+
status_code = int(rv.status)
149+
span.set_http_status(status_code)
150+
span.set_data("reason", rv.reason)
151+
147152
sentry_sdk.add_breadcrumb(
148153
type="http",
149154
category="httplib",
150155
data=span_data,
156+
level=http_client_status_to_breadcrumb_level(status_code),
151157
)
152-
153-
span.set_http_status(int(rv.status))
154-
span.set_data("reason", rv.reason)
155158
finally:
156159
span.__exit__(None, None, None)
157160

sentry_sdk/tracing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
_serialize_span_attribute,
2121
get_current_thread_meta,
2222
logger,
23+
should_be_treated_as_error,
2324
)
2425

2526
from typing import TYPE_CHECKING, cast
@@ -424,7 +425,7 @@ def __enter__(self):
424425

425426
def __exit__(self, ty, value, tb):
426427
# type: (Optional[Any], Optional[Any], Optional[Any]) -> None
427-
if value is not None:
428+
if value is not None and should_be_treated_as_error(ty, value):
428429
self.set_status(SPANSTATUS.INTERNAL_ERROR)
429430
else:
430431
status_unset = (

sentry_sdk/utils.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1879,11 +1879,21 @@ def datetime_from_isoformat(value):
18791879
return result.astimezone(timezone.utc)
18801880

18811881

1882-
# TODO-neel-potel use in span status
18831882
def should_be_treated_as_error(ty, value):
18841883
# type: (Any, Any) -> bool
18851884
if ty == SystemExit and hasattr(value, "code") and value.code in (0, None):
18861885
# https://docs.python.org/3/library/exceptions.html#SystemExit
18871886
return False
18881887

18891888
return True
1889+
1890+
1891+
def http_client_status_to_breadcrumb_level(status_code):
1892+
# type: (Optional[int]) -> str
1893+
if status_code is not None:
1894+
if 500 <= status_code <= 599:
1895+
return "error"
1896+
elif 400 <= status_code <= 499:
1897+
return "warning"
1898+
1899+
return "info"

tests/integrations/aiohttp/test_aiohttp.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -534,8 +534,8 @@ async def handler(request):
534534
@pytest.mark.parametrize(
535535
"status_code,level",
536536
[
537-
(200, None),
538-
(301, None),
537+
(200, "info"),
538+
(301, "info"),
539539
(403, "warning"),
540540
(405, "warning"),
541541
(500, "error"),
@@ -570,10 +570,7 @@ async def handler(request):
570570

571571
crumb = event["breadcrumbs"]["values"][0]
572572
assert crumb["type"] == "http"
573-
if level is None:
574-
assert "level" not in crumb
575-
else:
576-
assert crumb["level"] == level
573+
assert crumb["level"] == level
577574
assert crumb["category"] == "httplib"
578575
assert crumb["data"] == ApproxDict(
579576
{

tests/integrations/httpx/test_httpx.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ def before_breadcrumb(crumb, hint):
6464
@pytest.mark.parametrize(
6565
"status_code,level",
6666
[
67-
(200, None),
68-
(301, None),
67+
(200, "info"),
68+
(301, "info"),
6969
(403, "warning"),
7070
(405, "warning"),
7171
(500, "error"),
@@ -98,12 +98,7 @@ def test_crumb_capture_client_error(
9898
crumb = event["breadcrumbs"]["values"][0]
9999
assert crumb["type"] == "http"
100100
assert crumb["category"] == "httplib"
101-
102-
if level is None:
103-
assert "level" not in crumb
104-
else:
105-
assert crumb["level"] == level
106-
101+
assert crumb["level"] == level
107102
assert crumb["data"] == ApproxDict(
108103
{
109104
"url": url,

0 commit comments

Comments
 (0)