Skip to content

Commit

Permalink
Fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
antonpirker committed Aug 28, 2023
1 parent 0d10528 commit 0ee7172
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
3 changes: 0 additions & 3 deletions sentry_sdk/integrations/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,6 @@ async def _sentry_wrapped_send(event):
return await self.app(scope)(
receive, _sentry_wrapped_send
)

# return await callback(transaction)

except Exception as exc:
_capture_exception(
hub, exc, mechanism_type=self.mechanism_type
Expand Down
1 change: 1 addition & 0 deletions sentry_sdk/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,7 @@ def set_context(self, key, value):

def set_http_status(self, http_status):
# type: (int) -> None
super(Transaction, self).set_http_status(http_status)
self.set_context("response", {"status_code": http_status})

def to_json(self):
Expand Down
31 changes: 14 additions & 17 deletions tests/integrations/asgi/test_asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ async def app(scope, receive, send):

@pytest.fixture
def asgi3_app_with_error():
async def send_with_error(event):
1 / 0

async def app(scope, receive, send):
await send(
await send_with_error(
{
"type": "http.response.start",
"status": 200,
Expand All @@ -58,10 +61,7 @@ async def app(scope, receive, send):
],
}
)

1 / 0

await send(
await send_with_error(
{
"type": "http.response.body",
"body": b"Hello, world!",
Expand Down Expand Up @@ -167,9 +167,9 @@ async def test_capture_transaction_with_error(
sentry_init(send_default_pii=True, traces_sample_rate=1.0)
app = SentryAsgiMiddleware(asgi3_app_with_error)

events = capture_events()
with pytest.raises(ZeroDivisionError):
async with TestClient(app) as client:
events = capture_events()
await client.get("/")

(error_event, transaction_event) = events
Expand Down Expand Up @@ -395,38 +395,35 @@ async def test_auto_session_tracking_with_aggregates(
(
"/message",
"endpoint",
"tests.integrations.asgi.test_asgi.asgi3_app_with_error.<locals>.app",
"tests.integrations.asgi.test_asgi.asgi3_app.<locals>.app",
"component",
),
],
)
@pytest.mark.asyncio
async def test_transaction_style(
sentry_init,
asgi3_app_with_error,
asgi3_app,
capture_events,
url,
transaction_style,
expected_transaction,
expected_source,
):
sentry_init(send_default_pii=True, traces_sample_rate=1.0)
app = SentryAsgiMiddleware(
asgi3_app_with_error, transaction_style=transaction_style
)
app = SentryAsgiMiddleware(asgi3_app, transaction_style=transaction_style)

scope = {
"endpoint": asgi3_app_with_error,
"endpoint": asgi3_app,
"route": url,
"client": ("127.0.0.1", 60457),
}

with pytest.raises(ZeroDivisionError):
async with TestClient(app, scope=scope) as client:
events = capture_events()
await client.get(url)
async with TestClient(app, scope=scope) as client:
events = capture_events()
await client.get(url)

(_, transaction_event) = events
(transaction_event,) = events

assert transaction_event["transaction"] == expected_transaction
assert transaction_event["transaction_info"] == {"source": expected_source}
Expand Down

0 comments on commit 0ee7172

Please sign in to comment.