Commit 44d8911
fix(sdk): use sys.orig_argv for process.command to handle python -m invocations (#5083)
* fix(sdk): use sys.orig_argv for process.command to handle python -m invocations
ProcessResourceDetector populated process.command, process.command_line,
and process.command_args from sys.argv. For applications launched via
`python -m <module>`, the interpreter rewrites sys.argv[0] to the
resolved module path, so the ``-m <module>`` portion of the original
invocation is lost and the detector emits misleading telemetry.
Python 3.10+ exposes sys.orig_argv which preserves the original
arguments received by the interpreter. Since the SDK already requires
Python >= 3.10, switch to sys.orig_argv (with a getattr fallback for
safety). This also aligns with the OTel semantic conventions that
reference /proc/<pid>/cmdline for these attributes.
Fixes #4518
Signed-off-by: Ali <alliasgher123@gmail.com>
* nit: drop sys.orig_argv fallback and use PR number in changelog
Two review nits from MikeGoldsmith:
- sys.orig_argv has been available since Python 3.10; the SDK now
requires 3.10+ so the getattr fallback is dead code. Use sys.orig_argv
directly and update the comment.
- CHANGELOG entries should reference the PR number, not the issue
number.
Signed-off-by: Ali <alliasgher123@gmail.com>
* test: remove redundant sys.argv patch from test_process_detector
Signed-off-by: Ali <alliasgher123@gmail.com>
* test: drop superfluous sys.argv mock in python-m test
The detector reads only sys.orig_argv, so patching sys.argv had no
effect on the test's outcome. Keep only the sys.orig_argv patch.
Signed-off-by: Ali <alliasgher123@gmail.com>
---------
Signed-off-by: Ali <alliasgher123@gmail.com>
Co-authored-by: Mike Goldsmith <goldsmith.mike@gmail.com>
Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>1 parent 849cfac commit 44d8911
3 files changed
Lines changed: 40 additions & 7 deletions
File tree
- opentelemetry-sdk
- src/opentelemetry/sdk/resources
- tests/resources
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
| 32 | + | |
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
| |||
Lines changed: 10 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
385 | 385 | | |
386 | 386 | | |
387 | 387 | | |
388 | | - | |
389 | | - | |
390 | | - | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
391 | 398 | | |
392 | 399 | | |
393 | 400 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
574 | 574 | | |
575 | 575 | | |
576 | 576 | | |
577 | | - | |
| 577 | + | |
578 | 578 | | |
579 | 579 | | |
580 | 580 | | |
| |||
620 | 620 | | |
621 | 621 | | |
622 | 622 | | |
623 | | - | |
| 623 | + | |
624 | 624 | | |
625 | 625 | | |
626 | 626 | | |
627 | | - | |
| 627 | + | |
628 | 628 | | |
629 | 629 | | |
630 | 630 | | |
631 | | - | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
632 | 656 | | |
633 | 657 | | |
634 | 658 | | |
| |||
0 commit comments