Repository navigation
Commit 59dcbfb
fix(telemetry): let trace_function alone decide a span's status (#1309)
# Description
`trace_function` opened its span with `start_as_current_span`'s defaults
(`record_exception=True`, `set_status_on_exception=True`). OTel's
`use_span` therefore recorded any `Exception` leaving the block and
marked the span `ERROR`, on top of what the wrapper had already done:
- `QueueShutDown` still ended as `ERROR` on every queue teardown, even
though #1075 treats it as a non-error. In practice that is one `ERROR`
`EventQueueSource.dequeue_event` span per streaming request.
- Every exception was recorded twice on the span, and OTel's `Type:
message` description replaced the wrapper's `str(e)`.
## Change
- `src/a2a/utils/telemetry.py`: pass `record_exception=False,
set_status_on_exception=False` to `start_as_current_span` in both the
async and the sync wrapper. The wrapper already records the exception
and sets the status itself.
- `tests/utils/test_telemetry.py`: add
`test_span_status_with_real_otel_sdk`. It goes through a real
`TracerProvider` + `InMemorySpanExporter`, because the existing mocked
tracer can't see what OTel does on exit. It is parametrized over:
- `QueueShutDown`, expected not `ERROR`;
- `ValueError`, expected `ERROR`.
Both cases check that the span has exactly one `exception` event. Both
fail on `main` and pass with this change.
## Before / after
The reproduction script from #1308 (a2a-sdk `main` at 6ff0a82,
opentelemetry-sdk 1.42.1):
```
# before
shutdown ERROR 'AsyncQueueShutDown: ' ['exception', 'exception']
boom ERROR 'ValueError: real failure' ['exception', 'exception']
# after
shutdown UNSET None ['exception']
boom ERROR 'real failure' ['exception']
```
## Checks
- `./scripts/lint.sh`: ruff check, ruff format and ty all pass.
- `uv run pytest --cov=src`: 2206 passed, 93 % coverage.
- **Pre-existing failure:**
`tests/integration/cross_version/client_server/test_client_server.py`
fails locally on `main` too, without this change (the 0.3 server/client
subprocess doesn't start on my machine). This PR doesn't touch it.
- [x] Follow the [`CONTRIBUTING`
Guide](https://github.com/a2aproject/a2a-python/blob/main/CONTRIBUTING.md).
- [x] Make your Pull Request title in the
<https://www.conventionalcommits.org/> specification.
- [x] Ensure the tests and linter pass (Run `bash scripts/format.sh`
from the repository root to format)
- [x] Appropriate docs were updated (if necessary)
Fixes #1308 🦕
Co-authored-by: Atenea Agent @svc_atenea_gitlab
Co-authored-by: mykytanetipa <mykytanetipa@google.com>1 parent 486f0f6 commit 59dcbfb
2 files changed
Lines changed: 59 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
229 | 229 | | |
230 | 230 | | |
231 | 231 | | |
232 | | - | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
233 | 241 | | |
234 | 242 | | |
235 | 243 | | |
| |||
272 | 280 | | |
273 | 281 | | |
274 | 282 | | |
275 | | - | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
276 | 291 | | |
277 | 292 | | |
278 | 293 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
294 | 294 | | |
295 | 295 | | |
296 | 296 | | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
0 commit comments