Commit e103926
authored
feat: Make ASGI support span first (#5680)
This PR makes the ASGI integration work both in legacy and span
streaming mode. Some features and attributes will be missing in span
streaming mode for now (see the Out of scope section below).
Best reviewed with whitespace ignored:
https://github.com/getsentry/sentry-python/pull/5680/changes?w=1
---
A bit of a background on migrating integrations to span first. In order
to support both legacy spans and span streaming, most integrations will
follow the same patterns:
### API
We need to use the `start_span` API from `sentry_sdk.traces` if we're in
span streaming mode (`traces_lifecycle="stream"`).
There are no transactions anymore. Top-level spans will also be started
via the `start_span` API in span streaming mode.
### Setting data on spans
If an integration sets data on a span (via `span.set_data`,
`span.set_tag` etc.), it should use `span.set_attribute` when span
streaming is enabled.
The attributes that we set need to be in Sentry conventions. This is
deliberately not the case for most quick ports of integrations like this
one and will follow in [a future
step](#5152).
### Trace propagation
If an integration sits at a service boundary and is capable of
propagating incoming trace information (like WSGI/ASGI or Celery), in
span first mode we need to switch from the old style `with
continue_trace(...) as transaction:` to the [new style
`continue_trace()` and
`new_trace()`](https://sentry-docs-git-ivana-span-first-migration-guide.sentry.dev/platforms/python/migration/span-first/#trace-propagation)
(not context managers).
### `start_span` arguments
You can pass things like `op`, `origin`, `source` to the old
`start_span` API. With the new API, this is no longer possible, and the
individual properties need to be set as attributes directly.
### Out of scope
For now, the following is out of scope and will follow in the future:
- Making sure all attributes are correct and that they're set in Sentry
conventions: #5152
- Migrating event processors (as streaming spans are not events, event
processors are not run on them, meaning some data will not be set yet):
#51521 parent dc65e13 commit e103926
1 file changed
+92
-27
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
| 28 | + | |
27 | 29 | | |
28 | 30 | | |
| 31 | + | |
29 | 32 | | |
30 | 33 | | |
31 | 34 | | |
| |||
35 | 38 | | |
36 | 39 | | |
37 | 40 | | |
38 | | - | |
39 | 41 | | |
40 | 42 | | |
41 | 43 | | |
42 | 44 | | |
43 | 45 | | |
| 46 | + | |
44 | 47 | | |
45 | 48 | | |
46 | 49 | | |
| 50 | + | |
47 | 51 | | |
48 | | - | |
| 52 | + | |
| 53 | + | |
49 | 54 | | |
50 | 55 | | |
51 | 56 | | |
| |||
185 | 190 | | |
186 | 191 | | |
187 | 192 | | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
188 | 196 | | |
189 | 197 | | |
190 | 198 | | |
| |||
204 | 212 | | |
205 | 213 | | |
206 | 214 | | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
213 | 273 | | |
214 | 274 | | |
215 | 275 | | |
216 | 276 | | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | 277 | | |
225 | | - | |
226 | | - | |
| 278 | + | |
| 279 | + | |
227 | 280 | | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
232 | 288 | | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
| 289 | + | |
| 290 | + | |
237 | 291 | | |
238 | 292 | | |
239 | 293 | | |
240 | 294 | | |
241 | 295 | | |
242 | | - | |
| 296 | + | |
243 | 297 | | |
244 | 298 | | |
245 | 299 | | |
246 | 300 | | |
247 | 301 | | |
248 | | - | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
249 | 314 | | |
250 | 315 | | |
251 | 316 | | |
| |||
0 commit comments