Skip to content

[PROF-14883] Publish thread context attribute keys at process start#576

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 8 commits into
mainfrom
ivoanjo/prof-14883-early-thread-context
Jun 12, 2026
Merged

[PROF-14883] Publish thread context attribute keys at process start#576
gh-worker-dd-mergequeue-cf854d[bot] merged 8 commits into
mainfrom
ivoanjo/prof-14883-early-thread-context

Conversation

@ivoanjo

@ivoanjo ivoanjo commented Jun 4, 2026

Copy link
Copy Markdown
Member

What does this PR do?

This PR unifies the registerAttributeKeys mechanism used for supporting the "OTel thread context" with setProcessContext so that they get both published together at process start.

Motivation:

Beyond the code simplification (most of this PR is deletes), the big advantage of this approach is that registerAttributeKeys happened at profiler start, and now this is all moved to process start.

This was meh because profiler start is by default delayed (afaik up to 70 seconds in practice) which means that the "thread context" information would be missing for the same period of time, which was super confusing, and would mean an outside reader would be missing this data for that period.

Additional Notes:

This PR will pair with one on the dd-trace-java side to provide the needed info when setting the process context.

How to test the change?

This change includes test coverage + on the dd-trace-java coverage we'll add a few tests too.

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-14883

@ivoanjo ivoanjo requested a review from a team as a code owner June 4, 2026 11:56

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5c28a04d41

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread ddprof-lib/src/main/java/com/datadoghq/profiler/OTelContext.java Outdated
Comment thread ddprof-lib/src/main/cpp/profiler.cpp
@dd-octo-sts

dd-octo-sts Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

CI Test Results

Run: #27430935426 | Commit: cbceb7a | Duration: 12m 54s (longest job)

All 32 test jobs passed

Status Overview

JDK glibc-aarch64/debug glibc-amd64/debug musl-aarch64/debug musl-amd64/debug
8 - - -
8-ibm - - -
8-j9 - -
8-librca - -
8-orcl - - -
11 - - -
11-j9 - -
11-librca - -
17 - -
17-graal - -
17-j9 - -
17-librca - -
21 - -
21-graal - -
21-librca - -
25 - -
25-graal - -
25-librca - -

Legend: ✅ passed | ❌ failed | ⚪ skipped | 🚫 cancelled

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


Updated: 2026-06-12 17:27:01 UTC

@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.

Sphinx automated review — PR #576 · ivoanjo/prof-14883-early-thread-context

Comment thread ddprof-lib/src/main/cpp/profiler.cpp
@@ -93,91 +92,24 @@ public void testNativeReadBackFunctionality() {
String tracerVersion = "3.5.0";

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.

🟡 MEDIUM · completeness [SPECIALIST]

testStartAttributesAutoRegistersKeys — the only test asserting that start,attributes=... auto-publishes the OTEP attribute_key_map without a separate setProcessContext call — is deleted with no replacement. The behaviour change in profiler.cpp is now untested; a regression would go undetected by the surviving test suite.

Suggestion: Add a test asserting the intended new behaviour of the attributes=... start path — either explicitly verifying the key map is absent (if the two-step contract is now required), or providing an equivalent end-to-end test that covers the same scenario.

Matched lens: Tests missing or dropped for new code.

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.

I don't agree with the AI -- it's suggesting a negative test (Y doesn't happen when X) and I don't see the value of such a negative tests. (E.g. I also don't assert that "free nachos every friday" doesn't happen when X happens -- negative tests are weird)

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.

This is related to #576 (comment) - if the context attributes are no longer autpublished and one needs to call setProcessContext to actually publish them, then the test, as described here, is not needed.

But - since setProcessContext is now setting the OTEL process context as well as making sure the custom attribute names are actually published, I wonder if it should not be renamed to something better reflecting the span of operations it does.

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.

Hmmm, that's a good point. Perhaps setProcessAndThreadContext? Any suggestions?

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.

Maybe initializeAllContext() and add a small javadoc mention of the custom attributes setup being done as part of this? Also, that one has to call this method to make sure the custom attributes are setup properly.

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.

Renamed and added big comment in 79cc3cc; also updated the downstream DataDog/dd-trace-java#11558 to match.

Comment thread ddprof-lib/src/main/java/com/datadoghq/profiler/OTelContext.java
Comment thread ddprof-lib/src/main/cpp/javaApi.cpp
Comment thread ddprof-lib/src/main/cpp/javaApi.cpp
Comment thread ddprof-lib/src/main/cpp/javaApi.cpp
Comment thread ddprof-test/src/test/java/com/datadoghq/profiler/context/ProcessContextTest.java Outdated
Comment thread ddprof-test/src/test/java/com/datadoghq/profiler/context/ProcessContextTest.java Outdated
@datadog-prod-us1-6

datadog-prod-us1-6 Bot commented Jun 8, 2026

Copy link
Copy Markdown

Pipelines

Fix all issues with BitsAI

⚠️ Warnings

🚦 40 Pipeline jobs failed

DataDog/java-profiler | integration-test-arm64-glibc: [hotspot, 11]   View in Datadog   GitLab

DataDog/java-profiler | integration-test-arm64-musl: [openj9, 17]   View in Datadog   GitLab

DataDog/java-profiler | integration-test-x64-glibc: [hotspot, 8]   View in Datadog   GitLab

View all 40 failed jobs.

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 75be380 | Docs | Datadog PR Page | Give us feedback!

ivoanjo added a commit to DataDog/dd-trace-java that referenced this pull request Jun 12, 2026
@ivoanjo

ivoanjo commented Jun 12, 2026

Copy link
Copy Markdown
Member Author

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Jun 12, 2026

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-06-12 14:43:29 UTC ℹ️ Start processing command /merge


2026-06-12 14:43:38 UTC ℹ️ MergeQueue: waiting for PR to be ready

This pull request is not mergeable according to GitHub. Common reasons include pending required checks, missing approvals, or merge conflicts — but it could also be blocked by other repository rules or settings.
It will be added to the queue as soon as checks pass and/or get approvals. View in MergeQueue UI.
Note: if you pushed new commits since the last approval, you may need additional approval.
You can remove it from the waiting list with /remove command.


2026-06-12 16:42:06 UTC ℹ️ MergeQueue: merge request added to the queue

The expected merge time in main is approximately 33m (p90).


2026-06-12 17:09:07 UTC ℹ️ MergeQueue: This merge request was merged

ivoanjo added 8 commits June 12, 2026 17:40
**What does this PR do?**

This PR unifies the `registerAttributeKeys` mechanism used for
supporting the "OTel thread context" with `setProcessContext` so that
they get both published together at process start.

**Motivation:**

Beyond the code simplification (most of this PR is deletes), the big
advantage of this approach is that `registerAttributeKeys` happened at
profiler start, and now this is all moved to process start.

This was meh because profiler start is by default delayed (afaik up to
70 seconds in practice) which means that the "thread context"
information would be missing for the same period of time, which was
super confusing, and would mean an outside reader would be missing this
data for that period.

**Additional Notes:**

This PR will pair with one on the dd-trace-java side to provide the
needed info when setting the process context.

**How to test the change?**

This change includes test coverage + on the dd-trace-java coverage
we'll add a few tests too.
@ivoanjo ivoanjo force-pushed the ivoanjo/prof-14883-early-thread-context branch from 5df97f0 to 75be380 Compare June 12, 2026 16:40
@ivoanjo

ivoanjo commented Jun 12, 2026

Copy link
Copy Markdown
Member Author

I did a trivial rebase on top of main + force push; to get over the "commits were not signed" above (I had authored this in a workspace, need to check what's up there with missing signatures)

@gh-worker-dd-mergequeue-cf854d gh-worker-dd-mergequeue-cf854d Bot merged commit cbceb7a into main Jun 12, 2026
111 of 113 checks passed
@gh-worker-dd-mergequeue-cf854d gh-worker-dd-mergequeue-cf854d Bot deleted the ivoanjo/prof-14883-early-thread-context branch June 12, 2026 17:09
@github-actions github-actions Bot added this to the 1.45.0 milestone Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants