12
12
import sentry_sdk
13
13
from sentry_sdk .api import continue_trace
14
14
from sentry_sdk .consts import OP
15
-
16
15
from sentry_sdk .integrations ._asgi_common import (
17
16
_get_headers ,
18
17
_get_request_data ,
42
41
43
42
if TYPE_CHECKING :
44
43
from typing import Any
45
- from typing import Callable
46
44
from typing import Dict
47
45
from typing import Optional
48
46
from typing import Tuple
@@ -102,6 +100,7 @@ def __init__(
102
100
mechanism_type = "asgi" , # type: str
103
101
span_origin = "manual" , # type: str
104
102
http_methods_to_capture = DEFAULT_HTTP_METHODS_TO_CAPTURE , # type: Tuple[str, ...]
103
+ asgi_version = None , # type: Optional[int]
105
104
):
106
105
# type: (...) -> None
107
106
"""
@@ -140,10 +139,16 @@ def __init__(
140
139
self .app = app
141
140
self .http_methods_to_capture = http_methods_to_capture
142
141
143
- if _looks_like_asgi3 (app ):
144
- self .__call__ = self ._run_asgi3 # type: Callable[..., Any]
145
- else :
146
- self .__call__ = self ._run_asgi2
142
+ if asgi_version is None :
143
+ if _looks_like_asgi3 (app ):
144
+ asgi_version = 3
145
+ else :
146
+ asgi_version = 2
147
+
148
+ if asgi_version == 3 :
149
+ self .__call__ = self ._run_asgi3
150
+ elif asgi_version == 2 :
151
+ self .__call__ = self ._run_asgi2 # type: ignore
147
152
148
153
def _capture_lifespan_exception (self , exc ):
149
154
# type: (Exception) -> None
@@ -217,28 +222,16 @@ async def _run_app(self, scope, receive, send, asgi_version):
217
222
source = transaction_source ,
218
223
origin = self .span_origin ,
219
224
)
220
- logger .debug (
221
- "[ASGI] Created transaction (continuing trace): %s" ,
222
- transaction ,
223
- )
224
225
else :
225
226
transaction = Transaction (
226
227
op = OP .HTTP_SERVER ,
227
228
name = transaction_name ,
228
229
source = transaction_source ,
229
230
origin = self .span_origin ,
230
231
)
231
- logger .debug (
232
- "[ASGI] Created transaction (new): %s" , transaction
233
- )
234
232
235
233
if transaction :
236
234
transaction .set_tag ("asgi.type" , ty )
237
- logger .debug (
238
- "[ASGI] Set transaction name and source on transaction: '%s' / '%s'" ,
239
- transaction .name ,
240
- transaction .source ,
241
- )
242
235
243
236
with (
244
237
sentry_sdk .start_transaction (
@@ -248,7 +241,6 @@ async def _run_app(self, scope, receive, send, asgi_version):
248
241
if transaction is not None
249
242
else nullcontext ()
250
243
):
251
- logger .debug ("[ASGI] Started transaction: %s" , transaction )
252
244
try :
253
245
254
246
async def _sentry_wrapped_send (event ):
@@ -303,12 +295,6 @@ def event_processor(self, event, hint, asgi_scope):
303
295
event ["transaction" ] = name
304
296
event ["transaction_info" ] = {"source" : source }
305
297
306
- logger .debug (
307
- "[ASGI] Set transaction name and source in event_processor: '%s' / '%s'" ,
308
- event ["transaction" ],
309
- event ["transaction_info" ]["source" ],
310
- )
311
-
312
298
return event
313
299
314
300
# Helper functions.
0 commit comments