@@ -216,27 +216,32 @@ async def _run_app(
216216 span_ctx : "ContextManager[Union[Span, StreamedSpan, None]]"
217217 if span_streaming :
218218 segment : "Optional[StreamedSpan]" = None
219- attributes : "Attributes" = {}
219+ attributes : "Attributes" = {
220+ "sentry.span.source" : getattr (
221+ transaction_source , "value" , transaction_source
222+ ),
223+ "sentry.origin" : self .span_origin ,
224+ "asgi.type" : ty ,
225+ }
220226 sentry_scope .set_custom_sampling_context ({"asgi_scope" : scope })
227+
221228 if ty in ("http" , "websocket" ):
222229 if (
223230 ty == "websocket"
224231 or method in self .http_methods_to_capture
225232 ):
226233 sentry_sdk .traces .continue_trace (_get_headers (scope ))
227234 attributes ["sentry.op" ] = f"{ ty } .server"
235+ segment = sentry_sdk .traces .start_span (
236+ name = transaction_name , attributes = attributes
237+ )
228238 else :
229239 sentry_sdk .traces .new_trace ()
230240 attributes ["sentry.op" ] = OP .HTTP_SERVER
241+ segment = sentry_sdk .traces .start_span (
242+ name = transaction_name , attributes = attributes
243+ )
231244
232- attributes ["sentry.span.source" ] = getattr (
233- transaction_source , "value" , transaction_source
234- )
235- attributes ["sentry.origin" ] = self .span_origin
236- attributes ["asgi.type" ] = ty
237- segment = sentry_sdk .traces .start_span (
238- name = transaction_name , attributes = attributes
239- )
240245 span_ctx = segment or nullcontext ()
241246
242247 else :
0 commit comments