dd-trace 5.134.0 → 5.135.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE-3rdparty.csv +0 -1
- package/ci/cypress/support.js +15 -1
- package/ci/diagnose.js +4 -4
- package/ci/test-annotations.d.ts +5 -0
- package/ci/test-annotations.js +5 -0
- package/ci/test-optimization-validation/approval-artifacts.js +2 -2
- package/ci/test-optimization-validation/approval.js +2 -2
- package/ci/test-optimization-validation/artifact-id.js +2 -3
- package/ci/test-optimization-validation/ci-package-scripts.js +1 -1
- package/ci/test-optimization-validation/cli.js +1 -1
- package/ci/test-optimization-validation/command-runner.js +2 -3
- package/ci/test-optimization-validation/executable.js +1 -1
- package/ci/test-optimization-validation/framework-adapters/cucumber.js +1 -1
- package/ci/test-optimization-validation/literal-environment.js +2 -2
- package/ci/test-optimization-validation/manifest-scaffold.js +1 -1
- package/ci/test-optimization-validation/offline-fixtures.js +1 -1
- package/ci/test-optimization-validation/redaction.js +3 -3
- package/ci/test-optimization-validation/runner-contract.js +10 -10
- package/ci/test-optimization-validation/scenarios/ci-wiring.js +1 -1
- package/ci/vitest-no-worker-init-annotations.mjs +4 -0
- package/ci/vitest-no-worker-init-node-setup.mjs +22 -0
- package/ci/vitest-no-worker-init-runner-setup.mjs +7 -32
- package/ci/vitest-no-worker-init-setup.mjs +34 -12
- package/ci/vitest-no-worker-init-v5-setup.mjs +6 -0
- package/ext/exporters.js +1 -0
- package/index.d.ts +19 -0
- package/loader-hook.mjs +53 -0
- package/openfeature/exposure-hook.d.ts +66 -0
- package/openfeature/exposure-hook.js +5 -0
- package/package.json +11 -9
- package/packages/datadog-core/src/storage.js +1 -1
- package/packages/datadog-esbuild/index.js +70 -7
- package/packages/datadog-instrumentations/src/cucumber.js +53 -19
- package/packages/datadog-instrumentations/src/cypress-config.js +163 -15
- package/packages/datadog-instrumentations/src/graphql.js +9 -3
- package/packages/datadog-instrumentations/src/grpc/server.js +23 -6
- package/packages/datadog-instrumentations/src/helpers/fetch.js +5 -1
- package/packages/datadog-instrumentations/src/helpers/graphql-jit-runtime.js +30 -8
- package/packages/datadog-instrumentations/src/helpers/hooks.js +1 -1
- package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +16 -6
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentation-registry.js +8 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql-jit.js +3 -1
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/react-router.js +49 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/typesafe.js +23 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/webdriverio.js +12 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/target-patterns.json +8 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/targets.js +19 -2
- package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +8 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +1 -1
- package/packages/datadog-instrumentations/src/jest.js +265 -82
- package/packages/datadog-instrumentations/src/mariadb-bundle.js +69 -11
- package/packages/datadog-instrumentations/src/mariadb.js +13 -6
- package/packages/datadog-instrumentations/src/mocha/common.js +89 -8
- package/packages/datadog-instrumentations/src/mocha/main.js +11 -2
- package/packages/datadog-instrumentations/src/mocha/utils.js +58 -12
- package/packages/datadog-instrumentations/src/mocha/worker.js +1 -1
- package/packages/datadog-instrumentations/src/oracledb.js +33 -0
- package/packages/datadog-instrumentations/src/pg.js +2 -1
- package/packages/datadog-instrumentations/src/playwright.js +81 -28
- package/packages/datadog-instrumentations/src/react-router.js +106 -0
- package/packages/datadog-instrumentations/src/typesafe.js +89 -0
- package/packages/datadog-instrumentations/src/vitest-main-no-worker-init.js +84 -48
- package/packages/datadog-instrumentations/src/vitest-main.js +26 -0
- package/packages/datadog-instrumentations/src/vitest-test-annotations.js +20 -0
- package/packages/datadog-instrumentations/src/vitest-worker.js +39 -17
- package/packages/datadog-instrumentations/src/vitest.js +10 -8
- package/packages/datadog-plugin-cucumber/src/index.js +5 -0
- package/packages/datadog-plugin-cypress/src/cypress-plugin.js +274 -44
- package/packages/datadog-plugin-cypress/src/index.js +1 -1
- package/packages/datadog-plugin-cypress/src/lifecycle-owner.js +20 -0
- package/packages/datadog-plugin-cypress/src/plugin.js +10 -0
- package/packages/datadog-plugin-cypress/src/retry-config-observer.js +281 -0
- package/packages/datadog-plugin-cypress/src/setup-handoff.js +125 -0
- package/packages/datadog-plugin-cypress/src/support.js +1217 -439
- package/packages/datadog-plugin-graphql/src/execute.js +2 -2
- package/packages/datadog-plugin-graphql/src/utils.js +5 -5
- package/packages/datadog-plugin-jest/src/index.js +25 -3
- package/packages/datadog-plugin-mocha/src/index.js +47 -6
- package/packages/datadog-plugin-oracledb/src/connection-parser.js +21 -11
- package/packages/datadog-plugin-playwright/src/index.js +4 -0
- package/packages/datadog-plugin-react-router/src/index.js +118 -0
- package/packages/datadog-plugin-typesafe/src/index.js +17 -0
- package/packages/datadog-plugin-typesafe/src/tracing.js +31 -0
- package/packages/datadog-plugin-vitest/src/index.js +8 -0
- package/packages/dd-trace/src/agent/info.js +2 -1
- package/packages/dd-trace/src/aiguard/sdk.js +0 -11
- package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +9 -16
- package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +4 -2
- package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +9 -16
- package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +9 -14
- package/packages/dd-trace/src/ci-visibility/requests/route.js +44 -0
- package/packages/dd-trace/src/ci-visibility/telemetry-logs.js +5 -0
- package/packages/dd-trace/src/ci-visibility/test-annotations.js +72 -0
- package/packages/dd-trace/src/ci-visibility/test-declaration-annotations.js +170 -0
- package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +9 -16
- package/packages/dd-trace/src/config/defaults.js +4 -3
- package/packages/dd-trace/src/config/generated-config-types.d.ts +4 -0
- package/packages/dd-trace/src/config/index.js +95 -39
- package/packages/dd-trace/src/config/parsers.js +9 -1
- package/packages/dd-trace/src/config/supported-configurations.json +16 -0
- package/packages/dd-trace/src/debugger/probe_sampler.js +6 -6
- package/packages/dd-trace/src/encode/0.4.js +2 -2
- package/packages/dd-trace/src/esm-module-load.js +58 -0
- package/packages/dd-trace/src/exporter.js +25 -6
- package/packages/dd-trace/src/exporters/agent/index.js +3 -1
- package/packages/dd-trace/src/exporters/agentless/index.js +3 -1
- package/packages/dd-trace/src/exporters/common/request.js +4 -4
- package/packages/dd-trace/src/exporters/llmobs/index.js +135 -0
- package/packages/dd-trace/src/exporters/log/index.js +4 -3
- package/packages/dd-trace/src/llmobs/constants/tags.js +1 -0
- package/packages/dd-trace/src/llmobs/experiments/index.js +2 -3
- package/packages/dd-trace/src/llmobs/experiments/noop.js +5 -2
- package/packages/dd-trace/src/llmobs/index.js +13 -2
- package/packages/dd-trace/src/llmobs/plugins/claude-agent-sdk/index.js +1 -1
- package/packages/dd-trace/src/llmobs/plugins/genai/index.js +1 -1
- package/packages/dd-trace/src/llmobs/plugins/genai/util.js +8 -4
- package/packages/dd-trace/src/llmobs/plugins/typesafe/index.js +102 -0
- package/packages/dd-trace/src/llmobs/prompts/cache.js +3 -1
- package/packages/dd-trace/src/llmobs/sdk.js +2 -1
- package/packages/dd-trace/src/llmobs/span_processor.js +210 -12
- package/packages/dd-trace/src/llmobs/tagger.js +3 -0
- package/packages/dd-trace/src/llmobs/writers/util.js +3 -3
- package/packages/dd-trace/src/log/writer.js +7 -1
- package/packages/dd-trace/src/openfeature/agentless_configuration_source.js +64 -6
- package/packages/dd-trace/src/openfeature/configuration_source.js +18 -2
- package/packages/dd-trace/src/openfeature/debug-logging-hook.js +66 -3
- package/packages/dd-trace/src/openfeature/exposure-hook.js +185 -0
- package/packages/dd-trace/src/openfeature/flagging_provider.js +39 -13
- package/packages/dd-trace/src/openfeature/remote_config.js +16 -3
- package/packages/dd-trace/src/openfeature/writers/base.js +62 -27
- package/packages/dd-trace/src/openfeature/writers/exposures.js +161 -1
- package/packages/dd-trace/src/openfeature/writers/flag-eval-evp-hook.js +5 -0
- package/packages/dd-trace/src/openfeature/writers/flag-evaluation-aggregation.js +9 -4
- package/packages/dd-trace/src/openfeature/writers/flag-evaluation-payload.js +2 -0
- package/packages/dd-trace/src/openfeature/writers/flag-evaluation-pii.js +2 -0
- package/packages/dd-trace/src/openfeature/writers/split-features.js +25 -0
- package/packages/dd-trace/src/opentelemetry/metrics/periodic_metric_reader.js +2 -2
- package/packages/dd-trace/src/opentelemetry/tracer_provider.js +5 -1
- package/packages/dd-trace/src/opentracing/tracer.js +9 -13
- package/packages/dd-trace/src/otel-thread-ctx.js +47 -21
- package/packages/dd-trace/src/plugins/ci_plugin.js +4 -4
- package/packages/dd-trace/src/plugins/index.js +3 -0
- package/packages/dd-trace/src/plugins/tracing.js +1 -1
- package/packages/dd-trace/src/plugins/util/git.js +11 -5
- package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +2 -4
- package/packages/dd-trace/src/plugins/util/test.js +26 -6
- package/packages/dd-trace/src/plugins/util/web.js +16 -0
- package/packages/dd-trace/src/process-tags/index.js +1 -1
- package/packages/dd-trace/src/profiling/config.js +6 -3
- package/packages/dd-trace/src/proxy.js +15 -4
- package/packages/dd-trace/src/serverless.js +3 -2
- package/packages/dd-trace/src/span_processor.js +21 -9
- package/packages/dd-trace/src/span_stats.js +28 -2
- package/packages/dd-trace/src/startup-log.js +2 -1
- package/packages/dd-trace/src/tagger.js +7 -5
- package/packages/dd-trace/src/telemetry/dependencies.js +4 -0
- package/packages/dd-trace/src/telemetry/index.js +3 -0
- package/packages/dd-trace/src/telemetry/logs/index.js +21 -2
- package/packages/dd-trace/src/telemetry/logs/log-collector.js +1 -0
- package/packages/dd-trace/src/telemetry/telemetry.js +10 -3
- package/packages/dd-trace/src/util.js +1 -1
- package/register.js +2 -1
- package/vendor/dist/@datadog/openfeature-node-server/index.js +1 -1
- package/vendor/dist/@datadog/openfeature-node-server/rules-based/index.d.ts +78 -0
- package/vendor/dist/@datadog/openfeature-node-server/rules-based/index.js +1 -1
- package/vendor/dist/@opentelemetry/core/index.js +1 -1
- package/vendor/dist/@opentelemetry/resources/LICENSE +0 -201
- package/vendor/dist/@opentelemetry/resources/index.js +0 -1
|
@@ -143,7 +143,14 @@ class BaseFFEWriter {
|
|
|
143
143
|
continue
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
-
|
|
146
|
+
let eventSizeBytes
|
|
147
|
+
try {
|
|
148
|
+
eventSizeBytes = Buffer.byteLength(JSON.stringify(event))
|
|
149
|
+
} catch {
|
|
150
|
+
log.warn('%s could not serialize an event, dropping event', this.constructor.name)
|
|
151
|
+
this._droppedEvents++
|
|
152
|
+
continue
|
|
153
|
+
}
|
|
147
154
|
|
|
148
155
|
// Check individual event size limit if configured
|
|
149
156
|
if (this._eventSizeLimit && eventSizeBytes > this._eventSizeLimit) {
|
|
@@ -175,7 +182,14 @@ class BaseFFEWriter {
|
|
|
175
182
|
this._buffer = []
|
|
176
183
|
this._bufferSize = 0
|
|
177
184
|
|
|
178
|
-
|
|
185
|
+
let payload
|
|
186
|
+
try {
|
|
187
|
+
payload = this._encode(this.makePayload(events))
|
|
188
|
+
} catch {
|
|
189
|
+
log.warn('%s could not encode %d events, dropping batch', this.constructor.name, events.length)
|
|
190
|
+
this._droppedEvents += events.length
|
|
191
|
+
return
|
|
192
|
+
}
|
|
179
193
|
|
|
180
194
|
// Keep byte counting behind the debug callback because payloads can be several megabytes.
|
|
181
195
|
// eslint-disable-next-line eslint-rules/eslint-log-printf-style
|
|
@@ -198,14 +212,19 @@ class BaseFFEWriter {
|
|
|
198
212
|
*/
|
|
199
213
|
destroy () {
|
|
200
214
|
if (this.#destroyer) {
|
|
201
|
-
log.debug('
|
|
215
|
+
log.debug('%s stopping with %d buffered events; final flush requested without awaiting delivery',
|
|
216
|
+
this.constructor.name, this._buffer.length)
|
|
202
217
|
clearInterval(this._periodic)
|
|
203
218
|
this.flush()
|
|
204
219
|
globalThis[Symbol.for('dd-trace')].beforeExitHandlers.delete(this.#destroyer)
|
|
205
220
|
this.#destroyer = undefined
|
|
206
221
|
|
|
207
222
|
if (this._droppedEvents > 0) {
|
|
208
|
-
log.warn(
|
|
223
|
+
log.warn(
|
|
224
|
+
'%s dropped %d events (buffer capacity, size limits, serialization or delivery failures)',
|
|
225
|
+
this.constructor.name,
|
|
226
|
+
this._droppedEvents
|
|
227
|
+
)
|
|
209
228
|
}
|
|
210
229
|
}
|
|
211
230
|
}
|
|
@@ -313,13 +332,14 @@ class BaseFFEWriter {
|
|
|
313
332
|
// The request helper mutates headers. Concurrent envelopes must not share them.
|
|
314
333
|
const requestOptions = { ...route.requestOptions, headers: { ...route.requestOptions.headers } }
|
|
315
334
|
request(payload, requestOptions, (error, response, statusCode) => {
|
|
316
|
-
const errorMessage = error && (this.#formatError
|
|
335
|
+
const errorMessage = error && (this.#formatError
|
|
336
|
+
? this.#formatError(error, statusCode)
|
|
337
|
+
: error.message)
|
|
317
338
|
if (fallbackRoute && isSafeToReplay(error, statusCode)) {
|
|
318
339
|
log.debug(
|
|
319
|
-
'%s switching from %s
|
|
340
|
+
'%s switching from %s to direct intake after definitive rejection',
|
|
320
341
|
this.constructor.name,
|
|
321
|
-
route.url.
|
|
322
|
-
route.endpoint
|
|
342
|
+
route.url.origin
|
|
323
343
|
)
|
|
324
344
|
if (this._requestOptions === route.requestOptions) {
|
|
325
345
|
this.#activateRoute(fallbackRoute)
|
|
@@ -332,27 +352,25 @@ class BaseFFEWriter {
|
|
|
332
352
|
|
|
333
353
|
if (fallbackRoute && isTransportFailure(error, statusCode)) {
|
|
334
354
|
log.debug(
|
|
335
|
-
'%s switching future batches from %s
|
|
355
|
+
'%s switching future batches from %s to direct intake after an ambiguous failure without replay',
|
|
336
356
|
this.constructor.name,
|
|
337
|
-
route.url.
|
|
338
|
-
route.endpoint
|
|
357
|
+
route.url.origin
|
|
339
358
|
)
|
|
340
359
|
if (this._requestOptions === route.requestOptions) {
|
|
341
360
|
this.#activateRoute(fallbackRoute)
|
|
342
361
|
this._fallbackRoute = undefined
|
|
343
362
|
route.onFallback?.()
|
|
344
363
|
}
|
|
345
|
-
|
|
364
|
+
this.#logDropped(route, eventCount, error, errorMessage, statusCode)
|
|
346
365
|
onComplete?.(false)
|
|
347
366
|
return
|
|
348
367
|
}
|
|
349
368
|
|
|
350
369
|
if (fallbackRoute && shouldSwitchFutureRoute(statusCode)) {
|
|
351
370
|
log.debug(
|
|
352
|
-
'%s switching future batches from %s
|
|
371
|
+
'%s switching future batches from %s to direct intake after status %d without replay',
|
|
353
372
|
this.constructor.name,
|
|
354
|
-
route.url.
|
|
355
|
-
route.endpoint,
|
|
373
|
+
route.url.origin,
|
|
356
374
|
statusCode
|
|
357
375
|
)
|
|
358
376
|
if (this._requestOptions === route.requestOptions) {
|
|
@@ -360,7 +378,7 @@ class BaseFFEWriter {
|
|
|
360
378
|
this._fallbackRoute = undefined
|
|
361
379
|
route.onFallback?.()
|
|
362
380
|
}
|
|
363
|
-
|
|
381
|
+
this.#logDropped(route, eventCount, error, errorMessage, statusCode)
|
|
364
382
|
onComplete?.(false)
|
|
365
383
|
return
|
|
366
384
|
}
|
|
@@ -374,25 +392,42 @@ class BaseFFEWriter {
|
|
|
374
392
|
shouldSwitchFutureRoute(statusCode))
|
|
375
393
|
) {
|
|
376
394
|
route.onUnavailable()
|
|
377
|
-
|
|
378
|
-
log.error('Failed to send events to %s%s: %s', route.url.href, route.endpoint, errorMessage)
|
|
379
|
-
} else {
|
|
380
|
-
log.warn('Events request returned status %d', statusCode)
|
|
381
|
-
}
|
|
395
|
+
this.#logDropped(route, eventCount, error, errorMessage, statusCode)
|
|
382
396
|
onComplete?.(false)
|
|
383
397
|
return
|
|
384
398
|
}
|
|
385
399
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
400
|
+
const delivered = !error && statusCode >= 200 && statusCode < 300
|
|
401
|
+
if (delivered) {
|
|
402
|
+
log.debug('%s accepted %d events at %s (%s, status %d); downstream delivery is not observed',
|
|
403
|
+
this.constructor.name, eventCount, route.url.origin,
|
|
404
|
+
// An Agent URL path prefix precedes the EVP path, so the route type cannot be read from its start.
|
|
405
|
+
route.endpoint.includes('/evp_proxy/') ? 'Agent/local EVP handoff' : 'HTTP receiver', statusCode)
|
|
390
406
|
} else {
|
|
391
|
-
|
|
407
|
+
this.#logDropped(route, eventCount, error, errorMessage, statusCode)
|
|
392
408
|
}
|
|
393
|
-
onComplete?.(
|
|
409
|
+
onComplete?.(delivered)
|
|
394
410
|
})
|
|
395
411
|
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Batches are not retried after a failed final attempt, so the failure log states the loss.
|
|
415
|
+
*
|
|
416
|
+
* @param {ActiveWriterRoute} route - Route that failed
|
|
417
|
+
* @param {number} eventCount - Event count in the dropped batch
|
|
418
|
+
* @param {Error | null} error - Request error
|
|
419
|
+
* @param {string | null | undefined} errorMessage - Redacted request error
|
|
420
|
+
* @param {number | undefined} statusCode - HTTP response status
|
|
421
|
+
*/
|
|
422
|
+
#logDropped (route, eventCount, error, errorMessage, statusCode) {
|
|
423
|
+
if (error) {
|
|
424
|
+
log.error('%s failed to send %d events to %s (status=%s, cause=%s); events dropped',
|
|
425
|
+
this.constructor.name, eventCount, route.url.origin, statusCode ?? 'none', errorMessage)
|
|
426
|
+
} else {
|
|
427
|
+
log.warn('%s events request to %s returned status %d; %d events were dropped',
|
|
428
|
+
this.constructor.name, route.url.origin, statusCode, eventCount)
|
|
429
|
+
}
|
|
430
|
+
}
|
|
396
431
|
}
|
|
397
432
|
|
|
398
433
|
module.exports = BaseFFEWriter
|
|
@@ -12,12 +12,16 @@ const {
|
|
|
12
12
|
} = require('../../evp_proxy/constants')
|
|
13
13
|
const { joinEVPProxyPath } = require('../../evp_proxy/path')
|
|
14
14
|
const log = require('../../log')
|
|
15
|
+
const { snapshotFeatures } = require('./split-features')
|
|
15
16
|
const BaseFFEWriter = require('./base')
|
|
16
17
|
|
|
17
18
|
// Disabled-state cap. Drops invalidate experiment results because the provider's
|
|
18
19
|
// exposure dedupe cache keeps masking dropped events after recovery. The first
|
|
19
20
|
// drop emits a warning and `droppedEventCount` accumulates the cumulative loss.
|
|
20
21
|
const PENDING_MAX_EVENTS = 1000
|
|
22
|
+
// Include the in-flight batch in both budgets. Leave headroom in the shared 64 MiB request buffer.
|
|
23
|
+
const DELIVERY_MAX_BYTES = 16 * 1024 * 1024
|
|
24
|
+
const DELIVERY_MAX_BATCHES = 1000
|
|
21
25
|
|
|
22
26
|
/**
|
|
23
27
|
* @typedef {object} ExposureRoute
|
|
@@ -39,6 +43,7 @@ const PENDING_MAX_EVENTS = 1000
|
|
|
39
43
|
* @property {string} flag.key - Flag key
|
|
40
44
|
* @property {object} variant - Variant information
|
|
41
45
|
* @property {string} variant.key - Variant key
|
|
46
|
+
* @property {Record<string, string | number | boolean>} [features]
|
|
42
47
|
* @property {number} [serial_id] - Serial id of the split the subject landed in
|
|
43
48
|
* @property {object} subject - Subject (user/entity) information
|
|
44
49
|
* @property {string} subject.id - Subject identifier
|
|
@@ -73,6 +78,19 @@ class ExposuresWriter extends BaseFFEWriter {
|
|
|
73
78
|
#context
|
|
74
79
|
|
|
75
80
|
#dropWarned = false
|
|
81
|
+
#deliveryWarned = false
|
|
82
|
+
#closed = false
|
|
83
|
+
#appendDepth = 0
|
|
84
|
+
#inFlight = false
|
|
85
|
+
#deliveryBytes = 0
|
|
86
|
+
#deliveryCount = 0
|
|
87
|
+
/** @type {{ payload: string, eventCount: number, bytes: number }[]} */
|
|
88
|
+
#deliveryQueue = []
|
|
89
|
+
/** @type {ReturnType<typeof setTimeout> | undefined} */
|
|
90
|
+
#deliveryTimer
|
|
91
|
+
#shutdownDeadline = Infinity
|
|
92
|
+
/** @type {ReturnType<typeof setTimeout> | undefined} */
|
|
93
|
+
#shutdownTimer
|
|
76
94
|
|
|
77
95
|
/**
|
|
78
96
|
* @param {import('../../config/config-base')} config - Tracer configuration object
|
|
@@ -91,6 +109,10 @@ class ExposuresWriter extends BaseFFEWriter {
|
|
|
91
109
|
payloadSizeLimit: EVP_PAYLOAD_SIZE_LIMIT,
|
|
92
110
|
eventSizeLimit: EVP_EVENT_SIZE_LIMIT,
|
|
93
111
|
headers,
|
|
112
|
+
// Request errors can echo credentials in the URL or response body.
|
|
113
|
+
formatError: (error, statusCode) => statusCode === undefined
|
|
114
|
+
? /** @type {{ code?: string }} */ (error).code ?? 'UNKNOWN'
|
|
115
|
+
: 'none',
|
|
94
116
|
})
|
|
95
117
|
|
|
96
118
|
if (route.agent || route.fallback) {
|
|
@@ -118,6 +140,14 @@ class ExposuresWriter extends BaseFFEWriter {
|
|
|
118
140
|
* @param {ExposureRoute} [route] - Selected EVP route
|
|
119
141
|
*/
|
|
120
142
|
setEnabled (enabled, route) {
|
|
143
|
+
if (this.#closed) {
|
|
144
|
+
// An outstanding request may discover unavailability during shutdown.
|
|
145
|
+
if (!enabled) {
|
|
146
|
+
this.#enabled = false
|
|
147
|
+
this.#discardDelivery()
|
|
148
|
+
}
|
|
149
|
+
return
|
|
150
|
+
}
|
|
121
151
|
if (route) {
|
|
122
152
|
this.#setRoute(route)
|
|
123
153
|
}
|
|
@@ -125,10 +155,14 @@ class ExposuresWriter extends BaseFFEWriter {
|
|
|
125
155
|
this.#enabled = enabled
|
|
126
156
|
|
|
127
157
|
if (enabled && this.#pendingEvents.length > 0) {
|
|
158
|
+
log.debug('%s exposure delivery enabled; queueing %d pending exposure event(s)',
|
|
159
|
+
this.constructor.name, this.#pendingEvents.length)
|
|
128
160
|
// Flush all pending events as a batch
|
|
129
161
|
super.append(this.#pendingEvents)
|
|
130
162
|
this.#pendingEvents = []
|
|
131
163
|
}
|
|
164
|
+
if (enabled) this.#scheduleDelivery()
|
|
165
|
+
else this.#cancelDelivery()
|
|
132
166
|
}
|
|
133
167
|
|
|
134
168
|
/**
|
|
@@ -162,8 +196,14 @@ class ExposuresWriter extends BaseFFEWriter {
|
|
|
162
196
|
* @param {ExposureEvent|ExposureEvent[]} events - Exposure event(s) to append
|
|
163
197
|
*/
|
|
164
198
|
append (events) {
|
|
199
|
+
if (this.#closed) return
|
|
165
200
|
if (this.#enabled) {
|
|
166
|
-
|
|
201
|
+
this.#appendDepth++
|
|
202
|
+
try {
|
|
203
|
+
super.append(events)
|
|
204
|
+
} finally {
|
|
205
|
+
this.#appendDepth--
|
|
206
|
+
}
|
|
167
207
|
return
|
|
168
208
|
}
|
|
169
209
|
|
|
@@ -194,6 +234,123 @@ class ExposuresWriter extends BaseFFEWriter {
|
|
|
194
234
|
return
|
|
195
235
|
}
|
|
196
236
|
super.flush()
|
|
237
|
+
// Explicit, periodic and shutdown flushes may start delivery immediately.
|
|
238
|
+
// A byte-triggered flush during append must never initiate transport inline.
|
|
239
|
+
if (this.#appendDepth === 0) this.#drainDelivery()
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
destroy () {
|
|
243
|
+
if (this.#closed) return
|
|
244
|
+
this.#closed = true
|
|
245
|
+
this.#shutdownDeadline = Date.now() + this._timeout
|
|
246
|
+
this.#shutdownTimer = setTimeout(() => {
|
|
247
|
+
this.#shutdownTimer = undefined
|
|
248
|
+
this.#expireShutdown()
|
|
249
|
+
}, this._timeout)
|
|
250
|
+
this.#shutdownTimer.unref?.()
|
|
251
|
+
if (!this.#enabled) {
|
|
252
|
+
const undelivered = this.#pendingEvents.length + this._buffer.length
|
|
253
|
+
if (undelivered > 0) {
|
|
254
|
+
log.warn('%s dropped %d exposure event(s) at shutdown because exposure delivery was not enabled',
|
|
255
|
+
this.constructor.name, undelivered)
|
|
256
|
+
}
|
|
257
|
+
this._droppedEvents += undelivered
|
|
258
|
+
this.#pendingEvents = []
|
|
259
|
+
this._buffer = []
|
|
260
|
+
this._bufferSize = 0
|
|
261
|
+
this.#discardDelivery()
|
|
262
|
+
}
|
|
263
|
+
super.destroy()
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Queues an encoded exposure batch, keeping accepted batches when capacity is exhausted.
|
|
268
|
+
* @param {string} payload - Encoded payload
|
|
269
|
+
* @param {number} eventCount - Number of exposures
|
|
270
|
+
*/
|
|
271
|
+
_sendPayload (payload, eventCount) {
|
|
272
|
+
const bytes = Buffer.byteLength(payload)
|
|
273
|
+
if (this.#deliveryBytes + bytes > DELIVERY_MAX_BYTES || this.#deliveryCount >= DELIVERY_MAX_BATCHES) {
|
|
274
|
+
this._droppedEvents += eventCount
|
|
275
|
+
if (!this.#deliveryWarned) {
|
|
276
|
+
this.#deliveryWarned = true
|
|
277
|
+
log.warn('%s delivery queue full, dropping newest batch', this.constructor.name)
|
|
278
|
+
}
|
|
279
|
+
return
|
|
280
|
+
}
|
|
281
|
+
this.#deliveryQueue.push({ payload, eventCount, bytes })
|
|
282
|
+
this.#deliveryBytes += bytes
|
|
283
|
+
this.#deliveryCount++
|
|
284
|
+
this.#scheduleDelivery()
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
#scheduleDelivery () {
|
|
288
|
+
if (this.#deliveryQueue.length === 0) {
|
|
289
|
+
if (!this.#inFlight) this.#cancelShutdownTimer()
|
|
290
|
+
return
|
|
291
|
+
}
|
|
292
|
+
if (!this.#enabled || this.#inFlight || this.#deliveryTimer) return
|
|
293
|
+
// A timer yields past socket completion so Node can reach beforeExit between requests.
|
|
294
|
+
// Only the bounded shutdown drain should keep an otherwise idle process alive.
|
|
295
|
+
this.#deliveryTimer = setTimeout(() => {
|
|
296
|
+
this.#deliveryTimer = undefined
|
|
297
|
+
this.#drainDelivery()
|
|
298
|
+
})
|
|
299
|
+
if (!this.#closed) this.#deliveryTimer.unref?.()
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
#expireShutdown () {
|
|
303
|
+
const before = this._droppedEvents
|
|
304
|
+
this.#discardDelivery()
|
|
305
|
+
const dropped = this._droppedEvents - before
|
|
306
|
+
if (dropped > 0) {
|
|
307
|
+
log.warn('%s shutdown deadline reached, dropping %d queued events', this.constructor.name, dropped)
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
#cancelShutdownTimer () {
|
|
312
|
+
clearTimeout(this.#shutdownTimer)
|
|
313
|
+
this.#shutdownTimer = undefined
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
#cancelDelivery () {
|
|
317
|
+
if (!this.#deliveryTimer) return
|
|
318
|
+
clearTimeout(this.#deliveryTimer)
|
|
319
|
+
this.#deliveryTimer = undefined
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
#discardDelivery () {
|
|
323
|
+
this.#cancelDelivery()
|
|
324
|
+
this.#cancelShutdownTimer()
|
|
325
|
+
for (const batch of this.#deliveryQueue) {
|
|
326
|
+
this._droppedEvents += batch.eventCount
|
|
327
|
+
this.#deliveryBytes -= batch.bytes
|
|
328
|
+
this.#deliveryCount--
|
|
329
|
+
}
|
|
330
|
+
this.#deliveryQueue = []
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
#drainDelivery () {
|
|
334
|
+
this.#cancelDelivery()
|
|
335
|
+
if (Date.now() >= this.#shutdownDeadline) {
|
|
336
|
+
this.#expireShutdown()
|
|
337
|
+
return
|
|
338
|
+
}
|
|
339
|
+
if (!this.#enabled || this.#inFlight) return
|
|
340
|
+
const batch = this.#deliveryQueue.shift()
|
|
341
|
+
if (!batch) {
|
|
342
|
+
this.#cancelShutdownTimer()
|
|
343
|
+
return
|
|
344
|
+
}
|
|
345
|
+
this.#inFlight = true
|
|
346
|
+
super._sendPayload(batch.payload, batch.eventCount, delivered => {
|
|
347
|
+
this.#inFlight = false
|
|
348
|
+
this.#deliveryBytes -= batch.bytes
|
|
349
|
+
this.#deliveryCount--
|
|
350
|
+
if (!delivered) this._droppedEvents += batch.eventCount
|
|
351
|
+
// Yield even when a transport implementation invokes its callback synchronously.
|
|
352
|
+
this.#scheduleDelivery()
|
|
353
|
+
})
|
|
197
354
|
}
|
|
198
355
|
|
|
199
356
|
/**
|
|
@@ -222,6 +379,9 @@ class ExposuresWriter extends BaseFFEWriter {
|
|
|
222
379
|
},
|
|
223
380
|
}
|
|
224
381
|
|
|
382
|
+
const features = snapshotFeatures(event.features)
|
|
383
|
+
if (features !== undefined) formatted.features = features
|
|
384
|
+
|
|
225
385
|
if (typeof event.serial_id === 'number') {
|
|
226
386
|
formatted.serial_id = event.serial_id
|
|
227
387
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const { MAX_EVALUATION_TIMESTAMP_MS } = require('../constants/constants')
|
|
4
|
+
const { snapshotFeatures } = require('./split-features')
|
|
5
|
+
|
|
4
6
|
const { snapshotEvaluationContext } = require('./flag-evaluation-context')
|
|
5
7
|
const {
|
|
6
8
|
recordContextTruncated, recordDropped, recordHookError, recordTargetingKeyOmitted,
|
|
@@ -82,6 +84,9 @@ class FlagEvalEVPHook {
|
|
|
82
84
|
flagKey: hookContext.flagKey,
|
|
83
85
|
variant: evaluationDetails.variant,
|
|
84
86
|
allocationKey: typeof metadata?.__dd_allocation_key === 'string' ? metadata.__dd_allocation_key : undefined,
|
|
87
|
+
features: metadata?.__dd_has_evaluation_features === true
|
|
88
|
+
? snapshotFeatures(metadata, '__dd_evaluation_feature.')
|
|
89
|
+
: undefined,
|
|
85
90
|
runtimeDefault: evaluationDetails.variant === undefined,
|
|
86
91
|
errorCode: evaluationDetails.errorCode,
|
|
87
92
|
targetingKey,
|
|
@@ -7,6 +7,7 @@ const {
|
|
|
7
7
|
FLAG_EVALUATION_GLOBAL_CAP,
|
|
8
8
|
FLAG_EVALUATION_PER_FLAG_CAP,
|
|
9
9
|
} = require('../constants/constants')
|
|
10
|
+
const { snapshotFeatures } = require('./split-features')
|
|
10
11
|
const { validatedContextEntries, snapshotFromEntries } = require('./flag-evaluation-context')
|
|
11
12
|
const { normalizeTargetingKey, optionalKey, protectedErrorCode } =
|
|
12
13
|
require('./flag-evaluation-pii')
|
|
@@ -20,6 +21,7 @@ const MAX_DIRECT_IDENTITY_LENGTH = 16_383
|
|
|
20
21
|
* @typedef {object} FlagEvaluationEvent
|
|
21
22
|
* @property {string} flagKey
|
|
22
23
|
* @property {string} [variant]
|
|
24
|
+
* @property {Record<string, string | number | boolean>} [features]
|
|
23
25
|
* @property {string} [allocationKey]
|
|
24
26
|
* @property {boolean} runtimeDefault
|
|
25
27
|
* @property {unknown} [errorCode]
|
|
@@ -32,6 +34,7 @@ const MAX_DIRECT_IDENTITY_LENGTH = 16_383
|
|
|
32
34
|
* @typedef {object} AggregationDimensions
|
|
33
35
|
* @property {string} flagKey
|
|
34
36
|
* @property {string} [variant]
|
|
37
|
+
* @property {Record<string, string | number | boolean>} [features]
|
|
35
38
|
* @property {string} [allocation]
|
|
36
39
|
* @property {string} [error]
|
|
37
40
|
*/
|
|
@@ -94,10 +97,11 @@ class FlagEvaluationAggregator {
|
|
|
94
97
|
const error = protectedErrorCode(event.errorCode)
|
|
95
98
|
const variant = optionalKey(event.variant)
|
|
96
99
|
const allocation = optionalKey(event.allocationKey)
|
|
100
|
+
const features = snapshotFeatures(event.features)
|
|
97
101
|
// Group by the raw key; the serializer independently hashes protected rows once per output bucket.
|
|
98
102
|
const identity = JSON.stringify([
|
|
99
103
|
flagKey, variant, allocation, event.runtimeDefault === true, error,
|
|
100
|
-
targetingKey, contextEntries, consent,
|
|
104
|
+
targetingKey, contextEntries, consent, features,
|
|
101
105
|
])
|
|
102
106
|
// Keep digest keys separate from short JSON identities, which always start with '['.
|
|
103
107
|
const fullKey = identity.length > MAX_DIRECT_IDENTITY_LENGTH
|
|
@@ -111,11 +115,11 @@ class FlagEvaluationAggregator {
|
|
|
111
115
|
|
|
112
116
|
const perFlag = this.#perFlag.get(flagKey) ?? 0
|
|
113
117
|
if (perFlag >= FLAG_EVALUATION_PER_FLAG_CAP) {
|
|
114
|
-
this.#addDegraded(event, { flagKey, variant, allocation, error })
|
|
118
|
+
this.#addDegraded(event, { flagKey, variant, allocation, error, features })
|
|
115
119
|
return
|
|
116
120
|
}
|
|
117
121
|
if (this.#full.size >= FLAG_EVALUATION_GLOBAL_CAP) {
|
|
118
|
-
this.#addDegraded(event, { flagKey, variant, allocation, error })
|
|
122
|
+
this.#addDegraded(event, { flagKey, variant, allocation, error, features })
|
|
119
123
|
return
|
|
120
124
|
}
|
|
121
125
|
|
|
@@ -124,6 +128,7 @@ class FlagEvaluationAggregator {
|
|
|
124
128
|
flagKey,
|
|
125
129
|
variant,
|
|
126
130
|
allocation,
|
|
131
|
+
features,
|
|
127
132
|
runtimeDefault: event.runtimeDefault === true,
|
|
128
133
|
error,
|
|
129
134
|
rawTargetingKey: targetingKey,
|
|
@@ -165,7 +170,7 @@ class FlagEvaluationAggregator {
|
|
|
165
170
|
recordDegraded('cardinality_cap')
|
|
166
171
|
const key = JSON.stringify([
|
|
167
172
|
dimensions.flagKey, dimensions.variant, dimensions.allocation,
|
|
168
|
-
event.runtimeDefault === true, dimensions.error,
|
|
173
|
+
event.runtimeDefault === true, dimensions.error, dimensions.features,
|
|
169
174
|
])
|
|
170
175
|
const existing = this.#degraded.get(key)
|
|
171
176
|
if (existing) {
|
|
@@ -24,6 +24,7 @@ const { recordDegraded, recordDropped, recordPayloadSplit } = require('./flag-ev
|
|
|
24
24
|
* @property {string} [targeting_key]
|
|
25
25
|
* @property {{ evaluation: ContextSnapshot }} [context]
|
|
26
26
|
* @property {{ key: string }} [variant]
|
|
27
|
+
* @property {Record<string, string | number | boolean>} [features]
|
|
27
28
|
* @property {{ key: string }} [allocation]
|
|
28
29
|
* @property {{ message: string }} [error]
|
|
29
30
|
*/
|
|
@@ -52,6 +53,7 @@ function makeRow (entry, timestamp, degraded) {
|
|
|
52
53
|
const allocation = normalizeTargetingKey(entry.allocation)
|
|
53
54
|
if (variant) row.variant = { key: variant }
|
|
54
55
|
if (allocation) row.allocation = { key: allocation }
|
|
56
|
+
if (entry.features !== undefined) row.features = entry.features
|
|
55
57
|
const error = protectedErrorCode(entry.error)
|
|
56
58
|
if (error !== undefined) row.error = { message: error }
|
|
57
59
|
if (!degraded) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const { hashTargetingKey: digestTargetingKey } = require('../encoding')
|
|
4
|
+
const { snapshotFeatures } = require('./split-features')
|
|
4
5
|
|
|
5
6
|
// Keep this vocabulary explicit: an upstream enum addition needs a privacy review.
|
|
6
7
|
const ERROR_CODES = new Set([
|
|
@@ -90,6 +91,7 @@ function normalizeFlagEvaluationEvent (event, targetingKey) {
|
|
|
90
91
|
flagKey: normalizeTargetingKey(event.flagKey),
|
|
91
92
|
variant: optionalKey(event.variant),
|
|
92
93
|
allocationKey: optionalKey(event.allocationKey),
|
|
94
|
+
features: snapshotFeatures(event.features),
|
|
93
95
|
runtimeDefault: event.runtimeDefault === true,
|
|
94
96
|
errorCode: protectedErrorCode(event.errorCode),
|
|
95
97
|
targetingKey,
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Snapshot scalar split features in canonical key order for stable aggregation.
|
|
5
|
+
* A prefix selects one provider destination; hook-only metadata must not reach intake.
|
|
6
|
+
* @param {unknown} source
|
|
7
|
+
* @param {string} [prefix]
|
|
8
|
+
* @returns {Record<string, string | number | boolean> | undefined}
|
|
9
|
+
*/
|
|
10
|
+
function snapshotFeatures (source, prefix = '') {
|
|
11
|
+
if (source === null || typeof source !== 'object' || Array.isArray(source)) return
|
|
12
|
+
let features
|
|
13
|
+
for (const key of Object.keys(source).sort()) {
|
|
14
|
+
if (!key.startsWith(prefix) || key.length === prefix.length) continue
|
|
15
|
+
const descriptor = Object.getOwnPropertyDescriptor(source, key)
|
|
16
|
+
const value = descriptor?.value
|
|
17
|
+
if (typeof value !== 'string' && typeof value !== 'boolean' &&
|
|
18
|
+
!(typeof value === 'number' && Number.isFinite(value))) continue
|
|
19
|
+
features ??= Object.create(null)
|
|
20
|
+
features[key.slice(prefix.length)] = value
|
|
21
|
+
}
|
|
22
|
+
return features
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
module.exports = { snapshotFeatures }
|
|
@@ -12,10 +12,10 @@ const { nowUnixNano } = require('./time')
|
|
|
12
12
|
* @param {(error: Error | null) => void} [done]
|
|
13
13
|
* @param {Error | null} [error]
|
|
14
14
|
*/
|
|
15
|
-
function callDone (done, error) {
|
|
15
|
+
function callDone (done, error = null) {
|
|
16
16
|
if (!done) return
|
|
17
17
|
try {
|
|
18
|
-
done(error
|
|
18
|
+
done(error)
|
|
19
19
|
} catch (callbackError) {
|
|
20
20
|
log.error('Error completing OTLP metrics lifecycle callback:', callbackError)
|
|
21
21
|
}
|
|
@@ -84,7 +84,11 @@ class TracerProvider {
|
|
|
84
84
|
return Promise.reject(new Error('Not started'))
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
exporter.
|
|
87
|
+
if (typeof exporter.flush === 'function') {
|
|
88
|
+
exporter.flush()
|
|
89
|
+
} else {
|
|
90
|
+
exporter._writer?.flush()
|
|
91
|
+
}
|
|
88
92
|
return this.#activeProcessor.forceFlush()
|
|
89
93
|
}
|
|
90
94
|
|
|
@@ -4,6 +4,7 @@ const os = require('os')
|
|
|
4
4
|
const SpanProcessor = require('../span_processor')
|
|
5
5
|
const PrioritySampler = require('../priority_sampler')
|
|
6
6
|
const formats = require('../../../../ext/formats')
|
|
7
|
+
const exporters = require('../../../../ext/exporters')
|
|
7
8
|
const log = require('../log')
|
|
8
9
|
const runtimeMetrics = require('../runtime_metrics')
|
|
9
10
|
const getExporter = require('../exporter')
|
|
@@ -31,21 +32,17 @@ class DatadogTracer {
|
|
|
31
32
|
this._debug = config.debug
|
|
32
33
|
this._prioritySampler = prioritySampler ?? new PrioritySampler(config.env, config.sampler)
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
// exporter when the tracer is running in Test Optimization mode. Test spans
|
|
36
|
-
// (test_session/test_module/ test_suite/test) belong on the citestcycle
|
|
37
|
-
// endpoint, not on an OTLP traces endpoint — otherwise users with OTEL_*
|
|
38
|
-
// vars set in their environment (e.g. for a separate telemetry integration)
|
|
39
|
-
// silently lose all test spans. The same applies to the Electron exporter:
|
|
40
|
-
// spans must reach the Electron SDK's IPC bridge, not an OTLP endpoint,
|
|
41
|
-
// even when OTEL_* vars are set for unrelated telemetry.
|
|
42
|
-
const exportOtlpTraces = config.OTEL_TRACES_EXPORTER === 'otlp' && !config.isCiVisibility &&
|
|
43
|
-
config.tracing.DD_TRACE_EXPERIMENTAL_EXPORTER !== 'electron'
|
|
35
|
+
const exportOtlpTraces = getExporter.usesOtlpTraceExporter(config)
|
|
44
36
|
if (exportOtlpTraces) {
|
|
45
37
|
const { createOtlpTraceExporter } = require('../opentelemetry/trace')
|
|
46
38
|
this._exporter = createOtlpTraceExporter(config)
|
|
47
39
|
} else {
|
|
48
|
-
|
|
40
|
+
let exporterName = config.tracing.DD_TRACE_EXPERIMENTAL_EXPORTER
|
|
41
|
+
if (config.llmobs?.DD_LLMOBS_ENABLED && !config.isCiVisibility &&
|
|
42
|
+
(!exporterName || exporterName === exporters.AGENT || exporterName === exporters.AGENTLESS)) {
|
|
43
|
+
exporterName = exporters.LLMOBS
|
|
44
|
+
}
|
|
45
|
+
const Exporter = getExporter(exporterName)
|
|
49
46
|
this._exporter = new Exporter(config, this._prioritySampler)
|
|
50
47
|
}
|
|
51
48
|
|
|
@@ -58,8 +55,7 @@ class DatadogTracer {
|
|
|
58
55
|
this._exporter,
|
|
59
56
|
this._prioritySampler,
|
|
60
57
|
config,
|
|
61
|
-
otlpStatsExporter
|
|
62
|
-
exportOtlpTraces
|
|
58
|
+
otlpStatsExporter
|
|
63
59
|
)
|
|
64
60
|
this._url = this._exporter._url
|
|
65
61
|
this._enableGetRumData = config.rum.DD_TRACE_EXPERIMENTAL_GET_RUM_DATA_ENABLED
|