opentelemetry-process-context: implement process context publishing (OTEP-4719)#5337
opentelemetry-process-context: implement process context publishing (OTEP-4719)#5337herin049 wants to merge 31 commits into
Conversation
|
Key components of this PR are written in Rust, reviewers of this repo may not be experts in this language. I suggest adding comments to all the rust files for ease of understanding: publish.rs.txt |
ocelotl
left a comment
There was a problem hiding this comment.
I found a few things that may be required in the OTEP but missing here. If so, they are all very small changes to this PR.
A few other things are minor but also worth of considering.
ocelotl
left a comment
There was a problem hiding this comment.
Some more automatic review comments ✌️
Co-authored-by: Diego Hurtado <ocelotl@users.noreply.github.com>
|
@ocelotl I've switched from pulling the proto files in the Also, I've combined |
ocelotl
left a comment
There was a problem hiding this comment.
Looks good!
Just a question
There was a problem hiding this comment.
Pull request overview
This PR adds a new opentelemetry-process-context package to the OpenTelemetry Python monorepo. The package is a Rust-backed (PyO3/maturin) Python extension that publishes the SDK Resource into a discoverable process memory region for out-of-process readers, following the mechanism described in OTEP-4719.
Changes:
- Introduces the
opentelemetry-process-contextpackage (Python API + Rust implementation + tests). - Adds CI coverage (tox envs + GitHub Actions) and release workflow steps to build/upload native wheels and sdist.
- Adds a maintainer script to regenerate the embedded Rust
prostcode for the process-context protobufs.
Reviewed changes
Copilot reviewed 23 out of 30 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| uv.lock | Adds the new workspace member and editable dependency entry. |
| tox.ini | Adds test/lint envs for the new package and constrains tests to Linux. |
| scripts/proto_codegen_process_context.sh | New script to regenerate Rust prost code from upstream protos. |
| pyproject.toml | Adds the new package to the workspace dependencies/members and tool config. |
| opentelemetry-process-context/tests/test_process_context.py | Adds lifecycle + cross-process /proc validation tests. |
| opentelemetry-process-context/tests/init.py | Test package marker. |
| opentelemetry-process-context/test-requirements.in | Adds test dependency input for uv compilation. |
| opentelemetry-process-context/test-requirements.txt | Compiled test dependency lock for the package tests. |
| opentelemetry-process-context/src/opentelemetry/process_context/init.py | Public API re-export of the extension functions. |
| opentelemetry-process-context/src/opentelemetry/process_context/version.py | Package version constant. |
| opentelemetry-process-context/src/opentelemetry/process_context/py.typed | Marks the package as typed. |
| opentelemetry-process-context/src/opentelemetry/process_context/_rs/init.pyi | Type stubs for the Rust extension module. |
| opentelemetry-process-context/rust/src/lib.rs | PyO3 module entrypoint exposing publish/unpublish. |
| opentelemetry-process-context/rust/src/context.rs | Core shared-memory publication logic. |
| opentelemetry-process-context/rust/src/convert.rs | Converts Python Resource attributes into protobuf AnyValue/Resource. |
| opentelemetry-process-context/rust/src/proto.rs | Rust module wiring for checked-in generated prost code. |
| opentelemetry-process-context/rust/src/generated/opentelemetry.proto.common.v1.rs | Generated protobuf types used for encoding attributes. |
| opentelemetry-process-context/rust/src/generated/opentelemetry.proto.resource.v1.rs | Generated protobuf types for Resource. |
| opentelemetry-process-context/rust/src/generated/opentelemetry.proto.processcontext.v1development.rs | Generated protobuf types for ProcessContext. |
| opentelemetry-process-context/rust/Cargo.toml | Rust crate configuration for the extension. |
| opentelemetry-process-context/rust/Cargo.lock | Rust dependency lockfile for reproducible builds. |
| opentelemetry-process-context/pyproject.toml | Defines the Python package (maturin backend) and build metadata. |
| opentelemetry-process-context/README.rst | Package README scaffold. |
| opentelemetry-process-context/LICENSE | Package license file. |
| .github/workflows/test.yml | Adds Ubuntu test jobs for the new tox envs. |
| .github/workflows/lint.yml | Adds lint job for the new package. |
| .github/workflows/release.yml | Adds wheel/sdist build jobs for the native extension and downloads artifacts into dist/. |
| .github/workflows/generate_workflows.py | Updates workflow generator to respect tox platform constraints. |
| .codespellrc | Skips Rust target artifacts and ignores “crate”. |
| .changelog/5337.added | Adds changelog entry for the new feature/package. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Description
External profilers and observability tools (such as the OpenTelemetry eBPF Profiler) operate outside the instrumented process and have no access to resource attributes configured inside OpenTelemetry SDKs. OTEP-4719 (Process Context Sharing) introduces a standard mechanism for OpenTelemetry SDKs to publish resource attributes for access by out-of-process readers
This PR introduces the
opentelemetry-process-contextpackage as a Rust backed Python extension (built with maturin/pyo3) that implements the process outlined in OTEP-4719. It publishes the SDK's resource attributes toa memory region that any external reader with access to
/proc/<pid>/mapsand/proc/<pid>/memcan discover.Python API
The introduced Python API has a very light surface area, consisting of two methods to publish and unpublish the process context.
Compatability
The original OTEP explicitly mentions that this functionality is Linux only. However, I have tried to implement this package in such a way that limited testing/development can be performed natively on any Posix compatible system (e.g. MacOS). However, the full functionality of OTEP-4719 is only available on Linux and Windows is explicitly not supported.
memfd_create("OTEL_CTX")->mmap(MAP_PRIVATE)mmap/proc/<pid>/mapsshowsmemfd:OTEL_CTX/proc)madvise(MADV_DONTFORK)prctl(PR_SET_VMA_ANON_NAME, "OTEL_CTX")CLOCK_BOOTTIMECLOCK_MONOTONICFixes #5291
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Does This PR Require a Contrib Repo Change?
Checklist: