Skip to content

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

Draft
jbachorik wants to merge 3 commits into
masterfrom
jb/flaky_profile_tests
Draft

Fix app context attributes wiped by ddprof setContext on span activation#11646
jbachorik wants to merge 3 commits 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-SNAPSHOT).

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

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-SNAPSHOT (setContextValuesByIdAndBytes on ContextSetter / ThreadContext) — tracked in PROF-15098
  • ThreadContext.setContextValuesByIdAndBytes validates input before mutating (no half-written records on bad input) and skips slots with constantId <= 0
  • hasAppContextAttributes() and the redundant HAS_APP_CONTEXT static guard in DatadogProfilingIntegration were removed — reapplyAppContext() already short-circuits on !hasAppContext
  • Constant IDs are stable once registered in the global pool; the per-thread 256-entry ThreadContext cache makes the initial setContextAttribute cheap on repeated values

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]

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jbachorik jbachorik added type: bug Bug report and 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

Pipelines

Fix all issues with BitsAI

⚠️ Warnings

🚦 9 Pipeline jobs failed

DataDog/apm-reliability/dd-trace-java | build   View in Datadog   GitLab

DataDog/apm-reliability/dd-trace-java | build_tests: [:baseTest, base]   View in Datadog   GitLab

DataDog/apm-reliability/dd-trace-java | build_tests: [:instrumentationLatestDepTest, latestdep]   View in Datadog   GitLab

View all 9 failed jobs.

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 98e1879 | 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 13.91 s 13.91 s [-0.8%; +0.8%] (no difference)
startup:insecure-bank:tracing:Agent 12.90 s 12.94 s [-1.1%; +0.5%] (no difference)
startup:petclinic:appsec:Agent 16.81 s 16.10 s [+0.0%; +8.9%] (maybe worse)
startup:petclinic:iast:Agent 16.31 s 16.85 s [-7.4%; +0.9%] (no difference)
startup:petclinic:profiling:Agent 16.76 s 16.79 s [-1.5%; +1.0%] (no difference)
startup:petclinic:sca:Agent 16.67 s 16.68 s [-1.0%; +0.8%] (no difference)
startup:petclinic:tracing:Agent 15.93 s 15.98 s [-1.3%; +0.7%] (no difference)

Commit: 1a2464b7 · 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 and others added 2 commits June 15, 2026 17:30
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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 tag: no release notes Changes to exclude from release notes type: bug Bug report and fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant