Skip to content

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

Open
ivoanjo wants to merge 7 commits into
mainfrom
ivoanjo/prof-14883-early-thread-context
Open

[PROF-14883] Publish thread context attribute keys at process start#576
ivoanjo wants to merge 7 commits into
mainfrom
ivoanjo/prof-14883-early-thread-context

Conversation

@ivoanjo
Copy link
Copy Markdown
Member

@ivoanjo ivoanjo commented Jun 4, 2026

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

**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 requested a review from a team as a code owner June 4, 2026 11:56
Copy link
Copy Markdown

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

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
Comment thread ddprof-lib/src/main/cpp/profiler.cpp
@dd-octo-sts
Copy link
Copy Markdown
Contributor

dd-octo-sts Bot commented Jun 4, 2026

CI Test Results

Run: #27134891685 | Commit: a74e5f3 | Duration: 12m 13s (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-08 12:05:17 UTC

Copy link
Copy Markdown
Collaborator

@jbachorik jbachorik left a comment

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.

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
@datadog-prod-us1-6
Copy link
Copy Markdown

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

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-glibc: [hotspot, 17]   View in Datadog   GitLab

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

View all 40 failed jobs.

Useful? React with 👍 / 👎

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants