Skip to content

feat: tag trace and current span with feature flag metadata#7764

Draft
petzel wants to merge 1 commit intomasterfrom
eric.petzel/feature-flag-span-generation-tagging
Draft

feat: tag trace and current span with feature flag metadata#7764
petzel wants to merge 1 commit intomasterfrom
eric.petzel/feature-flag-span-generation-tagging

Conversation

@petzel
Copy link

@petzel petzel commented Mar 12, 2026

What does this PR do?

Attaches feature flag evaluation metadata to APM spans, enabling correlation between flag evaluations and traces.

When a flag is evaluated via the OpenFeature provider, we add tags on both the active span and trace with flag metadata (feature_flags..variant.key, feature_flags..subject.id).

Falls back to String(result.value) as the variant when the provider returns no explicit variant (e.g., flag not found, default returned).

Also enforces a configurable per-span limit on the number of flag tags to prevent bandwidth issues in traces with many evaluations

Motivation

Users of Datadog Feature Flagging + APM want to be able to filter APM traces by feature flag variant. These changes aim to enable that use case.

Additional Notes

Added config option:

  • DD_EXPERIMENTAL_FLAGGING_PROVIDER_MAX_FLAG_TAGS (default: 300) — maximum number of unique flag tags per span. Once reached, further evaluations still tag the current span, but skip tagging the trace.
    • The default maximum for feature flags added to RUM/Product Analytics events is 300, but that is across an entire user session. I chose to use 300 here to align with RUM.

Testing

  • Installed the tracer on a local NodeJS application
  • Created an endpoint which evaluated N (as input) number of feature flags
  • Set DD_EXPERIMENTAL_FLAGGING_PROVIDER_MAX_FLAG_TAGS=3
  • Invoked the endpoint with N=10
  • Ensured span tags were added to the current span
  • Ensured 3 trace tags were added
image
  • Set DD_EXPERIMENTAL_FLAGGING_PROVIDER_MAX_FLAG_TAGS=50
  • Invoked the endpoint with N=50
  • Ensured span tags were added to the current span
  • Ensured 50 trace tags were added
image

@github-actions
Copy link
Contributor

github-actions bot commented Mar 12, 2026

Overall package size

Self size: 4.98 MB
Deduped: 5.82 MB
No deduping: 5.82 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.0.0 | 81.15 kB | 815.98 kB | | dc-polyfill | 0.1.10 | 26.73 kB | 26.73 kB |

🤖 This report was automatically generated by heaviest-objects-in-the-universe

@codecov
Copy link

codecov bot commented Mar 12, 2026

Codecov Report

❌ Patch coverage is 11.76471% with 30 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.29%. Comparing base (d1b3492) to head (4ff7e14).

Files with missing lines Patch % Lines
packages/dd-trace/src/openfeature/span_tagger.js 9.52% 19 Missing ⚠️
...ages/dd-trace/src/openfeature/flagging_provider.js 9.09% 10 Missing ⚠️
packages/dd-trace/src/config/index.js 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7764      +/-   ##
==========================================
- Coverage   80.36%   80.29%   -0.08%     
==========================================
  Files         743      744       +1     
  Lines       32293    32327      +34     
==========================================
+ Hits        25953    25957       +4     
- Misses       6340     6370      +30     
Flag Coverage Δ
aiguard-macos 39.07% <50.00%> (-0.10%) ⬇️
aiguard-ubuntu 39.18% <50.00%> (-0.10%) ⬇️
aiguard-windows 38.91% <50.00%> (?)
apm-capabilities-tracing-macos 48.91% <11.76%> (-0.05%) ⬇️
apm-capabilities-tracing-ubuntu 48.94% <11.76%> (-0.05%) ⬇️
apm-capabilities-tracing-windows 48.68% <11.76%> (-0.05%) ⬇️
apm-integrations-child-process 38.37% <50.00%> (-0.10%) ⬇️
apm-integrations-couchbase-18 37.29% <50.00%> (-0.10%) ⬇️
apm-integrations-couchbase-eol 37.75% <50.00%> (-0.15%) ⬇️
apm-integrations-oracledb 37.59% <50.00%> (-0.09%) ⬇️
appsec-express 55.17% <50.00%> (-0.07%) ⬇️
appsec-fastify 51.51% <50.00%> (-0.07%) ⬇️
appsec-graphql 51.72% <50.00%> (-0.06%) ⬇️
appsec-kafka 44.24% <50.00%> (-0.08%) ⬇️
appsec-ldapjs 43.90% <50.00%> (-0.08%) ⬇️
appsec-lodash 43.56% <50.00%> (-0.08%) ⬇️
appsec-macos 58.18% <50.00%> (-0.07%) ⬇️
appsec-mongodb-core 48.68% <50.00%> (-0.08%) ⬇️
appsec-mongoose 49.34% <50.00%> (-0.08%) ⬇️
appsec-mysql 50.88% <50.00%> (+0.03%) ⬆️
appsec-node-serialize 43.08% <50.00%> (-0.08%) ⬇️
appsec-passport 47.52% <50.00%> (-0.09%) ⬇️
appsec-postgres 50.50% <50.00%> (-0.07%) ⬇️
appsec-sourcing 42.49% <50.00%> (-0.08%) ⬇️
appsec-template 43.25% <50.00%> (-0.08%) ⬇️
appsec-ubuntu 58.26% <50.00%> (-0.07%) ⬇️
appsec-windows 58.02% <50.00%> (-0.07%) ⬇️
instrumentations-instrumentation-bluebird 32.25% <50.00%> (-0.10%) ⬇️
instrumentations-instrumentation-body-parser 40.39% <50.00%> (-0.09%) ⬇️
instrumentations-instrumentation-child_process 37.69% <50.00%> (-0.10%) ⬇️
instrumentations-instrumentation-cookie-parser 34.22% <50.00%> (-0.09%) ⬇️
instrumentations-instrumentation-express 34.54% <50.00%> (-0.09%) ⬇️
instrumentations-instrumentation-express-mongo-sanitize 34.35% <50.00%> (-0.09%) ⬇️
instrumentations-instrumentation-express-session 40.02% <50.00%> (-0.09%) ⬇️
instrumentations-instrumentation-fs 31.86% <50.00%> (-0.10%) ⬇️
instrumentations-instrumentation-generic-pool 29.68% <ø> (ø)
instrumentations-instrumentation-http 39.66% <50.00%> (-0.10%) ⬇️
instrumentations-instrumentation-knex 32.25% <50.00%> (-0.10%) ⬇️
instrumentations-instrumentation-mongoose 33.38% <50.00%> (-0.09%) ⬇️
instrumentations-instrumentation-multer 40.14% <50.00%> (-0.09%) ⬇️
instrumentations-instrumentation-mysql2 38.14% <50.00%> (-0.10%) ⬇️
instrumentations-instrumentation-passport 43.95% <50.00%> (-0.09%) ⬇️
instrumentations-instrumentation-passport-http 43.61% <50.00%> (-0.09%) ⬇️
instrumentations-instrumentation-passport-local 44.15% <50.00%> (-0.09%) ⬇️
instrumentations-instrumentation-pg 37.58% <50.00%> (-0.10%) ⬇️
instrumentations-instrumentation-promise 32.18% <50.00%> (-0.10%) ⬇️
instrumentations-instrumentation-promise-js 32.18% <50.00%> (-0.10%) ⬇️
instrumentations-instrumentation-q 32.22% <50.00%> (-0.10%) ⬇️
instrumentations-instrumentation-url 32.15% <50.00%> (-0.10%) ⬇️
instrumentations-instrumentation-when 32.20% <50.00%> (-0.10%) ⬇️
llmobs-ai 42.13% <50.00%> (-0.09%) ⬇️
llmobs-anthropic 40.16% <50.00%> (-0.09%) ⬇️
llmobs-bedrock 39.11% <50.00%> (-0.08%) ⬇️
llmobs-google-genai 39.66% <50.00%> (-0.09%) ⬇️
llmobs-langchain 39.89% <50.00%> (-0.08%) ⬇️
llmobs-openai 43.85% <50.00%> (-0.09%) ⬇️
llmobs-vertex-ai 39.85% <50.00%> (-0.16%) ⬇️
platform-core 31.47% <ø> (ø)
platform-esbuild 34.42% <ø> (ø)
platform-instrumentations-misc 48.35% <ø> (ø)
platform-shimmer 37.56% <ø> (ø)
platform-unit-guardrails 32.89% <ø> (ø)
plugins-azure-durable-functions 25.62% <ø> (ø)
plugins-azure-event-hubs 25.79% <ø> (ø)
plugins-azure-service-bus 25.15% <ø> (ø)
plugins-bullmq 44.15% <50.00%> (+0.01%) ⬆️
plugins-cassandra 37.63% <50.00%> (-0.09%) ⬇️
plugins-cookie 26.84% <ø> (ø)
plugins-cookie-parser 26.63% <ø> (ø)
plugins-crypto 26.73% <ø> (ø)
plugins-dd-trace-api 38.20% <50.00%> (-0.10%) ⬇️
plugins-express-mongo-sanitize 26.78% <ø> (ø)
plugins-express-session 26.59% <ø> (ø)
plugins-fastify 42.10% <50.00%> (-0.09%) ⬇️
plugins-fetch 38.20% <50.00%> (-0.09%) ⬇️
plugins-fs 38.47% <50.00%> (-0.10%) ⬇️
plugins-generic-pool 25.83% <ø> (ø)
plugins-google-cloud-pubsub 45.31% <50.00%> (-0.09%) ⬇️
plugins-grpc 40.78% <50.00%> (-0.09%) ⬇️
plugins-handlebars 26.82% <ø> (ø)
plugins-hapi 40.02% <50.00%> (-0.10%) ⬇️
plugins-hono 40.28% <50.00%> (-0.09%) ⬇️
plugins-ioredis 38.28% <50.00%> (-0.10%) ⬇️
plugins-knex 26.46% <ø> (ø)
plugins-ldapjs 24.32% <ø> (ø)
plugins-light-my-request 26.19% <ø> (ø)
plugins-limitd-client 32.52% <50.00%> (-0.10%) ⬇️
plugins-lodash 25.92% <ø> (ø)
plugins-mariadb 39.32% <50.00%> (-0.10%) ⬇️
plugins-memcached 38.00% <50.00%> (-0.10%) ⬇️
plugins-microgateway-core 39.09% <50.00%> (-0.10%) ⬇️
plugins-moleculer 40.37% <50.00%> (-0.09%) ⬇️
plugins-mongodb 39.02% <50.00%> (-0.09%) ⬇️
plugins-mongodb-core 38.85% <50.00%> (-0.10%) ⬇️
plugins-mongoose 38.71% <50.00%> (-0.09%) ⬇️
plugins-multer 26.59% <ø> (ø)
plugins-mysql 39.01% <50.00%> (-0.10%) ⬇️
plugins-mysql2 39.11% <50.00%> (-0.10%) ⬇️
plugins-node-serialize 26.89% <ø> (ø)
plugins-opensearch 37.46% <50.00%> (-0.09%) ⬇️
plugins-passport-http 26.64% <ø> (ø)
plugins-postgres 35.51% <50.00%> (-0.08%) ⬇️
plugins-process 26.73% <ø> (ø)
plugins-pug 26.84% <ø> (ø)
plugins-redis 38.74% <50.00%> (-0.10%) ⬇️
plugins-router 42.96% <50.00%> (+0.04%) ⬆️
plugins-sequelize 25.43% <ø> (ø)
plugins-test-and-upstream-amqp10 38.36% <50.00%> (-0.10%) ⬇️
plugins-test-and-upstream-amqplib 43.73% <50.00%> (-0.10%) ⬇️
plugins-test-and-upstream-apollo 38.99% <50.00%> (-0.09%) ⬇️
plugins-test-and-upstream-avsc 38.53% <50.00%> (-0.10%) ⬇️
plugins-test-and-upstream-bunyan 33.78% <50.00%> (-0.10%) ⬇️
plugins-test-and-upstream-connect 40.68% <50.00%> (-0.10%) ⬇️
plugins-test-and-upstream-graphql 39.97% <50.00%> (-0.10%) ⬇️
plugins-test-and-upstream-koa 40.27% <50.00%> (-0.09%) ⬇️
plugins-test-and-upstream-protobufjs 38.75% <50.00%> (-0.10%) ⬇️
plugins-test-and-upstream-rhea 43.91% <50.00%> (-0.10%) ⬇️
plugins-undici 38.97% <50.00%> (-0.09%) ⬇️
plugins-url 26.73% <ø> (ø)
plugins-valkey 37.94% <50.00%> (-0.10%) ⬇️
plugins-vm 26.73% <ø> (ø)
plugins-winston 33.97% <50.00%> (-0.10%) ⬇️
plugins-ws 41.73% <50.00%> (-0.09%) ⬇️
profiling-macos 39.78% <50.00%> (-0.51%) ⬇️
profiling-ubuntu 39.90% <50.00%> (-0.10%) ⬇️
profiling-windows 41.48% <50.00%> (-0.09%) ⬇️
serverless-azure-functions-client 25.50% <ø> (ø)
serverless-azure-functions-eventhubs 25.50% <ø> (ø)
serverless-azure-functions-servicebus 25.50% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 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.

@pr-commenter
Copy link

pr-commenter bot commented Mar 12, 2026

Benchmarks

Benchmark execution time: 2026-03-13 21:33:34

Comparing candidate commit 4ff7e14 in PR branch eric.petzel/feature-flag-span-generation-tagging with baseline commit d1b3492 in branch master.

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

@petzel petzel changed the title feat: generate spans and root span tags for evaluated feature flags feat: tag span and trace with feature flag metadata Mar 12, 2026
@petzel petzel changed the title feat: tag span and trace with feature flag metadata feat: tag trace and current span with feature flag metadata Mar 12, 2026
@petzel petzel force-pushed the eric.petzel/feature-flag-span-generation-tagging branch from 1e6d409 to 0e5892d Compare March 13, 2026 21:24
@petzel petzel force-pushed the eric.petzel/feature-flag-span-generation-tagging branch from 0e5892d to 4ff7e14 Compare March 13, 2026 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant