Skip to content

Mix Databricks repair attempt into Spark parent trace id#12022

Open
aboitreaud wants to merge 6 commits into
masterfrom
adrien.boitreaud/databricks-repair-run-spark-trace-correlation
Open

Mix Databricks repair attempt into Spark parent trace id#12022
aboitreaud wants to merge 6 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

Copy link
Copy Markdown

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 69.73% (+12.34%)

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

@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 14.00 s 13.99 s [-0.6%; +0.8%] (no difference)
startup:insecure-bank:tracing:Agent 12.90 s 12.99 s [-1.4%; +0.1%] (no difference)
startup:petclinic:appsec:Agent 16.92 s 16.86 s [-0.6%; +1.3%] (no difference)
startup:petclinic:iast:Agent 16.95 s 16.96 s [-1.0%; +0.8%] (no difference)
startup:petclinic:profiling:Agent 16.59 s 16.65 s [-1.5%; +0.7%] (no difference)
startup:petclinic:sca:Agent 17.04 s 16.78 s [+0.7%; +2.3%] (maybe worse)
startup:petclinic:tracing:Agent 16.08 s 16.06 s [-0.8%; +1.0%] (no difference)

Commit: 56ca8200 · 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.

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.

1 participant