Skip to content

feat(fastapi): Add http.route attribute - #7322

Draft
alexander-alderman-webb wants to merge 5 commits into
masterfrom
webb/fastapi/http-route
Draft

feat(fastapi): Add http.route attribute#7322
alexander-alderman-webb wants to merge 5 commits into
masterfrom
webb/fastapi/http-route

Conversation

@alexander-alderman-webb

@alexander-alderman-webb alexander-alderman-webb commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Description

Add the _server_segment_span field on the Scope class so HTTP framework integrations have a reference to the server span. In this case, the reference is used to set the parametrized route as the http.route attribute.

Generically setting the current segment on the Scope is not enough to always have a reference to the server segment span.
The user can start a new segment in the same trace by calling traces.start_span(parent_span=None).

Issues

Reminders

Comment thread sentry_sdk/integrations/fastapi.py Outdated
Comment thread sentry_sdk/integrations/fastapi.py Outdated
Comment thread sentry_sdk/scope.py Outdated
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Codecov Results 📊

121236 passed | ❌ 2 failed | ⏭️ 6762 skipped | Total: 128000 | Pass Rate: 94.72% | Execution Time: 429m 51s

📊 Comparison with Base Branch

Metric Change
Total Tests 📉 -692
Passed Tests 📉 -694
Failed Tests 📈 +2
Skipped Tests

➕ New Tests (2)

View new tests
  • test_cache_spans_item_size[True]
    • File: tests.integrations.django.test_cache_module
    • Status: ❌ Failing
  • test_continuous_profiler_auto_start_and_stop_sampled[non-experiment-thread]
    • File: tests.profiler.test_continuous_profiler
    • Status: ❌ Failing

❌ Failed Tests

test_cache_spans_item_size[True]

File: tests.integrations.django.test_cache_module
Suite: py3.14-django-v5.2.17
Error: tests/integrations/django/test_cache_module.py:764: in test_cache_spans_item_size assert not spans[0]["attributes"]["cache.hit"] E assert not True

Stack Trace
tests/integrations/django/test_cache_module.py:764: in test_cache_spans_item_size
    assert not spans[0]["attributes"]["cache.hit"]
E   assert not True

test_continuous_profiler_auto_start_and_stop_sampled[non-experiment-thread]

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

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

✅ Patch coverage is 88.89%. Project has 2492 uncovered lines.
❌ Project coverage is 90.28%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
sentry_sdk/integrations/asgi.py 50.00% ⚠️ 1 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
- Coverage    90.29%    90.28%    -0.01%
==========================================
  Files          193       193         —
  Lines        25621     25630        +9
  Branches      9438      9440        +2
==========================================
+ Hits         23132     23138        +6
- Misses        2489      2492        +3
- Partials      1436      1438        +2

Generated by Codecov Action

Comment thread sentry_sdk/integrations/fastapi.py Outdated
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