Skip to content

feat(openfeature): implement flag evaluation metrics#7993

Open
dd-oleksii wants to merge 1 commit intomasterfrom
oleksii/jj-lwzwlonrxrpr
Open

feat(openfeature): implement flag evaluation metrics#7993
dd-oleksii wants to merge 1 commit intomasterfrom
oleksii/jj-lwzwlonrxrpr

Conversation

@dd-oleksii
Copy link
Copy Markdown
Member

@dd-oleksii dd-oleksii commented Apr 14, 2026

What does this PR do?

Add an OpenFeature finally hook that emits a feature_flag.evaluations OTel counter for every flag evaluation, including error and short-circuit cases. The hook is a no-op when otelMetricsEnabled is false.

Motivation

FFL-1944

Additional Notes

Tested locally against system-tests and it passes except a couple of cases affected by FFL-2064.

@dd-oleksii dd-oleksii requested a review from a team as a code owner April 14, 2026 11:30
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 14, 2026

Overall package size

Self size: 5.5 MB
Deduped: 6.34 MB
No deduping: 6.34 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.0.1 | 82.56 kB | 817.39 kB | | dc-polyfill | 0.1.10 | 26.73 kB | 26.73 kB |

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

@datadog-prod-us1-5
Copy link
Copy Markdown

datadog-prod-us1-5 bot commented Apr 14, 2026

Tests

Fix all issues with BitsAI or with Cursor

⚠️ Other Violations

🧪 1 Test failed

Instrumentation promise with promise >=7 (7.0.0) "before all" hook for "should run the then() callbacks in the context where then() was called" from with promise >=7 (7.0.0)   View in Datadog   (Fix with Cursor)
Timeout of 5000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/home/runner/work/dd-trace-js/dd-trace-js/packages/datadog-instrumentations/test/promise.spec.js)

Error: Timeout of 5000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/home/runner/work/dd-trace-js/dd-trace-js/packages/datadog-instrumentations/test/promise.spec.js)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

ℹ️ Info

No other issues found (see more)

❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 21.88%
Overall Coverage: 67.98% (-0.04%)

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

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 14, 2026

Codecov Report

❌ Patch coverage is 24.13793% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.56%. Comparing base (91205a5) to head (873af1c).

Files with missing lines Patch % Lines
...ages/dd-trace/src/openfeature/eval-metrics-hook.js 22.22% 21 Missing ⚠️
...ages/dd-trace/src/openfeature/flagging_provider.js 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7993      +/-   ##
==========================================
- Coverage   73.60%   73.56%   -0.04%     
==========================================
  Files         773      774       +1     
  Lines       36083    36112      +29     
==========================================
+ Hits        26558    26565       +7     
- Misses       9525     9547      +22     
Flag Coverage Δ
aiguard-macos 36.53% <ø> (-0.09%) ⬇️
aiguard-ubuntu 36.64% <ø> (-0.09%) ⬇️
aiguard-windows 36.44% <ø> (-0.09%) ⬇️
apm-capabilities-tracing-macos 48.15% <24.13%> (-0.03%) ⬇️
apm-capabilities-tracing-ubuntu 48.18% <24.13%> (-0.03%) ⬇️
apm-capabilities-tracing-windows 47.96% <24.13%> (-0.03%) ⬇️
apm-integrations-child-process 36.16% <ø> (-0.10%) ⬇️
apm-integrations-couchbase-18 35.15% <ø> (-0.09%) ⬇️
apm-integrations-couchbase-eol 35.20% <ø> (-0.12%) ⬇️
apm-integrations-oracledb 35.20% <ø> (-0.09%) ⬇️
appsec-express 52.90% <ø> (-0.07%) ⬇️
appsec-fastify 49.38% <ø> (-0.07%) ⬇️
appsec-graphql 49.73% <ø> (+0.02%) ⬆️
appsec-kafka 42.16% <ø> (-0.08%) ⬇️
appsec-ldapjs 41.48% <ø> (-0.08%) ⬇️
appsec-lodash 41.51% <ø> (-0.08%) ⬇️
appsec-macos 56.82% <ø> (-0.07%) ⬇️
appsec-mongodb-core 46.11% <ø> (-0.07%) ⬇️
appsec-mongoose 46.71% <ø> (-0.07%) ⬇️
appsec-mysql 48.86% <ø> (-0.07%) ⬇️
appsec-node-serialize 40.69% <ø> (-0.08%) ⬇️
appsec-passport 44.68% <ø> (-0.08%) ⬇️
appsec-postgres 48.44% <ø> (-0.08%) ⬇️
appsec-sourcing 40.18% <ø> (-0.08%) ⬇️
appsec-stripe 42.40% <ø> (-0.08%) ⬇️
appsec-template 40.85% <ø> (-0.08%) ⬇️
appsec-ubuntu 56.90% <ø> (-0.07%) ⬇️
appsec-windows 56.69% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-bluebird 29.85% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-body-parser 37.76% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-child_process 35.54% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-cookie-parser 31.77% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-express 31.99% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-express-mongo-sanitize 31.90% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-express-session 37.39% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-fs 29.52% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-generic-pool 30.99% <ø> (ø)
instrumentations-instrumentation-http 36.99% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-knex 29.82% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-mongoose 30.93% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-multer 37.53% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-mysql2 35.51% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-passport 41.27% <ø> (-0.08%) ⬇️
instrumentations-instrumentation-passport-http 40.96% <ø> (-0.08%) ⬇️
instrumentations-instrumentation-passport-local 41.46% <ø> (-0.08%) ⬇️
instrumentations-instrumentation-pg 35.03% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-promise 29.78% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-promise-js 29.79% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-q 29.82% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-url 29.78% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-when 29.80% <ø> (-0.10%) ⬇️
llmobs-ai 38.47% <ø> (-0.09%) ⬇️
llmobs-anthropic 37.92% <ø> (-0.09%) ⬇️
llmobs-bedrock 37.17% <ø> (-0.08%) ⬇️
llmobs-google-genai 37.61% <ø> (-0.08%) ⬇️
llmobs-langchain 37.16% <ø> (-0.07%) ⬇️
llmobs-openai 41.29% <ø> (-0.08%) ⬇️
llmobs-vertex-ai 37.78% <ø> (-0.09%) ⬇️
platform-core 30.01% <ø> (ø)
platform-esbuild 32.83% <ø> (ø)
platform-instrumentations-misc 40.24% <ø> (ø)
platform-shimmer 35.73% <ø> (ø)
platform-unit-guardrails 31.38% <ø> (ø)
platform-webpack 20.83% <ø> (ø)
plugins-azure-durable-functions 25.21% <ø> (ø)
plugins-azure-event-hubs 25.36% <ø> (ø)
plugins-azure-service-bus 24.78% <ø> (ø)
plugins-bullmq 40.81% <ø> (+0.02%) ⬆️
plugins-cassandra 35.34% <ø> (-0.09%) ⬇️
plugins-cookie 26.33% <ø> (ø)
plugins-cookie-parser 26.14% <ø> (ø)
plugins-crypto 25.66% <ø> (ø)
plugins-dd-trace-api 35.47% <ø> (-0.10%) ⬇️
plugins-express-mongo-sanitize 26.28% <ø> (ø)
plugins-express-session 26.10% <ø> (ø)
plugins-fastify 39.44% <ø> (-0.09%) ⬇️
plugins-fetch 35.85% <ø> (-0.09%) ⬇️
plugins-fs 35.76% <ø> (-0.10%) ⬇️
plugins-generic-pool 25.25% <ø> (ø)
plugins-google-cloud-pubsub 43.12% <ø> (-0.08%) ⬇️
plugins-grpc 38.12% <ø> (-0.09%) ⬇️
plugins-handlebars 26.32% <ø> (ø)
plugins-hapi 37.36% <ø> (-0.09%) ⬇️
plugins-hono 37.60% <ø> (-0.09%) ⬇️
plugins-ioredis 35.80% <ø> (-0.09%) ⬇️
plugins-knex 26.01% <ø> (ø)
plugins-langgraph 35.15% <ø> (-0.09%) ⬇️
plugins-ldapjs 23.88% <ø> (ø)
plugins-light-my-request 25.75% <ø> (ø)
plugins-limitd-client 30.07% <ø> (-0.10%) ⬇️
plugins-lodash 25.33% <ø> (ø)
plugins-mariadb 36.67% <ø> (-0.14%) ⬇️
plugins-memcached 35.45% <ø> (-0.09%) ⬇️
plugins-microgateway-core 36.44% <ø> (-0.09%) ⬇️
plugins-moleculer 38.15% <ø> (-0.09%) ⬇️
plugins-mongodb 36.54% <ø> (-0.09%) ⬇️
plugins-mongodb-core 36.26% <ø> (-0.09%) ⬇️
plugins-mongoose 36.13% <ø> (-0.09%) ⬇️
plugins-multer 26.10% <ø> (ø)
plugins-mysql 36.54% <ø> (-0.09%) ⬇️
plugins-mysql2 36.52% <ø> (-0.09%) ⬇️
plugins-node-serialize 26.37% <ø> (ø)
plugins-opensearch 35.10% <ø> (-0.09%) ⬇️
plugins-passport-http 26.16% <ø> (ø)
plugins-postgres 34.49% <ø> (-0.09%) ⬇️
plugins-process 25.66% <ø> (ø)
plugins-pug 26.33% <ø> (ø)
plugins-redis 35.96% <ø> (-0.09%) ⬇️
plugins-router 40.01% <ø> (-0.09%) ⬇️
plugins-sequelize 25.03% <ø> (ø)
plugins-test-and-upstream-amqp10 35.77% <ø> (-0.09%) ⬇️
plugins-test-and-upstream-amqplib 40.96% <ø> (-0.09%) ⬇️
plugins-test-and-upstream-apollo 36.62% <ø> (-0.08%) ⬇️
plugins-test-and-upstream-avsc 35.62% <ø> (-0.09%) ⬇️
plugins-test-and-upstream-bunyan 31.22% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-connect 37.95% <ø> (-0.09%) ⬇️
plugins-test-and-upstream-graphql 37.30% <ø> (-0.09%) ⬇️
plugins-test-and-upstream-koa 37.56% <ø> (-0.09%) ⬇️
plugins-test-and-upstream-protobufjs 35.83% <ø> (-0.09%) ⬇️
plugins-test-and-upstream-rhea 41.07% <ø> (-0.07%) ⬇️
plugins-undici 36.63% <ø> (-0.09%) ⬇️
plugins-url 25.66% <ø> (ø)
plugins-valkey 35.35% <ø> (-0.22%) ⬇️
plugins-vm 25.66% <ø> (ø)
plugins-winston 31.65% <ø> (-0.09%) ⬇️
plugins-ws 39.08% <ø> (-0.09%) ⬇️
profiling-macos 38.03% <ø> (-0.09%) ⬇️
profiling-ubuntu 38.19% <ø> (-0.09%) ⬇️
profiling-windows 39.55% <ø> (-0.09%) ⬇️
serverless-azure-functions-client 25.10% <ø> (ø)
serverless-azure-functions-eventhubs 25.10% <ø> (ø)
serverless-azure-functions-servicebus 25.10% <ø> (ø)

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.

Copy link
Copy Markdown

@sameerank sameerank left a comment

Choose a reason for hiding this comment

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

FYI we are currently ignoring this following system test for node: Test_FFE_Eval_Targeting_Key_Optional

https://github.com/DataDog/system-tests/blob/7d79f7af78d86a8e43723e6c27854ca368cfd70c/manifests/nodejs.yml#L1579

At some point we may want to think about making it match the other tracers

Comment thread packages/dd-trace/src/openfeature/eval-metrics-hook.js
Comment thread packages/dd-trace/src/openfeature/eval-metrics-hook.js
@dd-oleksii
Copy link
Copy Markdown
Member Author

FYI we are currently ignoring this following system test for node: Test_FFE_Eval_Targeting_Key_Optional

Yeah. My understanding is that this should have been fixed in FFL-1730 but it was not

if (this.#counter) return this.#counter

try {
const { metrics } = require('@opentelemetry/api')
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.

This would mean there is now a hard dependency from OpenFeature to OpenTelemetry. Can the API be done in a way that they can be externally combined instead?

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.

This code is only evaluated when otel is enabled, so it is a soft dependency — not a hard one.

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.

Heads up. This comment is the last thing blocking the merge and @rochdev is unresponsive on both github and slack.

FFE team's current consensus is that it is a misreading of the code and does not warrant the block. We also use the same approach in Go, Java, Python, and .NET tracers.

I'm dismissing the review to unblock the progress. I'll wait for Monday eve before merging unless I hear any objections 🙏

@dd-oleksii dd-oleksii requested a review from rochdev April 16, 2026 11:31
Add an OpenFeature `finally` hook that emits a `feature_flag.evaluations`
OTel counter for every flag evaluation, including error and short-circuit
cases. The hook is a no-op when `otelMetricsEnabled` is false.
@dd-oleksii dd-oleksii force-pushed the oleksii/jj-lwzwlonrxrpr branch from 7605a55 to 873af1c Compare April 16, 2026 11:59
@dd-oleksii dd-oleksii requested a review from a team as a code owner April 16, 2026 11:59
@dd-oleksii dd-oleksii requested review from greghuels and leoromanovsky and removed request for a team April 16, 2026 11:59
@dd-oleksii
Copy link
Copy Markdown
Member Author

(rebased on latest master to run system-tests)

@pr-commenter
Copy link
Copy Markdown

pr-commenter bot commented Apr 16, 2026

Benchmarks

Benchmark execution time: 2026-04-16 12:16:52

Comparing candidate commit 873af1c in PR branch oleksii/jj-lwzwlonrxrpr with baseline commit 91205a5 in branch master.

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

Copy link
Copy Markdown
Contributor

@leoromanovsky leoromanovsky left a comment

Choose a reason for hiding this comment

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

Solid tests.

@dd-oleksii dd-oleksii dismissed rochdev’s stale review April 17, 2026 20:07

This comment is the last thing blocking the merge and @rochdev is unresponsive on both github and slack.

FFE team's current consensus is that it is a misreading of the code and does not warrant the block. We also use the same approach in Go, Java, Python, and .NET tracers.

I'm dismissing the review to unblock the progress. I'll wait for Monday eve before merging unless I hear any objections 🙏

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.

4 participants