Skip to content

feat(openfeature): add span enrichment#4844

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 2 commits into
mainfrom
oleksii/span-enrichment
Jul 1, 2026
Merged

feat(openfeature): add span enrichment#4844
gh-worker-dd-mergequeue-cf854d[bot] merged 2 commits into
mainfrom
oleksii/span-enrichment

Conversation

@dd-oleksii

@dd-oleksii dd-oleksii commented Jun 3, 2026

Copy link
Copy Markdown
Member

What does this PR do?

Add an optional integration between openfeature and tracer that adds feature flag evaluation details as span tags. These are later decoded by the backend to associate traces with experiments. More details in RFC.

Motivation

This deepens integration between FFE (feature flagging and experimentation) and APM, and allows users to run experiments on APM-generated metrics.

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. ffe/go: enable span enrichment tests system-tests#7125
  • 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!

@dd-oleksii dd-oleksii requested review from a team as code owners June 3, 2026 02:59
@dd-oleksii dd-oleksii added the team:ffe Feature Flagging & Experimentation label Jun 3, 2026

@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: 39968c94bd

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

Comment thread openfeature/span_enrichment.go
@datadog-prod-us1-3

datadog-prod-us1-3 Bot commented Jun 3, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 72.73%
Overall Coverage: 62.94% (-0.02%)

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

@codecov

codecov Bot commented Jun 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 74.84277% with 40 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.68%. Comparing base (31d85a6) to head (08ef21a).
⚠️ Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
internal/openfeature/span_enrichment.go 77.77% 12 Missing and 8 partials ⚠️
ddtrace/tracer/span.go 26.31% 14 Missing ⚠️
openfeature/span_enrichment.go 80.00% 3 Missing and 3 partials ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
openfeature/evaluator.go 78.08% <100.00%> (ø)
openfeature/exposure_hook.go 90.62% <ø> (ø)
openfeature/provider.go 73.68% <100.00%> (ø)
openfeature/span_enrichment.go 80.00% <80.00%> (ø)
ddtrace/tracer/span.go 85.71% <26.31%> (ø)
internal/openfeature/span_enrichment.go 77.77% <77.77%> (ø)

... and 454 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.

@dd-oleksii dd-oleksii force-pushed the oleksii/span-enrichment branch 2 times, most recently from 05a6a4c to 980c094 Compare June 3, 2026 03:26
@pr-commenter

pr-commenter Bot commented Jun 3, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-06-25 02:11:42

Comparing candidate commit 2e59473 in PR branch oleksii/span-enrichment with baseline commit baa5573 in branch main.

Found 2 performance improvements and 1 performance regressions! Performance is the same for 294 metrics, 2 unstable metrics, 1 flaky benchmarks without significant changes.

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 ----------------------------------'

scenario:BenchmarkInjectW3C

  • 🟩 execution_time [-63.500ns; -47.500ns] or [-2.994%; -2.240%]

scenario:BenchmarkOTLPProtoSize/1000spans

  • 🟩 execution_time [-10.147µs; -9.437µs] or [-3.099%; -2.882%]

scenario:BenchmarkPayloadVersions/simple_1000spans/v1.0

  • 🟥 allocated_mem [+1 bytes; +1 bytes] or [+2.857%; +2.857%]

Known flaky benchmarks

These benchmarks are marked as flaky and will not trigger a failure. Modify FLAKY_BENCHMARKS_REGEX to control which benchmarks are marked as flaky.

Known flaky benchmarks without significant changes:

  • scenario:BenchmarkOTLPTraceWriterFlush

@dd-oleksii dd-oleksii force-pushed the oleksii/span-enrichment branch from 980c094 to 4c3c5dc Compare June 4, 2026 12:38

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

A couple bits of feedback. Let me know if you need help with checking these changes against the tests in DataDog/system-tests#6828 There should be a way to run it locally

Comment thread internal/openfeature/span_enrichment.go
Comment thread internal/openfeature/span_enrichment.go Outdated
@dd-oleksii dd-oleksii force-pushed the oleksii/span-enrichment branch 3 times, most recently from 858ebd6 to 0e2b1ba Compare June 10, 2026 13:50
@dd-oleksii dd-oleksii requested a review from sameerank June 10, 2026 15:59

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

Thanks for making the requested changes!

Comment thread ddtrace/tracer/span.go Outdated
Comment thread internal/openfeature/span_enrichment.go Outdated
Comment thread ddtrace/tracer/span.go
Comment thread internal/openfeature/span_enrichment.go Outdated
Comment thread internal/openfeature/span_enrichment.go
Comment thread openfeature/span_enrichment_test.go Outdated
Comment thread openfeature/span_enrichment_test.go
func (se *SpanEnrichment) addSerialID(sid uint32) {
if _, exists := se.serialIDs[sid]; !exists {
if len(se.serialIDs) >= spanEnrichmentMaxSerialIDs {
log.Debug("openfeature: span enrichment: too many flag serial IDs, dropping (max %d)", spanEnrichmentMaxSerialIDs)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we have telemetry on these drops?

@dd-oleksii dd-oleksii Jun 25, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, I think it's useful. Dropping serial ids may impact experiment results, so worth flagging. I'm going to add it in a follow-up — looks like I need to add the new metric in dd-go first, also not sure if triggering telemetry while holding span mutex is safe

Comment thread openfeature/types.go
Comment thread openfeature/provider.go
@kakkoyun kakkoyun self-requested a review June 23, 2026 12:21
@dd-oleksii dd-oleksii marked this pull request as draft June 23, 2026 17:57
@dd-oleksii dd-oleksii force-pushed the oleksii/span-enrichment branch 4 times, most recently from 5c99705 to e5e23b0 Compare June 25, 2026 01:05
@dd-oleksii dd-oleksii force-pushed the oleksii/span-enrichment branch from e5e23b0 to 2465a86 Compare June 25, 2026 01:05
@dd-oleksii dd-oleksii marked this pull request as ready for review June 25, 2026 01:12

@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: 2465a86288

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

eval.Subject = evalCtx.TargetingKey()
}
return eval
} else if evalDetails.Variant == "" {

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 Treat type mismatches as runtime defaults

When a matched flag carries a variant/serialId but the caller requests an incompatible type, the SDK returns the caller's default with TypeMismatchCode while preserving the provider's variant metadata; the existing flag-evaluation path treats that case as a runtime default. This check only handles Variant == "" and the serial-id branch above wins first, so span enrichment records the experiment serial/subject (or drops the default if no serial is present) even though the application received the default value, causing traces to be associated with variants users did not receive.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Erronous evaluations must not set serial id/variant

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.

I noticed this as well in my Java implementation; the evaluator checks type compatibility before it attaches variant metadata / serial ID metadata. I believe there is an existing bug in the Go implementation.

What Java does have is safer because it checks type compatibility first and returns TYPE_MISMATCH.

https://github.com/DataDog/dd-trace-java/blob/master/products/feature-flagging/feature-flagging-api/src/main/java/datadog/trace/api/openfeature/DDEvaluator.java#L365-L372

Then the evaluator only attaches __dd_split_serial_id after that check passes.

https://github.com/DataDog/dd-trace-java/pull/11658/changes#diff-bb0f2b4fd2735100fb695688e2ac2b660736f170dfa310581597f1fb508bd426

Finally, SpanEnrichmentHook.java can safely prefer serial ID because Java never leaves serial metadata on a type-mismatch result.

https://github.com/DataDog/dd-trace-java/pull/11658/changes#diff-f811d167f50174142ea217783896ba76819da9cc7f19b65e4a922cda3bb10abcR107-R123

@dd-oleksii dd-oleksii force-pushed the oleksii/span-enrichment branch from 2465a86 to 2e59473 Compare June 25, 2026 01:47
@dd-oleksii dd-oleksii requested a review from darccio June 25, 2026 02:12

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

One risk identified is that it can emit ffe_flags_enc for a variant the app did not actually receive.

I added a stack PR with a new test to demonstrate: #4953

Comment thread openfeature/provider.go
evalLoggingHook = newFlagEvalLoggingHook(evalWriter)
}

var spanEnrichmentHook *spanEnrichmentHook

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.

Oh, shutdown, are you able to clean up the span enrichment state?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't think there's a need because the state is tied to spans (and in particular to root spans). So when those spans are finished, it's going to send and cleanup that state. There's no state in span enrichment hook itself

eval.Subject = evalCtx.TargetingKey()
}
return eval
} else if evalDetails.Variant == "" {

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.

I noticed this as well in my Java implementation; the evaluator checks type compatibility before it attaches variant metadata / serial ID metadata. I believe there is an existing bug in the Go implementation.

What Java does have is safer because it checks type compatibility first and returns TYPE_MISMATCH.

https://github.com/DataDog/dd-trace-java/blob/master/products/feature-flagging/feature-flagging-api/src/main/java/datadog/trace/api/openfeature/DDEvaluator.java#L365-L372

Then the evaluator only attaches __dd_split_serial_id after that check passes.

https://github.com/DataDog/dd-trace-java/pull/11658/changes#diff-bb0f2b4fd2735100fb695688e2ac2b660736f170dfa310581597f1fb508bd426

Finally, SpanEnrichmentHook.java can safely prefer serial ID because Java never leaves serial metadata on a type-mismatch result.

https://github.com/DataDog/dd-trace-java/pull/11658/changes#diff-f811d167f50174142ea217783896ba76819da9cc7f19b65e4a922cda3bb10abcR107-R123

Comment thread internal/openfeature/span_enrichment.go

@darccio darccio left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

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

Let's discuss plans as a team about resolving (#4953) with a cohesive effort.

@dd-oleksii

Copy link
Copy Markdown
Member Author

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Jun 30, 2026

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-06-30 11:06:35 UTC ℹ️ Start processing command /merge


2026-06-30 11:06:45 UTC ℹ️ MergeQueue: waiting for PR to be ready

This pull request is not mergeable according to GitHub. Common reasons include pending required checks, missing approvals, or merge conflicts — but it could also be blocked by other repository rules or settings.
It will be added to the queue as soon as checks pass and/or get approvals. View in MergeQueue UI.
Note: if you pushed new commits since the last approval, you may need additional approval.
You can remove it from the waiting list with /remove command.


2026-06-30 15:12:13 UTC ⚠️ MergeQueue: This merge request was unqueued

devflow unqueued this merge request: It did not become mergeable within the expected time

@gh-worker-dd-mergequeue-cf854d gh-worker-dd-mergequeue-cf854d Bot merged commit 40a2a62 into main Jul 1, 2026
214 checks passed
@gh-worker-dd-mergequeue-cf854d gh-worker-dd-mergequeue-cf854d Bot deleted the oleksii/span-enrichment branch July 1, 2026 11:33
darccio pushed a commit that referenced this pull request Jul 1, 2026
<!--
* New contributors are highly encouraged to read our
  [CONTRIBUTING](/CONTRIBUTING.md) documentation.
* Commit and PR titles should be prefixed with the general area of the pull request's change.

-->
### What does this PR do?

<!--
* A brief description of the change being made with this pull request.
* If the description here cannot be expressed in a succinct form, consider
  opening multiple pull requests instead of a single one.
-->
Add an optional integration between openfeature and tracer that adds feature flag evaluation details as span tags. These are later decoded by the backend to associate traces with experiments. [More details in RFC](https://docs.google.com/document/d/1rtO4uCZ0-y5iLfNkKjIbHqWpx2qF4cHZV13ENafuomk/edit?tab=t.0#).

### Motivation

<!--
* What inspired you to submit this pull request?
* Link any related GitHub issues or PRs here.
* If this resolves a GitHub issue, include "Fixes #XXXX" to link the issue and auto-close it on merge.
-->
This deepens integration between FFE (feature flagging and experimentation) and APM, and allows users to run experiments on APM-generated metrics.

### Reviewer's Checklist
<!--
* Authors can use this list as a reference to ensure that there are no problems
  during the review but the signing off is to be done by the reviewer(s).
-->

- [ ] Changed code has unit tests for its functionality at or near 100% coverage.
- [X] [System-Tests](https://github.com/DataDog/system-tests/) covering this feature have been added and enabled with the va.b.c-dev version tag. DataDog/system-tests#7125
- [ ] There is a benchmark for any new code, or changes to existing code.
- [X] If this interacts with the agent in a new way, a system test has been added.
- [X] New code is free of linting errors. You can check this by running `make lint` locally.
- [X] New code doesn't break existing tests. You can check this by running `make test` locally.
- [X] Add an appropriate team label so this PR gets put in the right place for the release notes.
- [X] 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!


Co-authored-by: benjamin.debernardi <benjamin.debernardi@datadoghq.com>
@darccio darccio mentioned this pull request Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mergequeue-status: done team:ffe Feature Flagging & Experimentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants