Skip to content

feat(llmobs): prompt tracking#4608

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 8 commits into
mainfrom
rarguelloF/MLOB-6011/prompt-tracking
Apr 8, 2026
Merged

feat(llmobs): prompt tracking#4608
gh-worker-dd-mergequeue-cf854d[bot] merged 8 commits into
mainfrom
rarguelloF/MLOB-6011/prompt-tracking

Conversation

@rarguelloF

@rarguelloF rarguelloF commented Mar 26, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds prompt tracking support for LLM spans in LLMObs via a new WithAnnotatedPrompt annotation option.

Example usage:

ctx := context.Background()

span, ctx := llmobs.StartLLMSpan(ctx, "my-llm-call")
defer span.Finish()

input := []llmobs.LLMMessage{
    {Role: "system", Content: "You are a helpful assistant."},
    {Role: "user", Content: "{{question}}"},
}
output := []llmobs.LLMMessage{
    {Role: "assistant", Content: "The answer is 42."},
}

span.AnnotateLLMIO(input, output,
    llmobs.WithAnnotatedPrompt(llmobs.Prompt{
        ID:      "qa-prompt",
        Version: "1.0.0",
        Label:   "production",
        ChatTemplate: []llmobs.LLMMessage{
            {Role: "system", Content: "You are a helpful assistant."},
            {Role: "user", Content: "{{question}}"},
        },
        Variables: map[string]string{
            "question": "What is the answer to life?",
        },
        RAGQueryVariables: []string{"question"},
    }),
)

Additional changes:

  • Adds WithAnnotatedToolDefinitions(toolDefinitions []ToolDefinition) annotation option for LLM spans.
  • Renames WithIntentWithAnnotatedIntent (old function deprecated, kept as alias)

Motivation

Prompt tracking LLMObs feature

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.

Unsure? Have a question? Request a review!

@github-actions github-actions Bot added the apm:ecosystem contrib/* related feature requests or bugs label Mar 26, 2026
@codecov

codecov Bot commented Mar 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.85714% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 60.75%. Comparing base (0e06d9c) to head (f4d6d76).

Files with missing lines Patch % Lines
llmobs/option.go 87.50% 1 Missing ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
internal/llmobs/llmobs.go 78.04% <100.00%> (ø)
internal/llmobs/span.go 71.35% <100.00%> (ø)
llmobs/llmobs.go 76.53% <ø> (ø)
llmobs/option.go 87.93% <87.50%> (ø)

... and 439 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-prod-us1-6

datadog-prod-us1-6 Bot commented Mar 26, 2026

Copy link
Copy Markdown

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 90.91%
Overall Coverage: 60.08%

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

@pr-commenter

pr-commenter Bot commented Mar 26, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-04-08 17:51:36

Comparing candidate commit f4d6d76 in PR branch rarguelloF/MLOB-6011/prompt-tracking with baseline commit 0e06d9c in branch main.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 217 metrics, 7 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 ----------------------------------'

@rarguelloF
rarguelloF marked this pull request as ready for review March 31, 2026 17:09
@rarguelloF
rarguelloF requested review from a team as code owners March 31, 2026 17:09

@PROFeNoM PROFeNoM 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.

LGTM - the data model matches Python's, defaults are correct, and tests are good 👍 Left one non-blocking comment :shipit:

Comment thread internal/llmobs/span.go
Comment on lines 354 to 369
if a.Prompt != nil {
if s.spanKind != SpanKindLLM {
log.Warn("llmobs: input prompt can only be annotated on llm spans, ignoring")
} else {
if a.Prompt.RAGContextVariables == nil {
a.Prompt.RAGContextVariables = []string{"context"}
}
if a.Prompt.RAGQueryVariables == nil {
a.Prompt.RAGQueryVariables = []string{"question"}
}
if a.Prompt.ID == "" {
a.Prompt.ID = s.mlApp + "_unnamed-prompt"
}
a.Prompt.MLApp = s.mlApp
s.llmCtx.prompt = a.Prompt
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: Python validates that template and chat_template are mutually exclusive. Might be worth a similar guard here since both fields are documented as alternatives, and setting both would produce a payload with both keys. Not blocking.

ddtrace/llmobs/_utils.py#L92-L93

if template and chat_template:
    raise ValueError("Only one of 'template' or 'chat_template' can be provided, not both.")

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.

thanks, that makes sense! In the Go SDK we are avoiding returning errors / panics, so we would prefer not to raise an exception like in Python. But we could automatically drop one of the 2 (keep chat_template maybe which looks more specific?) and log a warning. WDYT?

@rarguelloF

Copy link
Copy Markdown
Contributor Author

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Apr 8, 2026

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-04-08 08:59:31 UTC ℹ️ Start processing command /merge


2026-04-08 08:59:37 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in main is approximately 27m (p90).


2026-04-08 09:03:56 UTC ℹ️ MergeQueue: Readding this merge request to the queue because another merge request processed with yours failed. No action is needed from your side.


2026-04-08 09:13:44 UTCMergeQueue: The checks failed on this merge request

Tests failed on this commit b52e94a:

What to do next?

  • Investigate the failures and when ready, re-add your pull request to the queue!
  • If your PR checks are green, try to rebase/merge. It might be because the CI run is a bit old.
  • Any question, go check the FAQ.

@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit 8eba8fb into main Apr 8, 2026
450 of 464 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the rarguelloF/MLOB-6011/prompt-tracking branch April 8, 2026 18:36
darccio added a commit that referenced this pull request Apr 14, 2026
… merge

After merging main (which added the prompt-tracking PR #4608), test cases
that used the old testtracer.TestTracer API (Stop/WaitForLLMObsSpans) and
mismatched testTracer return-value counts needed updating for the new
llmobstest.Collector API (RequireSpan + tracer.Flush).

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

apm:ecosystem contrib/* related feature requests or bugs mergequeue-status: done

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants