@@ -126,6 +126,31 @@ async def app(scope, receive, send):
126
126
return app
127
127
128
128
129
+ @pytest .fixture
130
+ def asgi3_custom_transaction_app ():
131
+
132
+ async def app (scope , receive , send ):
133
+ sentry_sdk .get_current_scope ().set_transaction_name ("foobar" , source = "custom" )
134
+ await send (
135
+ {
136
+ "type" : "http.response.start" ,
137
+ "status" : 200 ,
138
+ "headers" : [
139
+ [b"content-type" , b"text/plain" ],
140
+ ],
141
+ }
142
+ )
143
+
144
+ await send (
145
+ {
146
+ "type" : "http.response.body" ,
147
+ "body" : b"Hello, world!" ,
148
+ }
149
+ )
150
+
151
+ return app
152
+
153
+
129
154
def test_invalid_transaction_style (asgi3_app ):
130
155
with pytest .raises (ValueError ) as exp :
131
156
SentryAsgiMiddleware (asgi3_app , transaction_style = "URL" )
@@ -679,3 +704,20 @@ def dummy_traces_sampler(sampling_context):
679
704
680
705
async with TestClient (app ) as client :
681
706
await client .get (request_url )
707
+
708
+
709
+ @pytest .mark .asyncio
710
+ async def test_custom_transaction_name (
711
+ sentry_init , asgi3_custom_transaction_app , capture_events
712
+ ):
713
+ sentry_init (traces_sample_rate = 1.0 )
714
+ events = capture_events ()
715
+ app = SentryAsgiMiddleware (asgi3_custom_transaction_app )
716
+
717
+ async with TestClient (app ) as client :
718
+ await client .get ("/test" )
719
+
720
+ (transaction_event ,) = events
721
+ assert transaction_event ["type" ] == "transaction"
722
+ assert transaction_event ["transaction" ] == "foobar"
723
+ assert transaction_event ["transaction_info" ] == {"source" : "custom" }
0 commit comments