Skip to content

feat(flask): Add http.route attribute - #7344

Draft
alexander-alderman-webb wants to merge 2 commits into
masterfrom
webb/flask/http-route
Draft

feat(flask): Add http.route attribute#7344
alexander-alderman-webb wants to merge 2 commits into
masterfrom
webb/flask/http-route

Conversation

@alexander-alderman-webb

Copy link
Copy Markdown
Contributor

Description

Set the http.route attribute on the server span in patches for Flask endpoints.

Issues

Reminders

from typing import TYPE_CHECKING

import sentry_sdk
from sentry_sdk.consts import SPANDATA

@sentry-warden sentry-warden Bot Sep 2, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

http.route access crashes when request.url_rule is None

In _request_started, request.url_rule.rule is used without a null check; unmatched routes leave url_rule as None and will raise AttributeError under span streaming. Guard like FastAPI (route_path is not None) or wrap with capture_internal_exceptions, matching _set_transaction_name_and_source.

Evidence
  • Hunk adds SPANDATA import used by the new http.route write in _request_started.
  • That path does server_span.set_attribute(SPANDATA.HTTP_ROUTE, request.url_rule.rule) with only a server_span is not None guard.
  • Nearby _set_transaction_name_and_source already try/excepts the same request.url_rule access because it can be missing.
  • FastAPI only sets HTTP_ROUTE when route_path is not None; Flask does not.
  • test_http_route only covers a matched /message/123456 path, not 404/unmatched routing.
Also found at 2 additional locations
  • sentry_sdk/integrations/flask.py:154-156
  • tests/integrations/flask/test_flask.py:162-162

Identified by Warden · code-review, find-bugs · FE7-QHG

@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Codecov Results 📊

130423 passed | ❌ 1 failed | ⏭️ 7110 skipped | Total: 137534 | Pass Rate: 94.83% | Execution Time: 471m 33s

📊 Comparison with Base Branch

Metric Change
Total Tests 📈 +32133
Passed Tests 📈 +31501
Failed Tests 📈 +1
Skipped Tests 📈 +631

➕ New Tests (1)

View new tests
  • test_continuous_profiler_auto_start_and_stop_sampled_span_streaming[experiment-thread]
    • File: tests.profiler.test_continuous_profiler
    • Status: ❌ Failing

❌ Failed Tests

test_continuous_profiler_auto_start_and_stop_sampled_span_streaming[experiment-thread]

File: tests.profiler.test_continuous_profiler
Suite: py3.15-common
Error: AssertionError: profiler should not be running assert 'ec68987471e1484dadf859f0946ed39a' is None + where 'ec68987471e1484dadf859f0946ed39a' = get_profiler_id()

Stack Trace
tests/profiler/test_continuous_profiler.py:896: in test_continuous_profiler_auto_start_and_stop_sampled_span_streaming
    assert get_profiler_id() is None, "profiler should not be running"
E   AssertionError: profiler should not be running
E   assert 'ec68987471e1484dadf859f0946ed39a' is None
E    +  where 'ec68987471e1484dadf859f0946ed39a' = get_profiler_id()

✅ Patch coverage is 100.00%. Project has 2498 uncovered lines.
✅ Project coverage is 90.27%. Comparing base (base) to head (head).

Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    90.27%    90.27%        —%
==========================================
  Files          193       193         —
  Lines        25682     25686        +4
  Branches      9468      9470        +2
==========================================
+ Hits         23184     23188        +4
- Misses        2498      2498         —
- Partials      1442      1442         —

Generated by Codecov Action

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant