Skip to content

feat(openfeature): improve exposure buffering - #9742

Open
leoromanovsky wants to merge 1 commit into
agent/openfeature-agentless-exposure-routingfrom
agent/openfeature-exposure-buffer-batching
Open

feat(openfeature): improve exposure buffering#9742
leoromanovsky wants to merge 1 commit into
agent/openfeature-agentless-exposure-routingfrom
agent/openfeature-exposure-buffer-batching

Conversation

@leoromanovsky

Copy link
Copy Markdown
Contributor

Stacked on #9741.

Motivation

Exposure buffering uses separate queues before and after route selection. The active writer also serializes events during append().

These paths have different capacity behavior. Payload overflow can also start a flush from the evaluation path.

Changes and Decisions

  • Use one bounded queue before and after route selection.
  • Retain the newest events when the queue reaches its capacity.
  • Log the capacity warning once and keep the full dropped-event count.
  • Defer serialization and size checks until flush.
  • Split buffered events into payload-size batches during flush.
  • Drop events that cannot be serialized or exceed an individual limit.
  • Schedule the startup drain on the next event loop turn.
  • Do not change discovery or route-selection policy.

Validation

The shared system-test contract ran locally against ec9d0a437.

  • Agent: TEST_LIBRARY=nodejs ./run.sh FEATURE_FLAGGING_AND_EXPERIMENTATION tests/ffe/test_exposure_egress.py passed one test.
  • Direct: TEST_LIBRARY=nodejs ./run.sh FEATURE_FLAGGING_AND_EXPERIMENTATION_AGENTLESS_DIRECT tests/ffe/test_exposure_egress.py passed one test.
  • Sidecar: TEST_LIBRARY=nodejs ./run.sh FEATURE_FLAGGING_AND_EXPERIMENTATION_AGENTLESS_SERVERLESS tests/ffe/test_exposure_egress.py passed one test with serverless-init:1.9.13.

@dd-octo-sts

dd-octo-sts Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Overall package size

Self size: 7.99 MB
Deduped: 8.77 MB
No deduping: 8.77 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.3.3 | 125.43 kB | 441.68 kB | | opentracing | 0.14.7 | 194.81 kB | 194.81 kB | | https-proxy-agent | 7.0.6 | 27.71 kB | 101.18 kB | | dc-polyfill | 0.1.11 | 25.74 kB | 25.74 kB | | proxy-from-env | 2.1.0 | 15.64 kB | 15.64 kB |

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

@pr-commenter

pr-commenter Bot commented Aug 9, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-08-09 18:07:46

Comparing candidate commit ec9d0a4 in PR branch agent/openfeature-exposure-buffer-batching with baseline commit 2ea4035 in branch agent/openfeature-agentless-exposure-routing.

📊 Benchmarking dashboard

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

Unstable benchmarks

These benchmarks have a confidence interval too wide to call a change; treat them as noise rather than signal.

scenario:appsec-appsec-enabled-24

  • unstable execution_time [-215.305ms; +209.295ms] or [-7.977%; +7.754%]

scenario:appsec-appsec-enabled-26

  • unstable execution_time [-225081.997µs; +226834.131µs] or [-8.720%; +8.787%]

scenario:appsec-appsec-enabled-with-attacks-24

  • unstable execution_time [-157545.914µs; +159158.814µs] or [-5.056%; +5.108%]

scenario:appsec-appsec-enabled-with-attacks-26

  • unstable execution_time [-185.448ms; +180.827ms] or [-6.325%; +6.168%]

scenario:appsec-control-20

  • unstable execution_time [-120.822ms; +133.695ms] or [-7.304%; +8.083%]

scenario:appsec-control-24

  • unstable execution_time [-112558.901µs; +112419.035µs] or [-8.987%; +8.976%]

scenario:appsec-control-26

  • unstable execution_time [-122.873ms; +125.599ms] or [-9.858%; +10.077%]

scenario:appsec-iast-no-vulnerability-control-20

  • unstable execution_time [-12908.721µs; +13644.027µs] or [-5.064%; +5.353%]

