Skip to content

Commit

Permalink
Fix most starlette tests (#3749)
Browse files Browse the repository at this point in the history
mainly some middleware span reordering
  • Loading branch information
sl0thentr0py authored Nov 11, 2024
1 parent b3084d1 commit fbbf5e7
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions tests/integrations/starlette/test_starlette.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,9 +659,9 @@ def test_middleware_spans(sentry_init, capture_events):
"AuthenticationMiddleware",
"ExceptionMiddleware",
"AuthenticationMiddleware", # 'op': 'middleware.starlette.send'
"ServerErrorMiddleware", # 'op': 'middleware.starlette.send'
"AuthenticationMiddleware", # 'op': 'middleware.starlette.send'
"ServerErrorMiddleware", # 'op': 'middleware.starlette.send'
"ServerErrorMiddleware", # 'op': 'middleware.starlette.send'
]

assert len(transaction_event["spans"]) == len(expected_middleware_spans)
Expand Down Expand Up @@ -736,23 +736,23 @@ def test_middleware_callback_spans(sentry_init, capture_events):
},
{
"op": "middleware.starlette.send",
"description": "ServerErrorMiddleware.__call__.<locals>._send",
"tags": {"starlette.middleware_name": "SampleMiddleware"},
"description": "SampleMiddleware.__call__.<locals>.do_stuff",
"tags": {"starlette.middleware_name": "ExceptionMiddleware"},
},
{
"op": "middleware.starlette.send",
"description": "SentryAsgiMiddleware._run_app.<locals>._sentry_wrapped_send",
"tags": {"starlette.middleware_name": "ServerErrorMiddleware"},
"description": "ServerErrorMiddleware.__call__.<locals>._send",
"tags": {"starlette.middleware_name": "SampleMiddleware"},
},
{
"op": "middleware.starlette.send",
"description": "SampleMiddleware.__call__.<locals>.do_stuff",
"tags": {"starlette.middleware_name": "ExceptionMiddleware"},
"description": "ServerErrorMiddleware.__call__.<locals>._send",
"tags": {"starlette.middleware_name": "SampleMiddleware"},
},
{
"op": "middleware.starlette.send",
"description": "ServerErrorMiddleware.__call__.<locals>._send",
"tags": {"starlette.middleware_name": "SampleMiddleware"},
"description": "SentryAsgiMiddleware._run_app.<locals>._sentry_wrapped_send",
"tags": {"starlette.middleware_name": "ServerErrorMiddleware"},
},
{
"op": "middleware.starlette.send",
Expand Down Expand Up @@ -830,16 +830,16 @@ def test_middleware_partial_receive_send(sentry_init, capture_events):
"description": "ServerErrorMiddleware.__call__.<locals>._send",
"tags": {"starlette.middleware_name": "SamplePartialReceiveSendMiddleware"},
},
{
"op": "middleware.starlette.send",
"description": "SentryAsgiMiddleware._run_app.<locals>._sentry_wrapped_send",
"tags": {"starlette.middleware_name": "ServerErrorMiddleware"},
},
{
"op": "middleware.starlette",
"description": "ExceptionMiddleware",
"tags": {"starlette.middleware_name": "ExceptionMiddleware"},
},
{
"op": "middleware.starlette.send",
"description": "SentryAsgiMiddleware._run_app.<locals>._sentry_wrapped_send",
"tags": {"starlette.middleware_name": "ServerErrorMiddleware"},
},
{
"op": "middleware.starlette.send",
"description": "functools.partial(<function SamplePartialReceiveSendMiddleware.__call__.<locals>.my_send at ",
Expand Down Expand Up @@ -886,13 +886,13 @@ def test_active_thread_id(sentry_init, capture_envelopes, teardown_profiling, en
sentry_init(
traces_sample_rate=1.0,
profiles_sample_rate=1.0,
integrations=[StarletteIntegration()],
)
app = starlette_app_factory()
asgi_app = SentryAsgiMiddleware(app)

envelopes = capture_envelopes()

client = TestClient(asgi_app)
client = TestClient(app)
response = client.get(endpoint)
assert response.status_code == 200

Expand Down Expand Up @@ -1244,9 +1244,7 @@ def test_transaction_http_method_default(sentry_init, capture_events):
"""
sentry_init(
traces_sample_rate=1.0,
integrations=[
StarletteIntegration(),
],
integrations=[StarletteIntegration()],
)
events = capture_events()

Expand Down

0 comments on commit fbbf5e7

Please sign in to comment.