Skip to content

feat(llmobs): read experiment scope from APM baggage in StartSpan#4651

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 2 commits intomainfrom
zied.aouini/llmobs-read-experiment-scope-from-baggage
Apr 13, 2026
Merged

feat(llmobs): read experiment scope from APM baggage in StartSpan#4651
gh-worker-dd-mergequeue-cf854d[bot] merged 2 commits intomainfrom
zied.aouini/llmobs-read-experiment-scope-from-baggage

Conversation

@aouinizied
Copy link
Copy Markdown
Member

What does this PR do?

Adds experiment scope propagation to StartSpan via APM baggage. When a parent span sets _ml_obs.experiment_id as a baggage item (e.g. via StartExperimentSpan), child LLMObs spans created with StartSpan now automatically read that baggage and set their scope to "experiments".

This requires exposing BaggageItem(key string) string on the APMSpan interface (the underlying Span type already has this method).

Motivation

The Python SDK already does this — every span checks span.context.get_baggage_item("_ml_obs.experiment_id") and sets _dd.scope = "experiments" if present. The Go SDK only set scope inside StartExperimentSpan directly, meaning child spans created via StartSpan were missing the experiments scope even when the baggage was propagated on the APM span.

Reviewer's Checklist

  • Changed code has unit tests for its functionality at or near 100% coverage.
  • System-Tests covering this feature have been added and enabled with the va.b.c-dev version tag.
  • There is a benchmark for any new code, or changes to existing code.
  • If this interacts with the agent in a new way, a system test has been added.
  • New code is free of linting errors. You can check this by running make lint locally.
  • New code doesn't break existing tests. You can check this by running make test locally.
  • Add an appropriate team label so this PR gets put in the right place for the release notes.
  • All generated files are up to date. You can check this by running make generate locally.
  • Non-trivial go.mod changes, e.g. adding new modules, are reviewed by @DataDog/dd-trace-go-guild. Make sure all nested modules are up to date by running make fix-modules locally.

Child LLMObs spans now check for the _ml_obs.experiment_id baggage item
on the APM span and automatically set scope to "experiments" when present.
Verifies that child spans created with StartSpan inherit scope
"experiments" when parent sets _ml_obs.experiment_id baggage.
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 10, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.71%. Comparing base (747b2e5) to head (b30b279).

Files with missing lines Patch % Lines
ddtrace/tracer/llmobs.go 0.00% 2 Missing ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
internal/llmobs/llmobs.go 78.13% <100.00%> (-6.01%) ⬇️
ddtrace/tracer/llmobs.go 0.00% <0.00%> (ø)

... and 271 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@datadog-official
Copy link
Copy Markdown
Contributor

datadog-official bot commented Apr 10, 2026

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 66.67%
Overall Coverage: 60.10% (-0.01%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: b30b279 | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback!

@pr-commenter
Copy link
Copy Markdown

pr-commenter bot commented Apr 10, 2026

Benchmarks

Benchmark execution time: 2026-04-10 09:40:42

Comparing candidate commit b30b279 in PR branch zied.aouini/llmobs-read-experiment-scope-from-baggage with baseline commit 747b2e5 in branch main.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 216 metrics, 8 unstable metrics.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

@aouinizied aouinizied marked this pull request as ready for review April 10, 2026 17:44
@aouinizied aouinizied requested review from a team as code owners April 10, 2026 17:44
@aouinizied aouinizied marked this pull request as draft April 13, 2026 08:40
@aouinizied aouinizied marked this pull request as ready for review April 13, 2026 10:15
Copy link
Copy Markdown
Contributor

@rarguelloF rarguelloF left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Copy Markdown
Member

@darccio darccio left a comment

Choose a reason for hiding this comment

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

LGTM

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants