Skip to content

Commit

Permalink
Fix most starlette tests
Browse files Browse the repository at this point in the history
mainly some middleware span reordering
  • Loading branch information
sl0thentr0py committed Nov 11, 2024
1 parent 706300c commit 8444e11
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions tests/integrations/starlette/test_starlette.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ def test_user_information_transaction_no_pii(sentry_init, capture_events):
assert "user" not in transaction_event


def test_middleware_spans(sentry_init, capture_events):
def test_middleware_spans(sentry_init, capture_events, render_span_tree):
sentry_init(
traces_sample_rate=1.0,
integrations=[StarletteIntegration()],
Expand All @@ -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 @@ -787,7 +787,7 @@ def test_middleware_receive_send(sentry_init, capture_events):
pass


def test_middleware_partial_receive_send(sentry_init, capture_events):
def test_middleware_partial_receive_send(sentry_init, capture_events, render_span_tree):
sentry_init(
traces_sample_rate=1.0,
integrations=[StarletteIntegration()],
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 8444e11

Please sign in to comment.