scenario:appsec-iast-no-vulnerability-iast-enabled-always-active-20

  • unstable execution_time [-14.828ms; +19.245ms] or [-5.629%; +7.305%]

scenario:appsec-iast-no-vulnerability-iast-enabled-default-config-20

  • unstable execution_time [-17.774ms; +22.344ms] or [-6.695%; +8.416%]

scenario:appsec-iast-with-vulnerability-iast-enabled-always-active-20

  • unstable execution_time [-29860.015µs; +30542.882µs] or [-5.407%; +5.531%]

scenario:child_process-shell-string-24

  • unstable execution_time [-20.010ms; +16.138ms] or [-6.091%; +4.913%]

scenario:debugger-line-probe-with-snapshot-minimal-24

  • unstable cpu_user_time [-1596.623ms; +592.473ms] or [-19.638%; +7.287%]
  • unstable execution_time [-1685.187ms; +629.877ms] or [-19.083%; +7.133%]
  • unstable instructions [-13.7G instructions; +4.9G instructions] or [-20.671%; +7.409%]
  • unstable throughput [-191.039op/s; +455.912op/s] or [-5.110%; +12.195%]

scenario:debugger-line-probe-without-snapshot-24

  • unstable cpu_user_time [-440.223ms; +511.056ms] or [-5.679%; +6.593%]
  • unstable execution_time [-419.463ms; +537.938ms] or [-4.973%; +6.377%]
  • unstable instructions [-4100.7M instructions; +4610.7M instructions] or [-6.532%; +7.344%]
  • unstable throughput [-223.569op/s; +187.232op/s] or [-5.863%; +4.910%]

scenario:dogstatsd-with-tags-20

  • unstable cpu_user_time [-475.789ms; +174.152ms] or [-9.924%; +3.632%]
  • unstable execution_time [-475.091ms; +177.988ms] or [-9.762%; +3.657%]
  • unstable throughput [-62718.954op/s; +169553.228op/s] or [-3.637%; +9.833%]

scenario:plugin-graphql-long-with-depth-and-collapse-off-20

  • unstable max_rss_usage [-27.554MB; +52.331MB] or [-6.776%; +12.870%]

scenario:plugin-graphql-long-with-depth-off-26

  • unstable max_rss_usage [-23009.154KB; +23560.012KB] or [-13.525%; +13.849%]

scenario:plugin-graphql-long-with-depth-on-max-20

  • unstable cpu_user_time [-601.326ms; +582.531ms] or [-5.206%; +5.043%]
  • unstable execution_time [-612.568ms; +585.813ms] or [-5.198%; +4.971%]
  • unstable throughput [-3.436op/s; +3.572op/s] or [-5.031%; +5.231%]

scenario:plugin-memcached-get-26

  • unstable cpu_user_time [-125.660ms; +200.397ms] or [-5.431%; +8.662%]
  • unstable execution_time [-122.412ms; +200.801ms] or [-5.135%; +8.423%]
  • unstable throughput [-1055684.691op/s; +636252.796op/s] or [-6.325%; +3.812%]

scenario:plugin-pg-service-20

  • unstable execution_time [-70.588ms; +114.152ms] or [-4.275%; +6.913%]

scenario:plugin-pg-service-26

  • unstable cpu_usage_percentage [-10.554%; +6.622%]
  • unstable execution_time [-100.758ms; +155.785ms] or [-11.112%; +17.181%]
  • unstable throughput [-747482.690op/s; +491442.978op/s] or [-11.053%; +7.267%]

scenario:test-optimization-large-suite-20

  • unstable max_rss_usage [-4038.005KB; +4144.005KB] or [-5.078%; +5.212%]

@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Aug 9, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 98.56% (+0.00%)

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

@codecov

codecov Bot commented Aug 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.56%. Comparing base (2ea4035) to head (ec9d0a4).

Additional details and impacted files
@@                               Coverage Diff                               @@
##           agent/openfeature-agentless-exposure-routing    #9742     +/-   ##
===============================================================================
  Coverage                                         98.56%   98.56%             
