Commit d5a8cec
Fix TracerProvider() crash on out-of-range OTEL_TRACES_SAMPLER_ARG (#5594)
* Fix TracerProvider() crash on out-of-range OTEL_TRACES_SAMPLER_ARG
_get_from_env_or_default() already caught ValueError/TypeError from
float(OTEL_TRACES_SAMPLER_ARG) to gracefully fall back to rate=1.0 with
a warning when the value is non-numeric. But TraceIdRatioBased.__init__
raises its own ValueError when the parsed rate is syntactically valid
yet outside [0.0, 1.0], and that exception was not covered by the same
guard, so TracerProvider() construction crashed instead of degrading
gracefully.
Per the SDK configuration spec, invalid OTEL_TRACES_SAMPLER_ARG values
MUST be logged and otherwise ignored, behaving as if the variable were
not set. An out-of-range numeric value is just as invalid as a
non-numeric one and should be handled the same way.
Moves the sampler construction inside the try block so both failure
modes share the existing fallback path.
* Rename 0.fixed to 5594.fixed
* Expand fallback warning to mention the rate that will be used
Per review feedback from @ocelotl: mention the fallback rate (1.0) in
the warning message so it's clear what value the sampler actually ends
up using when OTEL_TRACES_SAMPLER_ARG is invalid.
---------
Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>1 parent 8b5ae99 commit d5a8cec
3 files changed
Lines changed: 67 additions & 3 deletions
File tree
- .changelog
- opentelemetry-sdk
- src/opentelemetry/sdk/trace
- tests/trace
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
471 | 471 | | |
472 | 472 | | |
473 | 473 | | |
| 474 | + | |
474 | 475 | | |
475 | | - | |
476 | | - | |
477 | | - | |
| 476 | + | |
| 477 | + | |
478 | 478 | | |
479 | 479 | | |
480 | 480 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| 54 | + | |
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
| |||
353 | 354 | | |
354 | 355 | | |
355 | 356 | | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
356 | 419 | | |
357 | 420 | | |
358 | 421 | | |
| |||
0 commit comments