Skip to content

Commit a58e42d

Browse files
remanining tests
1 parent 89023f4 commit a58e42d

6 files changed

Lines changed: 195 additions & 4 deletions

File tree

tests/integrations/django/asgi/test_asgi.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,3 +1049,54 @@ async def test_transaction_http_method_custom(
10491049
(event1, event2) = events
10501050
assert event1["request"]["method"] == "OPTIONS"
10511051
assert event2["request"]["method"] == "HEAD"
1052+
1053+
1054+
@pytest.mark.parametrize("application", APPS)
1055+
@pytest.mark.asyncio
1056+
@pytest.mark.skipif(
1057+
django.VERSION < (3, 0), reason="Django ASGI support shipped in 3.0"
1058+
)
1059+
@pytest.mark.parametrize("span_streaming", [True, False])
1060+
async def test_request_url(
1061+
sentry_init,
1062+
capture_events,
1063+
capture_items,
1064+
application,
1065+
span_streaming,
1066+
):
1067+
sentry_init(
1068+
integrations=[DjangoIntegration()],
1069+
traces_sample_rate=1.0,
1070+
send_default_pii=True,
1071+
_experiments={"trace_lifecycle": "stream" if span_streaming else "static"},
1072+
)
1073+
comm = HttpCommunicator(
1074+
application,
1075+
"GET",
1076+
"/root/nomessage",
1077+
)
1078+
1079+
if span_streaming:
1080+
items = capture_items("span")
1081+
await comm.get_response()
1082+
await comm.wait()
1083+
1084+
sentry_sdk.flush()
1085+
spans = [item.payload for item in items]
1086+
1087+
(server_span,) = (
1088+
span
1089+
for span in spans
1090+
if span["attributes"].get("sentry.op") == "http.server"
1091+
)
1092+
assert server_span["attributes"]["url.full"] == (
1093+
"http://testserver/root/nomessage"
1094+
)
1095+
else:
1096+
events = capture_events()
1097+
1098+
await comm.get_response()
1099+
await comm.wait()
1100+
1101+
(event,) = events
1102+
assert event["request"]["url"] == "http://testserver/root/nomessage"

tests/integrations/fastapi/test_fastapi.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262

6363
def fastapi_app_factory():
6464
app = FastAPI()
65+
mounted_app = FastAPI()
6566

6667
@app.get("/error")
6768
async def _error():
@@ -74,6 +75,7 @@ async def _message():
7475
capture_message("Hi")
7576
return {"message": "Hi"}
7677

78+
@mounted_app.get("/nomessage")
7779
@app.delete("/nomessage")
7880
@app.get("/nomessage")
7981
@app.head("/nomessage")
@@ -118,6 +120,8 @@ async def body_form(
118120
capture_message("hi")
119121
return {"status": "ok"}
120122

123+
app.mount("/root", mounted_app)
124+
121125
return app
122126

123127

@@ -1058,7 +1062,7 @@ def test_request_url(sentry_init, capture_events, capture_items, span_streaming)
10581062

10591063
starlette_app = fastapi_app_factory()
10601064

1061-
client = TestClient(starlette_app, root_path="/root")
1065+
client = TestClient(starlette_app)
10621066

10631067
if span_streaming:
10641068
items = capture_items("span")
@@ -1080,7 +1084,6 @@ def test_request_url(sentry_init, capture_events, capture_items, span_streaming)
10801084

10811085
client.get("/root/nomessage")
10821086

1083-
assert len(events) == 1
10841087
(event,) = events
10851088
assert event["request"]["url"] == "http://testserver/root/nomessage"
10861089

tests/integrations/litestar/test_litestar.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ async def message_with_id() -> "dict[str, Any]":
4747
capture_message("hi")
4848
return {"status": "ok"}
4949

50+
@get("/nomessage")
51+
async def nomessage() -> "dict[str, Any]":
52+
return {"status": "ok"}
53+
5054
logging_config = LoggingConfig()
5155

5256
app = Litestar(
@@ -55,6 +59,7 @@ async def message_with_id() -> "dict[str, Any]":
5559
custom_error,
5660
message,
5761
message_with_id,
62+
nomessage,
5863
MyController,
5964
],
6065
debug=debug,
@@ -818,3 +823,41 @@ async def error() -> None: ...
818823
event_exception = events[0]["exception"]["values"][0]
819824
assert event_exception["type"] == "RuntimeError"
820825
assert event_exception["value"] == "Too Hot"
826+
827+
828+
@pytest.mark.parametrize("span_streaming", [True, False])
829+
def test_request_url(sentry_init, capture_events, capture_items, span_streaming):
830+
sentry_init(
831+
traces_sample_rate=1.0,
832+
integrations=[LitestarIntegration()],
833+
_experiments={
834+
"trace_lifecycle": "stream" if span_streaming else "static",
835+
},
836+
)
837+
838+
litestar_app = litestar_app_factory()
839+
client = TestClient(litestar_app, root_path="/root")
840+
841+
if span_streaming:
842+
items = capture_items("span")
843+
844+
client.get("/root/nomessage")
845+
846+
sentry_sdk.flush()
847+
spans = [item.payload for item in items]
848+
849+
(server_span,) = (
850+
span
851+
for span in spans
852+
if span["attributes"].get("sentry.op") == "http.server"
853+
)
854+
assert server_span["attributes"]["url.full"] == (
855+
"http://testserver/root/nomessage"
856+
)
857+
else:
858+
events = capture_events()
859+
860+
client.get("/root/nomessage")
861+
862+
(event,) = events
863+
assert event["request"]["url"] == "http://testserver/root/nomessage"

tests/integrations/quart/test_quart.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ async def hi():
4444
capture_message("hi")
4545
return "ok"
4646

47+
@app.route("/nomessage")
48+
async def nomessage():
49+
return "ok"
50+
4751
@app.route("/message/<message_id>")
4852
async def hi_with_id(message_id):
4953
capture_message("hi with id")
@@ -682,6 +686,22 @@ async def test_span_origin(sentry_init, capture_events):
682686
assert event["contexts"]["trace"]["origin"] == "auto.http.quart"
683687

684688

689+
@pytest.mark.asyncio
690+
async def test_request_url(sentry_init, capture_events):
691+
sentry_init(
692+
traces_sample_rate=1.0,
693+
integrations=[quart_sentry.QuartIntegration()],
694+
)
695+
app = quart_app_factory()
696+
client = app.test_client()
697+
698+
events = capture_events()
699+
await client.get("/root/nomessage", root_path="/root")
700+
701+
(event,) = events
702+
assert event["request"]["url"] == "http://localhost/root/nomessage"
703+
704+
685705
@pytest.mark.asyncio
686706
async def test_span_streaming_basic(sentry_init, capture_items):
687707
sentry_init(
@@ -966,3 +986,28 @@ async def test_span_streaming_sensitive_header_passthrough_with_pii(
966986
segment["attributes"]["http.request.header.authorization"]
967987
== "Bearer secret-token"
968988
)
989+
990+
991+
@pytest.mark.asyncio
992+
async def test_span_streaming_request_url(sentry_init, capture_items):
993+
sentry_init(
994+
traces_sample_rate=1.0,
995+
send_default_pii=True,
996+
integrations=[quart_sentry.QuartIntegration()],
997+
_experiments={
998+
"trace_lifecycle": "stream",
999+
},
1000+
)
1001+
app = quart_app_factory()
1002+
client = app.test_client()
1003+
1004+
items = capture_items("span")
1005+
await client.get("/root/nomessage", root_path="/root")
1006+
1007+
sentry_sdk.flush()
1008+
spans = [item.payload for item in items]
1009+
1010+
(server_span,) = (
1011+
span for span in spans if span["attributes"].get("sentry.op") == "http.server"
1012+
)
1013+
assert server_span["attributes"]["url.full"] == "http://localhost/root/nomessage"

tests/integrations/starlette/test_starlette.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ async def _body_raw(request):
146146
"TRACE",
147147
]
148148

149+
mounted_app = starlette.applications.Starlette(
150+
routes=[
151+
starlette.routing.Route("/nomessage", _nomessage, methods=all_methods),
152+
],
153+
)
154+
149155
app = starlette.applications.Starlette(
150156
debug=debug,
151157
routes=[
@@ -160,6 +166,7 @@ async def _body_raw(request):
160166
starlette.routing.Route("/body/json", _body_json, methods=["POST"]),
161167
starlette.routing.Route("/body/form", _body_form, methods=["POST"]),
162168
starlette.routing.Route("/body/raw", _body_raw, methods=["POST"]),
169+
starlette.routing.Mount("/root", app=mounted_app),
163170
],
164171
middleware=middleware,
165172
)
@@ -1492,7 +1499,7 @@ def test_request_url(sentry_init, capture_events, capture_items, span_streaming)
14921499

14931500
starlette_app = starlette_app_factory()
14941501

1495-
client = TestClient(starlette_app, root_path="/root")
1502+
client = TestClient(starlette_app)
14961503

14971504
if span_streaming:
14981505
items = capture_items("span")
@@ -1514,7 +1521,6 @@ def test_request_url(sentry_init, capture_events, capture_items, span_streaming)
15141521

15151522
client.get("/root/nomessage")
15161523

1517-
assert len(events) == 1
15181524
(event,) = events
15191525
assert event["request"]["url"] == "http://testserver/root/nomessage"
15201526

tests/integrations/starlite/test_starlite.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ async def message_with_id() -> "Dict[str, Any]":
4141
capture_message("hi")
4242
return {"status": "ok"}
4343

44+
@get("/nomessage")
45+
async def nomessage() -> "Dict[str, Any]":
46+
return {"status": "ok"}
47+
4448
logging_config = LoggingConfig()
4549

4650
app = Starlite(
@@ -49,6 +53,7 @@ async def message_with_id() -> "Dict[str, Any]":
4953
custom_error,
5054
message,
5155
message_with_id,
56+
nomessage,
5257
MyController,
5358
],
5459
debug=debug,
@@ -574,3 +579,41 @@ async def __call__(self, scope, receive, send):
574579
}
575580
else:
576581
assert "user" not in event
582+
583+
584+
@pytest.mark.parametrize("span_streaming", [True, False])
585+
def test_request_url(sentry_init, capture_events, capture_items, span_streaming):
586+
sentry_init(
587+
traces_sample_rate=1.0,
588+
integrations=[StarliteIntegration()],
589+
_experiments={
590+
"trace_lifecycle": "stream" if span_streaming else "static",
591+
},
592+
)
593+
594+
starlite_app = starlite_app_factory()
595+
client = TestClient(starlite_app, root_path="/root")
596+
597+
if span_streaming:
598+
items = capture_items("span")
599+
600+
client.get("/nomessage")
601+
602+
sentry_sdk.flush()
603+
spans = [item.payload for item in items]
604+
605+
(server_span,) = (
606+
span
607+
for span in spans
608+
if span["attributes"].get("sentry.op") == "http.server"
609+
)
610+
assert server_span["attributes"]["url.full"] == (
611+
"http://testserver/root/nomessage"
612+
)
613+
else:
614+
events = capture_events()
615+
616+
client.get("/nomessage")
617+
618+
(event,) = events
619+
assert event["request"]["url"] == "http://testserver/root/nomessage"

0 commit comments

Comments
 (0)