===============================================================================
  Files                                               970      970             
  Lines                                            139832   139902     +70     
  Branches                                          12047    13977   +1930     
===============================================================================
+ Hits                                             137826   137896     +70     
  Misses                                             2006     2006             
Flag Coverage Δ
aiguard 56.93% <ø> (ø)
aiguard-integration 55.85% <ø> (ø)
apm-bucket-0 57.17% <ø> (ø)
apm-bucket-1 63.31% <ø> (ø)
apm-bucket-2 62.16% <ø> (ø)
apm-bucket-3 59.74% <ø> (ø)
apm-capabilities-tracing 62.31% <ø> (ø)
apm-integrations-aerospike 56.21% <ø> (ø)
apm-integrations-confluentinc-kafka-javascript 61.10% <ø> (-0.04%) ⬇️
apm-integrations-couchbase 56.65% <ø> (ø)
apm-integrations-http 61.85% <ø> (ø)
apm-integrations-kafkajs 61.66% <ø> (ø)
apm-integrations-next 59.35% <ø> (ø)
apm-integrations-prisma 58.46% <ø> (ø)
appsec 72.07% <ø> (ø)
appsec-express_fastify_graphql 69.40% <ø> (ø)
appsec-integration 50.16% <ø> (-0.01%) ⬇️
appsec-kafka_ldapjs_lodash 63.37% <ø> (ø)
appsec-mongodb-core_mongoose_mysql 66.84% <ø> (ø)
appsec-next 56.61% <ø> (ø)
appsec-node-serialize_passport_postgres 66.25% <ø> (ø)
appsec-sourcing_stripe_template 64.67% <ø> (-0.01%) ⬇️
debugger 64.19% <ø> (ø)
instrumentations-bucket-0 51.64% <ø> (ø)
instrumentations-bucket-1 59.34% <ø> (ø)
instrumentations-bucket-10 60.83% <ø> (ø)
instrumentations-bucket-11 61.56% <ø> (ø)
instrumentations-bucket-12 51.65% <ø> (ø)
instrumentations-bucket-13 52.39% <ø> (ø)
instrumentations-bucket-14 51.60% <ø> (ø)
instrumentations-bucket-2 53.09% <ø> (ø)
instrumentations-bucket-3 53.45% <ø> (ø)
instrumentations-bucket-4 58.71% <ø> (ø)
instrumentations-bucket-5 50.26% <ø> (ø)
instrumentations-bucket-6 60.45% <ø> (ø)
instrumentations-bucket-7 58.05% <ø> (ø)
instrumentations-bucket-8 59.03% <ø> (ø)
instrumentations-bucket-9 57.39% <ø> (ø)
instrumentations-instrumentation-couchbase 50.90% <ø> (ø)
instrumentations-integration-esbuild 34.21% <ø> (ø)
llmobs-ai_anthropic_bedrock 62.80% <ø> (ø)
llmobs-bucket-1 61.31% <ø> (ø)
llmobs-openai 61.70% <ø> (ø)
llmobs-openai-agents_vertex-ai 59.98% <ø> (-0.01%) ⬇️
llmobs-sdk 66.74% <ø> (ø)
openfeature 56.00% <61.97%> (+<0.01%) ⬆️
openfeature-unit 53.92% <100.00%> (+0.07%) ⬆️
platform-core_esbuild_instrumentations-misc 41.22% <ø> (ø)
platform-integration 60.40% <ø> (ø)
platform-shimmer_unit-guardrails_webpack 38.88% <ø> (ø)
plugins-bucket-0 56.87% <ø> (ø)
plugins-bucket-1 54.00% <ø> (ø)
plugins-bucket-11 61.42% <ø> (ø)
plugins-bucket-17 61.24% <ø> (ø)
plugins-bucket-18 61.88% <ø> (ø)
plugins-bucket-19 61.26% <ø> (ø)
plugins-bucket-20 63.68% <ø> (ø)
plugins-bucket-4 58.26% <ø> (ø)
plugins-bullmq_cassandra_cookie 61.32% <ø> (ø)
plugins-cookie-parser_crypto_dd-trace-api 56.30% <ø> (ø)
plugins-fetch_fs_generic-pool 58.16% <ø> (ø)
plugins-google-cloud-pubsub_grpc_handlebars 64.10% <ø> (-0.01%) ⬇️
plugins-hapi_hono_ioredis 59.85% <ø> (ø)
plugins-knex_langgraph_ldapjs 55.01% <ø> (ø)
plugins-light-my-request_limitd-client_lodash 58.31% <ø> (-0.01%) ⬇️
plugins-mariadb_memcached_mercurius 61.25% <ø> (ø)
plugins-mongodb_mongodb-core_mongoose 59.21% <ø> (ø)
plugins-multer_mysql_mysql2 58.79% <ø> (ø)
plugins-nats_node-serialize_opensearch 60.34% <ø> (ø)
plugins-passport-http_pino_postgres 58.54% <ø> (ø)
plugins-process_pug_redis 57.34% <ø> (ø)
plugins-undici_url_valkey 57.97% <ø> (+0.03%) ⬆️
plugins-vm_winston_ws 59.54% <ø> (ø)
profiling 61.46% <ø> (+<0.01%) ⬆️
serverless-aws-sdk-aws-sdk 55.08% <ø> (ø)
serverless-aws-sdk-base-inject-field 50.88% <ø> (ø)
serverless-aws-sdk-bedrockruntime 54.61% <ø> (ø)
serverless-aws-sdk-client 56.17% <ø> (ø)
serverless-aws-sdk-dynamodb 55.44% <ø> (-0.01%) ⬇️
serverless-aws-sdk-eventbridge 49.68% <ø> (ø)
serverless-aws-sdk-kinesis 59.03% <ø> (ø)
serverless-aws-sdk-lambda 57.18% <ø> (ø)
serverless-aws-sdk-s3 55.54% <ø> (ø)
serverless-aws-sdk-serverless-peer-service 59.29% <ø> (ø)
serverless-aws-sdk-sns 59.84% <ø> (+<0.01%) ⬆️
serverless-aws-sdk-sqs 60.25% <ø> (ø)
serverless-aws-sdk-stepfunctions 55.37% <ø> (ø)
serverless-aws-sdk-util 51.41% <ø> (ø)
serverless-bucket-0 54.05% <ø> (ø)
serverless-bucket-1 58.80% <ø> (ø)
test-optimization-cucumber 71.05% <ø> (ø)
test-optimization-cypress 64.84% <ø> (+<0.01%) ⬆️
test-optimization-jest 72.41% <ø> (ø)
test-optimization-mocha 72.08% <ø> (-0.01%) ⬇️
test-optimization-playwright-playwright-atr 59.87% <ø> (ø)
test-optimization-playwright-playwright-efd 60.00% <ø> (ø)
test-optimization-playwright-playwright-final-status 60.16% <ø> (ø)
test-optimization-playwright-playwright-impacted-tests 59.70% <ø> (ø)
test-optimization-playwright-playwright-reporting 60.87% <ø> (-0.08%) ⬇️
test-optimization-playwright-playwright-test-management 60.68% <ø> (ø)
test-optimization-playwright-playwright-test-span 59.87% <ø> (ø)
test-optimization-selenium 59.06% <ø> (ø)
test-optimization-testopt 57.61% <ø> (ø)
test-optimization-vitest 73.29% <ø> (ø)
test-optimization-vitest-browser 58.94% <ø> (ø)
test-optimization-webdriverio 65.42% <ø> (ø)

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

☔ View full report in Codecov by Harness.
📢 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.

@leoromanovsky
leoromanovsky marked this pull request as ready for review August 10, 2026 01:21
@leoromanovsky
leoromanovsky requested a review from a team as a code owner August 10, 2026 01:21
@leoromanovsky
leoromanovsky requested review from dd-oleksii and pavlokhrebto and removed request for a team August 10, 2026 01:21

@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: ec9d0a4372

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

try {
eventSize = Buffer.byteLength(JSON.stringify(event))
} catch (error) {
log.warn('%s could not serialize an event, dropping event: %s', this.constructor.name, error.message)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Avoid rethrowing non-Error serialization failures

When an exposure or its subject.attributes has a toJSON/getter that throws null or undefined, this catch block immediately throws a new TypeError while reading error.message; because flush() also runs from the interval and beforeExit, that exception can escape into and crash the instrumented application instead of dropping the malformed event. Log the caught value without assuming it is an Error, including in the identical catch inside #send.

AGENTS.md reference: AGENTS.md:L222-L225

Useful? React with 👍 / 👎.

Comment on lines +103 to +104
if (this._buffer.length < this._bufferLimit) {
this._buffer.push(event)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Filter oversized events before occupying the bounded queue

Because size validation now happens only during flush(), events over the 1 MB limit still consume slots and replace valid older exposures in this ring. For example, if the queue contains 1,000 valid events and a synchronous burst of oversized evaluation contexts arrives before the timer runs, those invalid events evict the valid batch and are then themselves discarded during flushing, potentially delivering nothing; the count cap also no longer prevents a burst of large unique objects from consuming excessive memory. Oversized events must not be allowed to displace sendable entries in the bounded queue.

Useful? React with 👍 / 👎.

@dd-oleksii dd-oleksii 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.

I think the only user-facing change I question is preserving recent events. The rest of comments is just me struggling with the code

if (!this._dropWarningLogged) {
this._dropWarningLogged = true
log.warn(
'%s dropped exposure event(s) at cap %d. This may invalidate experiment results.',

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.

minor: exposure-specific logging in a potentially shared "base" writer. It doesn't look like it's actually shared, so maybe we should merge the two — this would make the interaction between BaseFFEWriter and ExposuresWriter easier to follow


/** @type {ExposureEvent[]} */
#pendingEvents = []
#routeResolved = false

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.

minor: #routeResolved is a confusing name and actually seems to mean something other than it says:

  1. route can be set in constructor but #routeResolved is not set here
  2. setEnabled can be called with empty/missing route but #routeResolved is set here regardless

The most accurate name for the field is #setEnabledCalled but maybe it should be #isInitializing or similar

Comment on lines +106 to +107
this._buffer[this._bufferStart] = event
this._bufferStart = (this._bufferStart + 1) % this._bufferLimit

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.

minor: is there a significant reason to prefer recent events? This seems to introduce more complexity and room for error.

Dropping newer events is also very slightly faster (because allocators optimize for young objects dying young).

continue
}

if (batch.length > 0 && this._payloadSizeLimit && batchSize + eventSize > this._payloadSizeLimit) {

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.

nitpick: the piece here looks like it would allow a single event to exceed the whole payload size limit (when batch.length === 0 && batchSize + eventSize > this._payloadSizeLimit).

batch.length > 0 could be removed because that's an impossible case. batchSize + eventSize > this._payloadSizeLimit implies batch is not empty

Suggested change
if (batch.length > 0 && this._payloadSizeLimit && batchSize + eventSize > this._payloadSizeLimit) {
if (this._payloadSizeLimit && batchSize + eventSize > this._payloadSizeLimit) {

continue
}

if (this._payloadSizeLimit && eventSize > this._payloadSizeLimit) {

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.

nitpick: I was a bit confused by two almost identical checks. One way to generalize this is to make sure that the event size limit is ≤ payload size limit (which should always be the case), so we can drop the second check.

In constructor:

if (this._payloadSizeLimit) {
  this._eventSizeLimit = Math.min(this._eventSizeLimit || Infinity, this._payloadSizeLimit)
}

this.constructor.name, PENDING_MAX_EVENTS)
}
}
super.append(events)

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.

major (🐛): the base writer will try to periodically flush these events, ignoring #enabled. If a flush attempt happens before setEnabled is called, this will likely lead to loosing events (or them going through?) — not the result we want in either case

EDIT: no, the flush is overridden to skip flush when #enabled is false. I hate implementation inheritance. This is another place where the flow is convoluted — merging two classes would simplify it

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.

2 participants