Skip to content

Restore app context attributes wiped by ddprof setContext on span activation - #11646

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 1 commit into
masterfrom
jb/flaky_profile_tests
Jul 1, 2026
Merged

Restore app context attributes wiped by ddprof setContext on span activation#11646
gh-worker-dd-mergequeue-cf854d[bot] merged 1 commit into
masterfrom
jb/flaky_profile_tests

Conversation

@jbachorik

@jbachorik jbachorik commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

What Does This Do

Preserves application-managed ddprof context attributes across span activation/deactivation, and restores them via a zero-allocation path using the new setContextValuesByIdAndBytes API (ddprof 1.45.0).

ddprof's setContext wipes all custom attribute slots when a span is activated. This change:

  • Snapshots each app-managed attribute per-thread in an AppContextSnapshot (constant ID + pre-encoded UTF-8 bytes) whenever setContextValue/clearContextValue is called
  • Skips re-encoding and re-snapshotting when the same value is set again on the same thread (common steady-state: same operation name across consecutive spans)
  • Re-applies both the DD sidecar encoding and the OTEP attrs_data value via a single setContextValuesByIdAndBytes call after every setSpanContext — no String allocation, no hash lookup, no OTEP sidecar gap
  • Releases the ThreadLocal when all slots are cleared (avoiding memory leak on pooled threads)
  • Sizes snapshot arrays to ContextSetter's actual internal size (deduplicated, max 10) rather than the raw attribute list size
  • Restores the pre-scope snapshot on DatadogProfilingScope.close() so ambient app context set before a scope is not lost when the scope exits (nested scope fix)

Allocation-free scope save/restore

DatadogProfilingScope needs to save the current app context snapshot on open and restore it on close. Since the tracer is GC-sensitive and app context is expected to be the common case, this uses a per-thread ScopeStack of pre-allocated slots (8 slots by default, grows on deeper nesting) rather than allocating a snapshot copy on each scope open.

JMH results with -prof gc confirm the pool path is allocation-free in steady state, including after the pool resizes beyond its initial 8-slot capacity:

Benchmark                    (attrCount)  (stackDepth)  Mode  Cnt    Score  gc.alloc.rate.norm
save                                   2             8  avgt    5    7.9 ns    ≈ 10⁻⁴ B/op
save                                   8             8  avgt    5    8.5 ns    ≈ 10⁻⁴ B/op
restore                                2             8  avgt    5    7.9 ns    ≈ 10⁻⁴ B/op
restore                                8             8  avgt    5    8.4 ns    ≈ 10⁻⁴ B/op
deepStack (8 slots, no resize)         2             8  avgt    5   78.2 ns    0.001 B/op
deepStack (16 slots, post-resize)      2            16  avgt    5  150.6 ns    0.001 B/op
deepStack (8 slots, no resize)         8             8  avgt    5   78.1 ns    0.001 B/op
deepStack (16 slots, post-resize)      8            16  avgt    5  151.5 ns    0.001 B/op

The deepStack benchmark borrows N slots then releases them all per iteration. At stackDepth=16 the pool resizes once during JMH warmup; the measurement phase shows the resize is never triggered again — allocation stays at noise level. The ~72 ns increase from depth 8 to 16 is proportional to the extra copyFrom calls (2× the work), not GC pressure.

For reference, a naive per-scope-open snapshot allocation would cost 128 B/op (2 attributes) to 224 B/op (8 attributes) at ~8–10 GB/sec allocation rate — object header + 3 array allocations.

Motivation

Application-set profiling context attributes (e.g. custom tags set via ProfilingContextAttribute.set()) were silently dropped on every span activation. This caused flaky profiling tests and incorrect/missing context in profiles when both span context and app context were in use simultaneously.

Additional Notes

  • Requires ddprof 1.45.0 (setContextValuesByIdAndBytes on ContextSetter / ThreadContext) — tracked in PROF-15098
  • [PROF-15181] tracks a follow-up cleanup in the java-profiler library

Contributor Checklist

  • Format the title according to the contribution guidelines
  • Assign the type: and (comp: or inst:) labels in addition to any other useful labels
  • Avoid using close, fix, or any linking keywords when referencing an issue
    Use solves instead, and assign the PR milestone to the issue
  • Update the CODEOWNERS file on source file addition, migration, or deletion
  • Update public documentation with any new configuration flags or behaviors
  • Add your completed PR to the merge queue by commenting /merge. You can also:
    • Customize the commit message associated with the merge with /merge --commit-message "..."
    • Remove your PR from the merge queue with /merge -c
    • Skip all merge queue checks with /merge -f --reason "reason"; please use this judiciously, as some checks do not run at the PR-level (note: the PR still needs to be mergeable, this will only skip the pre-merge build)
    • Get more information in this doc

Jira ticket: PROF-15096

@jbachorik jbachorik added type: bug fix Bug fix tag: no release notes Changes to exclude from release notes comp: profiling Profiling tag: ai generated Largely based on code generated by an AI or LLM labels Jun 15, 2026
@datadog-prod-us1-4

datadog-prod-us1-4 Bot commented Jun 15, 2026

Copy link
Copy Markdown

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 55.01% (-0.02%)

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

@dd-octo-sts

dd-octo-sts Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

🟢 Java Benchmark SLOs — All performance SLOs passed

Suite Status
Startup 🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Δ (95% CI of mean)
startup:insecure-bank:iast:Agent 14.80 s 14.68 s [-0.0%; +1.6%] (no difference)
startup:insecure-bank:tracing:Agent 13.66 s 13.64 s [-0.7%; +0.9%] (no difference)
startup:petclinic:appsec:Agent 16.95 s 16.74 s [+0.5%; +2.0%] (maybe worse)
startup:petclinic:iast:Agent 16.49 s 16.96 s [-7.2%; +1.6%] (no difference)
startup:petclinic:profiling:Agent 16.86 s 17.00 s [-1.9%; +0.3%] (no difference)
startup:petclinic:sca:Agent 17.02 s 16.85 s [+0.1%; +2.0%] (maybe worse)
startup:petclinic:tracing:Agent 16.04 s 16.15 s [-1.8%; +0.4%] (no difference)

Commit: fb48af68 · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

@jbachorik
jbachorik requested a review from Copilot June 19, 2026 06:51
@jbachorik

Copy link
Copy Markdown
Contributor Author

@codex review

Copilot AI 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.

Pull request overview

Preserves application-managed ddprof profiling context attributes across span activation/deactivation by snapshotting per-thread app-set values and reapplying them after setSpanContext, leveraging ddprof 1.45.0’s setContextValuesByIdAndBytes for a low-allocation restore path.

Changes:

  • Bump ddprof dependency to 1.45.0 to use the new bulk restore API.
  • Add per-thread app-context snapshotting in DatadogProfiler and reapply it via reapplyAppContext().
  • Invoke reapplyAppContext() on span activation and add unit tests for the reapply behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
gradle/libs.versions.toml Updates ddprof version to 1.45.0 to access the new API.
dd-java-agent/agent-profiling/profiling-ddprof/src/main/java/com/datadog/profiling/ddprof/DatadogProfiler.java Implements per-thread app attribute snapshot + reapply via setContextValuesByIdAndBytes.
dd-java-agent/agent-profiling/profiling-ddprof/src/main/java/com/datadog/profiling/ddprof/DatadogProfilingIntegration.java Calls reapplyAppContext() after span context activation.
dd-java-agent/agent-profiling/profiling-ddprof/src/test/java/com/datadog/profiling/ddprof/DatadogProfilerTest.java Adds tests to validate reapply behavior around span activation/reactivation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@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: db057e0734

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@jbachorik
jbachorik requested a review from Copilot June 19, 2026 08:02
@jbachorik

Copy link
Copy Markdown
Contributor Author

@codex review

Copilot AI 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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

@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: db057e0734

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copilot AI 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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

@jbachorik

Copy link
Copy Markdown
Contributor Author

@codex review

@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: f9da22457c

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@jbachorik
jbachorik marked this pull request as ready for review June 19, 2026 18:41
@jbachorik
jbachorik requested review from a team as code owners June 19, 2026 18:41

@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: b4c78957db

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@jbachorik

Copy link
Copy Markdown
Contributor Author

@codex review

@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: de7f6dac89

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@jbachorik

Copy link
Copy Markdown
Contributor Author

@codex review

@jbachorik jbachorik changed the title Fix app context attributes wiped by ddprof setContext on span activation Restore app context attributes wiped by ddprof setContext on span activation Jun 19, 2026

@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: bf09d5132f

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread gradle/libs.versions.toml
@jbachorik

Copy link
Copy Markdown
Contributor Author

@codex review

@jbachorik
jbachorik marked this pull request as draft June 19, 2026 19:27
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 5d2f3b2007

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@jbachorik
jbachorik marked this pull request as ready for review June 19, 2026 19:49

@rkennke rkennke left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good stuff! I found some issues that require attention.

@jbachorik jbachorik removed the tag: no release notes Changes to exclude from release notes label Jun 29, 2026

@rkennke rkennke left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-reviewed after the latest round. All prior review requests (mine, Copilot's, Codex's) are correctly addressed:

  • nonZeroCount inverse branch ✔, TL cleanup in clearAppContextSnapshot()
  • reapplyAppContext() folded into setSpanContext()/clearSpanContext()
  • cross-thread scopeStack null guard ✔
  • native-first ordering in setContextValue/clearContextValue
  • syncNativeAppContext() sequencing (reads from TL, not the reset slot) ✔
  • lockfile bumped to 1.45.0 ✔

The design is sound — native-first ordering, the id=0 slots being harmless since setContext already wiped everything, and the zero-alloc pooled save/restore (nice benchmark). I have a few non-blocking observations below; the only one I'd like resolved before merge is the LIFO assumption in ScopeStack (#1) — a doc comment is enough.

@rkennke rkennke left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me. Thank you!

@jbachorik

Copy link
Copy Markdown
Contributor Author

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Jul 1, 2026

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-07-01 07:27:27 UTC ℹ️ Start processing command /merge


2026-07-01 07:27:37 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-07-01 11:32:06 UTC ⚠️ MergeQueue: This merge request was unqueued

devflow unqueued this merge request: It did not become mergeable within the expected time

@jbachorik

Copy link
Copy Markdown
Contributor Author

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Jul 1, 2026

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-07-01 14:02:34 UTC ℹ️ Start processing command /merge


2026-07-01 14:02:40 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in master is approximately 2h (p90).


2026-07-01 15:09:36 UTC ℹ️ MergeQueue: This merge request was merged

@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit 602a81d into master Jul 1, 2026
587 of 593 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the jb/flaky_profile_tests branch July 1, 2026 15:09
@github-actions github-actions Bot added this to the 1.64.0 milestone Jul 1, 2026
rkennke added a commit that referenced this pull request Jul 23, 2026
Switch the profiler context bridge off the deprecated DirectByteBuffer (DBB)
context API onto java-profiler's all-native API (setTraceContext /
clearTraceContext / setContextValue / clearContextValue). This eliminates the
virtual-thread use-after-free (the DBB cached buffer that dangled on carrier
migration) and folds the per-activation sequence (setContext + two
setContextValue) into a single native call.

- DatadogProfilingIntegration.activate: one setTraceContext(...) carrying
  trace/span context + operation and resource attributes (3 JNI calls -> 1);
  close/clearContext: clearTraceContext() (wipes op/resource slots too).
- DatadogProfiler: setContextValue/clearContextValue/reapplyAppContext/
  syncNativeAppContext are now all-native. reapplyAppContext uses a per-slot
  native setContextValue loop (native setContextValue publishes valid=1, so app
  context stays visible without an active span — preserves PR #11646). A native
  batch reapply is deferred to a measured follow-up (java-profiler PROF-15361).
- AppContextSnapshot simplified to strings-only (the native path resolves each
  value's encoding via the process-wide cache; no cached id/utf8/snapshotTags).
- snapshot() uses the new native copyContextTags read (no ThreadContext/DBB, so
  it observes native writes without resetting the record).
- ContextSetter kept only for offsetOf + size (pure Java); no DBB usage remains.

Requires java-profiler with the all-native API (ddprof >= the phase-1 release;
DataDog/java-profiler#631). Build/test with -PddprofUseSnapshot=true against a
local publishToMavenLocal 1.47.0-SNAPSHOT until that ships. ddprof suite is
Linux-gated (assumeTrue(isLinux)) — verify on Linux/CI.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
rkennke added a commit that referenced this pull request Jul 24, 2026
Switch the profiler context bridge off the deprecated DirectByteBuffer (DBB)
context API onto java-profiler's all-native API (setTraceContext /
clearTraceContext / setContextValue / clearContextValue). This eliminates the
virtual-thread use-after-free (the DBB cached buffer that dangled on carrier
migration) and folds the per-activation sequence (setContext + two
setContextValue) into a single native call.

- DatadogProfilingIntegration.activate: one setTraceContext(...) carrying
  trace/span context + operation and resource attributes (3 JNI calls -> 1);
  close/clearContext: clearTraceContext() (wipes op/resource slots too).
- DatadogProfiler: setContextValue/clearContextValue/reapplyAppContext/
  syncNativeAppContext are now all-native. reapplyAppContext uses a per-slot
  native setContextValue loop (native setContextValue publishes valid=1, so app
  context stays visible without an active span — preserves PR #11646). A native
  batch reapply is deferred to a measured follow-up (java-profiler PROF-15361).
- AppContextSnapshot simplified to strings-only (the native path resolves each
  value's encoding via the process-wide cache; no cached id/utf8/snapshotTags).
- snapshot() uses the new native copyContextTags read (no ThreadContext/DBB, so
  it observes native writes without resetting the record).
- ContextSetter kept only for offsetOf + size (pure Java); no DBB usage remains.

Requires java-profiler with the all-native API (ddprof >= the phase-1 release;
DataDog/java-profiler#631). Build/test with -PddprofUseSnapshot=true against a
local publishToMavenLocal 1.47.0-SNAPSHOT until that ships. ddprof suite is
Linux-gated (assumeTrue(isLinux)) — verify on Linux/CI.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
gh-worker-dd-mergequeue-cf854d Bot pushed a commit that referenced this pull request Jul 28, 2026
…e 2) (#11899)

profiling(ddprof): migrate context bridge to the all-native API

Switch the profiler context bridge off the deprecated DirectByteBuffer (DBB)
context API onto java-profiler's all-native API (setTraceContext /
clearTraceContext / setContextValue / clearContextValue). This eliminates the
virtual-thread use-after-free (the DBB cached buffer that dangled on carrier
migration) and folds the per-activation sequence (setContext + two
setContextValue) into a single native call.

- DatadogProfilingIntegration.activate: one setTraceContext(...) carrying
  trace/span context + operation and resource attributes (3 JNI calls -> 1);
  close/clearContext: clearTraceContext() (wipes op/resource slots too).
- DatadogProfiler: setContextValue/clearContextValue/reapplyAppContext/
  syncNativeAppContext are now all-native. reapplyAppContext uses a per-slot
  native setContextValue loop (native setContextValue publishes valid=1, so app
  context stays visible without an active span — preserves PR #11646). A native
  batch reapply is deferred to a measured follow-up (java-profiler PROF-15361).
- AppContextSnapshot simplified to strings-only (the native path resolves each
  value's encoding via the process-wide cache; no cached id/utf8/snapshotTags).
- snapshot() uses the new native copyContextTags read (no ThreadContext/DBB, so
  it observes native writes without resetting the record).
- ContextSetter kept only for offsetOf + size (pure Java); no DBB usage remains.

Requires java-profiler with the all-native API (ddprof >= the phase-1 release;
DataDog/java-profiler#631). Build/test with -PddprofUseSnapshot=true against a
local publishToMavenLocal 1.47.0-SNAPSHOT until that ships. ddprof suite is
Linux-gated (assumeTrue(isLinux)) — verify on Linux/CI.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

profiling(ddprof): guard zero span in setTraceContext; document clearContextValue

The native setTraceContext rejects spanId==0 with IllegalArgumentException (it is
the activation path; clearing is clearTraceContext). The bridge's catch(Throwable)
would swallow that throw and leave the previous span's context stale on the thread.
Span ids are non-zero by construction (IdGenerationStrategy never yields 0,
DDSpanId.ZERO means "no span", and DDSpanContext is the only ProfilerContext), so
this is defensive: route a zero span to a clean clearTraceContext instead of a
silently-swallowed throw over stale state.

Also document clearContextValue(int)'s return contract (@param/@return) and add a
testContextRegistration scenario asserting a zero-span activation does not throw and
still reapplies app context.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

profiling(ddprof): describe current behavior in comments; drop historical references

Rewrite or remove comments that documented the superseded DirectByteBuffer context
API and the ddprof-version history of the bridge (e.g. "Replaces the previous
setContext...", "no DBB read", the 1.41.0/1.45.0 no-op history in
DatadogProfilingScope). Those explain how the code got here, not what it does now;
the commit history and PRs carry that evolution. Comment-only, behavior unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

profiling(ddprof): fix JMH benchmark for strings-only AppContextSnapshot

AppContextSnapshotBenchmark.setup() still called the old
record(int, int, byte[], String) signature; AppContextSnapshot.record is now
record(int, String) (strings-only, per the all-native context migration).
compileJmhJava was failing in CI.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

profiling(ddprof): fix two reapply ordering bugs found by PR review bots

- setContextValue: a rejected native write (e.g. >255-byte UTF-8) clears the
  native slot but left the Java snapshot untouched, so the attribute read as
  unset until the next span boundary silently resurrected the stale prior
  value. Reapply immediately on rejection so the prior value stays visible
  continuously, matching pre-migration DBB behavior.
- setTraceContext: reapplyAppContext() ran unconditionally after the native
  call, so when profiling.context.attributes also names
  _dd.trace.operation/resource (with span-name/resource-name context
  enabled), the trailing reapply clobbered the span-derived value that
  setTraceContext just wrote to the same offset with a stale app-recorded
  one. reapplyAppContext now takes the operation/resource offsets to skip.

Both were flagged independently by Codex and Datadog Autotest PR review bots
on #11899, with a concrete repro for the first. Added regression coverage to
DatadogProfilerTest#testContextRegistration for both (verified each new
assertion fails without its corresponding fix).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

Merge branch 'master' into rkennke/profiler-all-native-context-phase2

Rename reapplyAppContext skip-offset params to operationOffset/resourceOffset

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

Merge branch 'master' into rkennke/profiler-all-native-context-phase2

Co-authored-by: devflow.devflow-routing-intake <devflow.devflow-routing-intake@kubernetes.us1.ddbuild.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: profiling Profiling tag: ai generated Largely based on code generated by an AI or LLM type: bug fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants