|
14 | 14 | from sentry_sdk.integrations.logging import ignore_logger_for_events |
15 | 15 | from sentry_sdk.scope import should_send_default_pii |
16 | 16 | from sentry_sdk.tracing import SOURCE_FOR_STYLE, TransactionSource |
17 | | -from sentry_sdk.tracing_utils import has_span_streaming_enabled |
18 | 17 | from sentry_sdk.utils import ( |
19 | 18 | ensure_integration_enabled, |
20 | 19 | event_from_exception, |
@@ -169,100 +168,60 @@ async def _create_span_call( |
169 | 168 | return await old_call(self, scope, receive, send) |
170 | 169 |
|
171 | 170 | middleware_name = self.__class__.__name__ |
172 | | - if has_span_streaming_enabled(client.options): |
173 | | - if sentry_sdk.traces.get_current_span() is None: |
174 | | - return await old_call(self, scope, receive, send) |
175 | | - with sentry_sdk.traces.start_span( |
176 | | - name=middleware_name, |
177 | | - attributes={ |
178 | | - "sentry.op": OP.MIDDLEWARE_LITESTAR, |
179 | | - "sentry.origin": LitestarIntegration.origin, |
180 | | - }, |
181 | | - ) as middleware_span: |
182 | | - middleware_span.set_attribute(SPANDATA.MIDDLEWARE_NAME, middleware_name) |
183 | | - |
184 | | - # Creating spans for the "receive" callback |
185 | | - async def _sentry_receive( |
186 | | - *args: "Any", **kwargs: "Any" |
187 | | - ) -> "Union[HTTPReceiveMessage, WebSocketReceiveMessage]": |
188 | | - if client.get_integration(LitestarIntegration) is None: |
189 | | - return await receive(*args, **kwargs) |
190 | | - if sentry_sdk.traces.get_current_span() is None: |
191 | | - return await receive(*args, **kwargs) |
192 | | - with sentry_sdk.traces.start_span( |
193 | | - name=getattr(receive, "__qualname__", str(receive)), |
194 | | - attributes={ |
195 | | - "sentry.op": OP.MIDDLEWARE_LITESTAR_RECEIVE, |
196 | | - "sentry.origin": LitestarIntegration.origin, |
197 | | - }, |
198 | | - ) as span: |
199 | | - span.set_attribute(SPANDATA.MIDDLEWARE_NAME, middleware_name) |
200 | | - return await receive(*args, **kwargs) |
201 | | - |
202 | | - receive_name = getattr(receive, "__name__", str(receive)) |
203 | | - receive_patched = receive_name == "_sentry_receive" |
204 | | - new_receive = _sentry_receive if not receive_patched else receive |
205 | | - |
206 | | - # Creating spans for the "send" callback |
207 | | - async def _sentry_send(message: "Message") -> None: |
208 | | - if client.get_integration(LitestarIntegration) is None: |
209 | | - return await send(message) |
210 | | - if sentry_sdk.traces.get_current_span() is None: |
211 | | - return await send(message) |
212 | | - with sentry_sdk.traces.start_span( |
213 | | - name=getattr(send, "__qualname__", str(send)), |
214 | | - attributes={ |
215 | | - "sentry.op": OP.MIDDLEWARE_LITESTAR_SEND, |
216 | | - "sentry.origin": LitestarIntegration.origin, |
217 | | - }, |
218 | | - ) as span: |
219 | | - span.set_attribute(SPANDATA.MIDDLEWARE_NAME, middleware_name) |
220 | | - return await send(message) |
221 | | - |
222 | | - send_name = getattr(send, "__name__", str(send)) |
223 | | - send_patched = send_name == "_sentry_send" |
224 | | - new_send = _sentry_send if not send_patched else send |
225 | | - |
226 | | - return await old_call(self, scope, new_receive, new_send) |
227 | | - else: |
228 | | - with sentry_sdk.start_span( |
229 | | - op=OP.MIDDLEWARE_LITESTAR, |
230 | | - name=middleware_name, |
231 | | - origin=LitestarIntegration.origin, |
232 | | - ) as middleware_span: |
233 | | - # Creating spans for the "receive" callback |
234 | | - async def _sentry_receive( |
235 | | - *args: "Any", **kwargs: "Any" |
236 | | - ) -> "Union[HTTPReceiveMessage, WebSocketReceiveMessage]": |
237 | | - if client.get_integration(LitestarIntegration) is None: |
238 | | - return await receive(*args, **kwargs) |
239 | | - with sentry_sdk.start_span( |
240 | | - op=OP.MIDDLEWARE_LITESTAR_RECEIVE, |
241 | | - name=getattr(receive, "__qualname__", str(receive)), |
242 | | - origin=LitestarIntegration.origin, |
243 | | - ): |
244 | | - return await receive(*args, **kwargs) |
245 | | - |
246 | | - receive_name = getattr(receive, "__name__", str(receive)) |
247 | | - receive_patched = receive_name == "_sentry_receive" |
248 | | - new_receive = _sentry_receive if not receive_patched else receive |
249 | | - |
250 | | - # Creating spans for the "send" callback |
251 | | - async def _sentry_send(message: "Message") -> None: |
252 | | - if client.get_integration(LitestarIntegration) is None: |
253 | | - return await send(message) |
254 | | - with sentry_sdk.start_span( |
255 | | - op=OP.MIDDLEWARE_LITESTAR_SEND, |
256 | | - name=getattr(send, "__qualname__", str(send)), |
257 | | - origin=LitestarIntegration.origin, |
258 | | - ): |
259 | | - return await send(message) |
260 | | - |
261 | | - send_name = getattr(send, "__name__", str(send)) |
262 | | - send_patched = send_name == "_sentry_send" |
263 | | - new_send = _sentry_send if not send_patched else send |
264 | | - |
265 | | - return await old_call(self, scope, new_receive, new_send) |
| 171 | + if sentry_sdk.traces.get_current_span() is None: |
| 172 | + return await old_call(self, scope, receive, send) |
| 173 | + with sentry_sdk.traces.start_span( |
| 174 | + name=middleware_name, |
| 175 | + attributes={ |
| 176 | + "sentry.op": OP.MIDDLEWARE_LITESTAR, |
| 177 | + "sentry.origin": LitestarIntegration.origin, |
| 178 | + }, |
| 179 | + ) as middleware_span: |
| 180 | + middleware_span.set_attribute(SPANDATA.MIDDLEWARE_NAME, middleware_name) |
| 181 | + |
| 182 | + # Creating spans for the "receive" callback |
| 183 | + async def _sentry_receive( |
| 184 | + *args: "Any", **kwargs: "Any" |
| 185 | + ) -> "Union[HTTPReceiveMessage, WebSocketReceiveMessage]": |
| 186 | + if client.get_integration(LitestarIntegration) is None: |
| 187 | + return await receive(*args, **kwargs) |
| 188 | + if sentry_sdk.traces.get_current_span() is None: |
| 189 | + return await receive(*args, **kwargs) |
| 190 | + with sentry_sdk.traces.start_span( |
| 191 | + name=getattr(receive, "__qualname__", str(receive)), |
| 192 | + attributes={ |
| 193 | + "sentry.op": OP.MIDDLEWARE_LITESTAR_RECEIVE, |
| 194 | + "sentry.origin": LitestarIntegration.origin, |
| 195 | + }, |
| 196 | + ) as span: |
| 197 | + span.set_attribute(SPANDATA.MIDDLEWARE_NAME, middleware_name) |
| 198 | + return await receive(*args, **kwargs) |
| 199 | + |
| 200 | + receive_name = getattr(receive, "__name__", str(receive)) |
| 201 | + receive_patched = receive_name == "_sentry_receive" |
| 202 | + new_receive = _sentry_receive if not receive_patched else receive |
| 203 | + |
| 204 | + # Creating spans for the "send" callback |
| 205 | + async def _sentry_send(message: "Message") -> None: |
| 206 | + if client.get_integration(LitestarIntegration) is None: |
| 207 | + return await send(message) |
| 208 | + if sentry_sdk.traces.get_current_span() is None: |
| 209 | + return await send(message) |
| 210 | + with sentry_sdk.traces.start_span( |
| 211 | + name=getattr(send, "__qualname__", str(send)), |
| 212 | + attributes={ |
| 213 | + "sentry.op": OP.MIDDLEWARE_LITESTAR_SEND, |
| 214 | + "sentry.origin": LitestarIntegration.origin, |
| 215 | + }, |
| 216 | + ) as span: |
| 217 | + span.set_attribute(SPANDATA.MIDDLEWARE_NAME, middleware_name) |
| 218 | + return await send(message) |
| 219 | + |
| 220 | + send_name = getattr(send, "__name__", str(send)) |
| 221 | + send_patched = send_name == "_sentry_send" |
| 222 | + new_send = _sentry_send if not send_patched else send |
| 223 | + |
| 224 | + return await old_call(self, scope, new_receive, new_send) |
266 | 225 |
|
267 | 226 | not_yet_patched = old_call.__name__ not in ["_create_span_call"] |
268 | 227 |
|
|
0 commit comments