Skip to content

Mix Databricks repair attempt into Spark parent trace id - #12022

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 7 commits into
masterfrom
adrien.boitreaud/databricks-repair-run-spark-trace-correlation
Jul 23, 2026
Merged

gh-worker-dd-mergequeue-cf854d[bot] merged 7 commits into
masterfrom
adrien.boitreaud/databricks-repair-run-spark-trace-correlation

Conversation

@aboitreaud

@aboitreaud aboitreaud commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

What Does This Do

When a Databricks job run is repaired, Databricks reuses the same jobRunId, so the original and repaired attempts hashed to the same Spark parent trace id and collapsed onto one trace. This mixes the repair attempt index into the parent trace id (suffix -<attempt>, bare for attempt 0) so each attempt lands on its own trace.

The attempt index is recovered best-effort from the base64 + java-serialized unity.scope.data local property (key jobRunAttemptNum); on any failure it falls back to 0, reproducing the previous (non-repair-aware) trace id.

Motivation

Correlate Spark spans with the correct Databricks repair-run trace. Mirrors the crawler side in ddoghq/dogweb#411, using the same hash inputs on both sides.

Additional Notes

  • Attempt 0 stays bare for backward compatibility with never-repaired runs.
  • Parent span id is unchanged: it is keyed on taskRunId, which Databricks issues fresh per attempt.

@aboitreaud
aboitreaud requested a review from a team as a code owner July 21, 2026 13:56
@dd-octo-sts

dd-octo-sts Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Hi! 👋 Thanks for your pull request! 🎉

To help us review it, please make sure to:

  • Add at least one type, and one component or instrumentation label to the pull request

If you need help, please check our contributing guidelines.

@datadog-datadog-us1-prod datadog-datadog-us1-prod 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.

Datadog Autotest: PASS

More details

Databricks repair attempt extraction and trace ID mixing implementation is sound. Adversarial testing of the byte parsing logic (12/12 scenarios passed) confirms correct boundary checks, error handling, and output correctness. Constructor signature change is properly propagated with updated test fixtures. Trace ID differentiation between repair attempts (attempt 0 vs 1+) is verified by new test assertion. No behavioral regressions.

Was this helpful? React 👍 or 👎

📊 Validated against 12 scenarios · Open Bits AI session

🤖 Datadog Autotest · Commit 103f0b8 · What is Autotest? · Any feedback? Reach out in #autotest

@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: 103f0b88f6

ℹ️ 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".

// In the java-serialized stream the value follows its key as the next string, written as
// TC_STRING (0x74) with a 2-byte big-endian length prefix.
for (int i = keyIdx + JOB_RUN_ATTEMPT_NUM_KEY.length; i + 3 <= decoded.length; i++) {
if (decoded[i] != 0x74) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Handle repeated serialized string values

When unity.scope.data is a normal Java-serialized map and the attempt value has already appeared earlier in the stream (for example another Databricks tag with value "1" is written before jobRunAttemptNum), serialization emits that value as a TC_REFERENCE (0x71) rather than another TC_STRING (0x74). This loop skips references and then falls back to 0 (or parses a later string), so those repaired runs still hash as attempt 0 and the Spark spans attach to the original Databricks trace instead of the repair trace.

Useful? React with 👍 / 👎.

def contextWithoutTaskRunId = new DatabricksParentContext(null, "5678", null, 0)
// A repaired run reuses the same jobRunId but reports a non-zero attempt, which must yield a
// different trace id (its own trace) while a repaired task keeps its own fresh taskRunId span id.
def contextRepairedAttempt = new DatabricksParentContext("1234", "5678", "9012", 1)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Migrate touched Spock fixture to JUnit 5

The root /workspace/dd-trace-java/AGENTS.md Test frameworks guideline says to use JUnit 5 and migrate an existing Groovy test when it is touched. This change adds repaired-run coverage to the existing Spock fixture instead, so the new coverage remains in the deprecated test framework rather than following the repository instruction.

Useful? React with 👍 / 👎.

@aboitreaud aboitreaud added inst: apache spark Apache Spark instrumentation type: feature Enhancements and improvements labels Jul 22, 2026
@datadog-datadog-us1-prod

This comment has been minimized.

@dd-octo-sts

dd-octo-sts Bot commented Jul 22, 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.97 s 13.92 s [-0.4%; +1.1%] (no difference)
startup:insecure-bank:tracing:Agent 12.96 s 13.03 s [-1.5%; +0.4%] (no difference)
startup:petclinic:appsec:Agent 16.80 s 16.59 s [+0.3%; +2.1%] (maybe worse)
startup:petclinic:iast:Agent 16.30 s 16.87 s [-7.7%; +0.8%] (no difference)
startup:petclinic:profiling:Agent 16.68 s 16.67 s [-1.2%; +1.4%] (no difference)
startup:petclinic:sca:Agent 16.80 s 16.20 s [-0.6%; +8.0%] (no difference)
startup:petclinic:tracing:Agent 15.93 s 16.23 s [-3.1%; -0.7%] (maybe better)

Commit: 1d6a64fd · 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.

@pawel-big-lebowski pawel-big-lebowski 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.

Minor comment provided. Overwise looks good.

return 0;
}

private static int indexOf(byte[] haystack, byte[] needle) {

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.

Shouldn't the 2 newly added methods land in separate class? If difficult to apply with bytebuddy, please rename indexOf method to something more dbx specific?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I went for the rename 1d6a64f sounded simpler tbh 🙂

@aboitreaud
aboitreaud enabled auto-merge July 23, 2026 10:46
@aboitreaud
aboitreaud added this pull request to the merge queue Jul 23, 2026
@dd-octo-sts

dd-octo-sts Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

/merge

@gh-worker-devflow-routing-ef8351

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

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-07-23 11:29:44 UTC ℹ️ Start processing command /merge


2026-07-23 11:29:49 UTC ℹ️ MergeQueue: pull request added to the queue

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


2026-07-23 12:28:05 UTC ℹ️ MergeQueue: This merge request was merged

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 23, 2026
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit 507d52c into master Jul 23, 2026
587 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the adrien.boitreaud/databricks-repair-run-spark-trace-correlation branch July 23, 2026 12:28
@github-actions github-actions Bot added this to the 1.65.0 milestone Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

inst: apache spark Apache Spark instrumentation type: feature Enhancements and improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants