Skip to content

[PROF-12646] Update OTel process context support with latest version of reference library - #414

Merged
ivoanjo merged 9 commits into
mainfrom
ivoanjo/update-process-context
Mar 19, 2026
Merged

ivoanjo merged 9 commits into
mainfrom
ivoanjo/update-process-context

Conversation

@ivoanjo

@ivoanjo ivoanjo commented Mar 11, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

This PR updates the vendored version of the OTel process context support with the latest code from
open-telemetry/sig-profiling#79 (which will soon be merged upstream).

Motivation:

This latest version of the library fixes a number of small issues, but more importantly includes support for the thread context configuration keys which we need for #347 (so we will be able to shed a bunch of code once we rebase on top of this one).

Additional Notes:

From the Java API consumer side, not a lot changes with this version.

How to test the change?

Validate tests still pass!

For Datadog employees:

  • If this PR touches code that signs or publishes builds or packages, or handles
    credentials of any kind, I've requested a review from @DataDog/security-design-and-guidance.
  • This PR doesn't touch any of that.
  • JIRA: PROF-12646

…of reference library

**What does this PR do?**

This PR updates the vendored version of the OTel process context
support with the latest code from
open-telemetry/sig-profiling#79 (which will soon
be merged upstream).

**Motivation:**

This latest version of the library fixes a number of small issues, but
more importantly includes support for the thread context configuration
keys which we need for #347
(so we will be able to shed a bunch of code once we rebase on top of
this one).

**Additional Notes:**

From the Java API consumer side, not a lot changes with this version.

**How to test the change?**

Validate tests still pass!
@ivoanjo
ivoanjo requested a review from a team as a code owner March 11, 2026 16:20

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes from this file are a bit big but all comes from upstream -- same sha1sum as the PR I linked in the description :)

@dd-octo-sts

dd-octo-sts Bot commented Mar 11, 2026 •

Copy link
Copy Markdown
Contributor

Scan-Build Report

User:runner@runnervm0kj6c
Working Directory:/home/runner/work/java-profiler/java-profiler/ddprof-lib/src/test/make
Command Line:make -j4 all
Clang Version:Ubuntu clang version 18.1.3 (1ubuntu1)
Date:Wed Mar 11 17:51:58 2026

Bug Summary

Bug TypeQuantityDisplay?
All Bugs1
Memory error
Memory leak1

Reports

Bug Group Bug Type ▾ File Function/Method Line Path Length
Memory errorMemory leakotel_process_ctx.cppotel_process_ctx_decode_payload69343

@dd-octo-sts

dd-octo-sts Bot commented Mar 11, 2026 •

Copy link
Copy Markdown
Contributor

CI Test Results

Run: #34248580020 | Commit: 715b5db | Duration: 0s (longest job)

✅ All 0 test jobs passed

Summary: Total: 0 | Passed: 0 | Failed: 0


Updated: 2026-09-08 16:14:14 UTC

@ivoanjo

ivoanjo commented Mar 11, 2026

Copy link
Copy Markdown
Member Author
Execution failed for task ':ddprof-lib:compileDebug'.
> Failed to compile otel_process_ctx.cpp: exit code 1
  /home/runner/work/java-profiler/java-profiler/ddprof-lib/src/main/cpp/otel_process_ctx.cpp:148:71: error: use of undeclared identifier 'MFD_NOEXEC_SEAL'
    int fd = memfd_create("OTEL_CTX", MFD_CLOEXEC | MFD_ALLOW_SEALING | MFD_NOEXEC_SEAL);

Ooops I guess too old libc; I'll add a fallback #define for it.

ivoanjo added 4 commits March 11, 2026 17:28
I'll make sure to propagate this to the upstream version as well, so
we don't need to keep maintaining this separately.
TL;DR if there were repeated keys when parsing the data in the testing
code we could leak their values.

This matches the latest version upstream in
open-telemetry/sig-profiling#79 .

@jbachorik jbachorik left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a few nits and some comments where I am looking for clarification before approving.

Comment thread ddprof-lib/src/main/cpp/javaApi.cpp Resolved
ivoanjo added 4 commits March 18, 2026 14:55
In practice I'm not sure `ftruncate` could fail unless the kernel is
already on fire but no reason not to fix the leak anyway.
We were accidentally importing at least one Linux-specific header,
which made NOOP not work.

To make sure NOOP keeps working, let's move everything it doesn't need
inside the ifdef -- this way it'll be very obvious what's being compiled
for NOOP and what's not.
@ivoanjo
ivoanjo merged commit 715b5db into main Mar 19, 2026
82 checks passed
@ivoanjo
ivoanjo deleted the ivoanjo/update-process-context branch March 19, 2026 10:04
@github-actions github-actions Bot added this to the 1.40.0 milestone Mar 19, 2026
felixge pushed a commit to open-telemetry/sig-profiling that referenced this pull request Mar 31, 2026
…#88)

**What does this PR do?**

This PR collects a few more improvements to the process context C/C++
impl:

* Add a few more size checks that were missing to make sure we stay
within the limits of the embedded protobuf encoder
* Fix for leaking the memfd file descriptor in a weird corner case
* Make sure the no-op implementation does not need any Linux-specific
headers

**Motivation:**

These came up as we were adding process context support to Datadog's
dd-trace-java profiler in
DataDog/java-profiler#414 .

**Additional Notes:**

I've considered if the encoder should follow the design of the decoder
and always check the position of the pointer... It'd be a bigger change
so I hesitated in going for it.

**How to test the change?**

The no-op implementation build validates the minimal set of headers is
correct; for the other changes the build still passes and the example
script works fine.
@zhengyu123 zhengyu123 added the fixed_version: v_1.40.0 Version this PR's fix shipped in label Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fixed_version: v_1.40.0 Version this PR's fix shipped in

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants