Skip to content

Commit ab3b6eb

Browse files
committed
improvements
1 parent 8d83f7a commit ab3b6eb

File tree

7 files changed

+11
-14
lines changed

7 files changed

+11
-14
lines changed

sentry_sdk/integrations/aiohttp.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,11 +389,9 @@ def _prepopulate_attributes(request):
389389
except ValueError:
390390
attributes["server.address"] = request.host
391391

392-
try:
392+
with capture_internal_exceptions():
393393
url = f"{request.scheme}://{request.host}{request.path}" # noqa: E231
394394
if request.query_string:
395395
attributes["url.full"] = f"{url}?{request.query_string}"
396-
except Exception:
397-
pass
398396

399397
return attributes

sentry_sdk/integrations/asgi.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
)
3333
from sentry_sdk.utils import (
3434
ContextVar,
35+
capture_internal_exceptions,
3536
event_from_exception,
3637
HAS_REAL_CONTEXTVARS,
3738
CONTEXTVARS_ERROR_MESSAGE,
@@ -348,19 +349,18 @@ def _prepopulate_attributes(scope):
348349
try:
349350
host, port = scope[attr]
350351
attributes[f"{attr}.address"] = host
351-
attributes[f"{attr}.port"] = port
352+
if port is not None:
353+
attributes[f"{attr}.port"] = port
352354
except Exception:
353355
pass
354356

355-
try:
357+
with capture_internal_exceptions():
356358
full_url = _get_url(scope)
357359
query = _get_query(scope)
358360
if query:
359361
attributes["url.query"] = query
360362
full_url = f"{full_url}?{query}"
361363

362364
attributes["url.full"] = full_url
363-
except Exception:
364-
pass
365365

366366
return attributes

sentry_sdk/integrations/aws_lambda.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ def _event_from_error_json(error_json):
468468

469469

470470
def _prepopulate_attributes(aws_event, aws_context):
471+
# type: (Any, Any) -> dict[str, Any]
471472
attributes = {
472473
"cloud.provider": "aws",
473474
}

sentry_sdk/integrations/celery/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ def sentry_publish(self, *args, **kwargs):
514514

515515

516516
def _prepopulate_attributes(task, args, kwargs):
517+
# type: (Any, *Any, **Any) -> dict[str, str]
517518
attributes = {
518519
"celery.job.task": task.name,
519520
"celery.job.args": _serialize_span_attribute(args),

sentry_sdk/integrations/gcp.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ def _get_google_cloud_logs_url(final_time):
236236

237237

238238
def _prepopulate_attributes(gcp_event):
239+
# type: (Any) -> dict[str, Any]
239240
attributes = {
240241
"cloud.provider": "gcp",
241242
}

sentry_sdk/integrations/tornado.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,7 @@ def _prepopulate_attributes(request):
254254
except ValueError:
255255
attributes["server.address"] = request.host
256256

257-
try:
257+
with capture_internal_exceptions():
258258
attributes["url.full"] = request.full_url()
259-
except Exception:
260-
pass
261259

262260
return attributes

sentry_sdk/integrations/wsgi.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
_filter_headers,
1212
)
1313
from sentry_sdk.sessions import track_session
14-
from sentry_sdk.scope import use_isolation_scope
1514
from sentry_sdk.tracing import Transaction, TRANSACTION_SOURCE_ROUTE
1615
from sentry_sdk.utils import (
1716
ContextVar,
@@ -324,6 +323,7 @@ def event_processor(event, hint):
324323

325324

326325
def _prepopulate_attributes(wsgi_environ, use_x_forwarded_for=False):
326+
# type: (dict[str, str], bool) -> dict[str, str]
327327
"""Extract span attributes from the WSGI environment."""
328328
attributes = {}
329329

@@ -339,11 +339,9 @@ def _prepopulate_attributes(wsgi_environ, use_x_forwarded_for=False):
339339
except Exception:
340340
attributes["network.protocol.name"] = wsgi_environ["SERVER_PROTOCOL"]
341341

342-
try:
342+
with capture_internal_exceptions():
343343
url = get_request_url(wsgi_environ, use_x_forwarded_for)
344344
query = wsgi_environ.get("QUERY_STRING")
345345
attributes["url.full"] = f"{url}?{query}"
346-
except Exception:
347-
pass
348346

349347
return attributes

0 commit comments

Comments
 (0)