Skip to content

Commit 4ab60e2

Browse files
authored
refactor(config)!: gate experimental.appsec, plugins, ingestion shapes (#8318)
Gates three long-@deprecated programmatic config shapes for v6 in defaults.js; v5 keeps them. The `experimental.appsec.*` programmatic aliases (including the bare boolean alias and `experimental.appsec.standalone.enabled`) and the `ingestion: { sampleRate, rateLimit }` wrapper are no longer accepted on `tracer.init()` in v6. v5 keeps the legacy shape; v6 callers see an "Unknown option" warning instead of a silent rewrite to the canonical fields, and `DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED` is dropped so v6 falls through to `apmTracingEnabled` / `DD_APM_TRACING_ENABLED`. The v6 mutation runs through a shared `major-overrides` helper that both `helper.js` and `defaults.js` invoke before reading `supportedConfigurations`, so the helper layer's alias / deprecation caches and the defaults layer's `optionsTable` build see the same v6 shape regardless of which module is required first.
1 parent 626ce46 commit 4ab60e2

8 files changed

Lines changed: 152 additions & 110 deletions

File tree

MIGRATING.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,19 @@ the existing `'b3multi'` value. The legacy `'b3 single header'` spelling is
6868
still accepted on `DD_TRACE_PROPAGATION_STYLE` and the programmatic option as
6969
a quiet alias for `'b3'`; prefer the canonical `'b3'` going forward.
7070

71+
### `experimental.appsec` configuration removed
72+
73+
The `experimental.appsec.*` programmatic aliases (and
74+
`experimental.appsec.standalone.enabled`) have been removed. Use the canonical
75+
top-level `appsec.*` fields, and `apmTracingEnabled` (or
76+
`DD_APM_TRACING_ENABLED`) to control standalone ASM mode.
77+
78+
### `ingestion` option removed
79+
80+
The `ingestion: { sampleRate, rateLimit }` wrapper has been removed. Set
81+
`sampleRate` and `rateLimit` directly on the top-level `TracerOptions` object,
82+
or use `DD_TRACE_SAMPLE_RATE` / `DD_TRACE_RATE_LIMIT`.
83+
7184
## 4.0 to 5.0
7285

7386
### Node 16 is no longer supported

docs/test.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ tracer.init({
4646
version: '1.0.0',
4747
url: 'http://localhost',
4848
runtimeMetrics: true,
49-
ingestion: {
50-
sampleRate: 0.5,
51-
rateLimit: 500
52-
},
5349
experimental: {
5450
exporter: 'log'
5551
},
@@ -149,13 +145,6 @@ tracer.init({
149145
});
150146

151147
tracer.init({
152-
experimental: {
153-
appsec: {
154-
standalone: {
155-
enabled: true
156-
}
157-
}
158-
},
159148
iast: {
160149
enabled: true,
161150
requestSampling: 50,

eslint-rules/eslint-config-names-sync.mjs

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,24 @@ import ts from 'typescript'
66

77
const require = createRequire(import.meta.url)
88
const { DD_MAJOR } = require('../version.js')
9-
const { applyMajorVersionAliasFilters } = require('../packages/dd-trace/src/config/major-version-filters.js')
9+
const applyMajorOverrides = require('../packages/dd-trace/src/config/major-overrides.js')
1010

1111
const IGNORED_CONFIGURATION_NAMES = new Set([
1212
// v6 drops `experimental.b3` from `index.d.ts`; v5 still consumes the env var.
1313
'experimental.b3',
1414
'tracePropagationStyle',
1515
'tracing',
1616
])
17+
// Configuration name prefixes that are intentionally only present in
18+
// `supported-configurations.json` for v5 backports and stripped at runtime in
19+
// v6. Keep these out of the `index.d.ts` ↔ JSON parity check.
20+
const IGNORED_CONFIGURATION_NAME_PREFIXES = [
21+
'experimental.appsec.',
22+
'ingestion.',
23+
]
24+
const IGNORED_CONFIGURATION_LEAVES = new Set([
25+
'experimental.appsec',
26+
])
1727
const UNSUPPORTED_CONFIGURATION_ROOTS = new Set([
1828
'isCiVisibility',
1929
'logger',
@@ -83,7 +93,7 @@ function createInspectionResult (overrides) {
8393
function getSupportedConfigurationInfo (filePath) {
8494
const parsed = JSON.parse(fs.readFileSync(filePath, 'utf8'))
8595
const supportedConfigurations = parsed?.supportedConfigurations
86-
applyMajorVersionAliasFilters(supportedConfigurations, DD_MAJOR)
96+
applyMajorOverrides(supportedConfigurations, DD_MAJOR)
8797

8898
const names = new Set()
8999
const primaryEnvTargets = new Map()
@@ -121,14 +131,19 @@ function getSupportedConfigurationInfo (filePath) {
121131
}
122132

123133
for (const name of entry.configurationNames ?? []) {
124-
if (typeof name === 'string' && !IGNORED_CONFIGURATION_NAMES.has(name)) {
125-
// Deprecated entries opt out of the cross-check against `index.d.ts` so a
126-
// major-version drop of the public type does not strand the env var here.
127-
if (!entry.deprecated) {
128-
names.add(name)
129-
}
130-
targets.add(name)
134+
if (typeof name !== 'string' || IGNORED_CONFIGURATION_NAMES.has(name)) {
135+
continue
136+
}
137+
if (IGNORED_CONFIGURATION_LEAVES.has(name)) {
138+
continue
139+
}
140+
if (IGNORED_CONFIGURATION_NAME_PREFIXES.some((prefix) => name.startsWith(prefix))) {
141+
continue
142+
}
143+
if (!entry.deprecated) {
144+
names.add(name)
131145
}
146+
targets.add(name)
132147
}
133148
}
134149

@@ -485,6 +500,14 @@ function getIndexDtsConfigurationNames (filePath, supportedConfigurationInfo) {
485500
for (const ignoredConfigurationName of IGNORED_CONFIGURATION_NAMES) {
486501
names.delete(ignoredConfigurationName)
487502
}
503+
for (const leaf of IGNORED_CONFIGURATION_LEAVES) {
504+
names.delete(leaf)
505+
}
506+
for (const name of names) {
507+
if (IGNORED_CONFIGURATION_NAME_PREFIXES.some((prefix) => name.startsWith(prefix))) {
508+
names.delete(name)
509+
}
510+
}
488511

489512
return names
490513
}

index.d.ts

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -699,28 +699,6 @@ declare namespace tracer {
699699
*/
700700
protocolVersion?: string
701701

702-
/**
703-
* Deprecated in favor of the global versions of the variables provided under this option
704-
*
705-
* @deprecated
706-
* @hidden
707-
*/
708-
ingestion?: {
709-
/**
710-
* Controls the ingestion sample rate (between 0 and 1) between the agent and the backend.
711-
* @env DD_TRACE_SAMPLE_RATE
712-
* Programmatic configuration takes precedence over the environment variables listed above.
713-
*/
714-
sampleRate?: number
715-
716-
/**
717-
* Controls the ingestion rate limit between the agent and the backend. Defaults to deferring the decision to the agent.
718-
* @env DD_TRACE_RATE_LIMIT
719-
* Programmatic configuration takes precedence over the environment variables listed above.
720-
*/
721-
rateLimit?: number
722-
};
723-
724702
/**
725703
* Whether to enable inferred proxy services.
726704
* @default false
@@ -758,28 +736,6 @@ declare namespace tracer {
758736
*/
759737
enableGetRumData?: boolean
760738

761-
/**
762-
* Configuration of the AppSec. Can be a boolean as an alias to `appsec.enabled`.
763-
* @deprecated Please use the non-experimental `appsec` option instead.
764-
*/
765-
appsec?: boolean | {
766-
/**
767-
* Configuration of Standalone ASM mode
768-
* Deprecated in favor of `apmTracingEnabled`.
769-
*
770-
* @deprecated Please use `apmTracingEnabled` instead.
771-
*/
772-
standalone?: {
773-
/**
774-
* Whether to enable Standalone ASM.
775-
* @default false
776-
* @env DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED
777-
* Programmatic configuration takes precedence over the environment variables listed above.
778-
*/
779-
enabled?: boolean
780-
}
781-
} | TracerOptions['appsec'],
782-
783739
aiguard?: {
784740
/**
785741
* Set to `true` to enable the SDK.

packages/dd-trace/src/config/defaults.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,19 @@ const dns = require('dns')
44
const util = require('util')
55

66
const { DD_MAJOR } = require('../../../../version')
7-
const { applyMajorVersionAliasFilters } = require('./major-version-filters')
87
const { parsers, transformers, telemetryTransformers, setWarnInvalidValue } = require('./parsers')
8+
const applyMajorOverrides = require('./major-overrides')
99
const {
1010
supportedConfigurations,
1111
} = /** @type {import('./helper').SupportedConfigurationsJson} */ (require('./supported-configurations.json'))
1212

13+
applyMajorOverrides(supportedConfigurations, DD_MAJOR)
14+
1315
let log
1416
let seqId = 0
1517
const configWithOrigin = new Map()
1618
const parseErrors = new Map()
1719

18-
// Idempotent; mirrors the call in `helper.js` so either module load order produces the same shape.
19-
applyMajorVersionAliasFilters(supportedConfigurations, DD_MAJOR)
20-
2120
if (DD_MAJOR < 6) {
2221
// Default value for DD_TRACE_STARTUP_LOGS is 'false' in older major versions.
2322
// TODO: Remove this here once v5 is not supported anymore.

packages/dd-trace/src/config/helper.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,13 @@
2121
*/
2222

2323
const { deprecate } = require('util')
24-
2524
const { DD_MAJOR } = require('../../../../version')
26-
const { applyMajorVersionAliasFilters } = require('./major-version-filters')
25+
const applyMajorOverrides = require('./major-overrides')
2726
const {
2827
supportedConfigurations,
2928
} = /** @type {SupportedConfigurationsJson} */ (require('./supported-configurations.json'))
3029

31-
// Apply v6 env-alias deletions before the `aliases` / `aliasToCanonical` snapshot below; otherwise
32-
// `getEnvironmentVariables()` keeps rewriting the deprecated env vars to their canonical names.
33-
applyMajorVersionAliasFilters(supportedConfigurations, DD_MAJOR)
30+
applyMajorOverrides(supportedConfigurations, DD_MAJOR)
3431

3532
/**
3633
* Types for environment variable handling.

packages/dd-trace/src/config/major-version-filters.js renamed to packages/dd-trace/src/config/major-overrides.js

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,33 @@
44
* @typedef {import('./helper').SupportedConfigurationsJson['supportedConfigurations']} SupportedConfigurations
55
*/
66

7+
const EXPERIMENTAL_APPSEC_PREFIX = 'experimental.appsec'
78
const EXPERIMENTAL_IAST_PREFIX = 'experimental.iast'
8-
9-
const filtered = new WeakSet()
9+
const INGESTION_PREFIX = 'ingestion.'
1010

1111
/**
12-
* Shared between `helper.js` / `defaults.js` (runtime) and `eslint-config-names-sync` (lint) so
13-
* the JSON ↔ `index.d.ts` sync check uses the same view as the runtime parser. Idempotent on a
14-
* per-object basis so callers don't have to coordinate load order.
15-
*
1612
* @param {SupportedConfigurations} supportedConfigurations Mutated in place.
1713
* @param {number} majorVersion
1814
*/
19-
function applyMajorVersionAliasFilters (supportedConfigurations, majorVersion) {
20-
if (filtered.has(supportedConfigurations)) return
21-
filtered.add(supportedConfigurations)
22-
15+
function applyMajorOverrides (supportedConfigurations, majorVersion) {
2316
if (majorVersion < 6) return
2417

25-
// v6 strips both the bare `experimental.iast` alias and its nested forms so
26-
// `#applyOptions` warns "Unknown option" instead of writing user-supplied
27-
// objects into `iast.enabled` via the bare alias.
2818
for (const entries of Object.values(supportedConfigurations)) {
2919
for (const entry of entries) {
3020
if (Array.isArray(entry.configurationNames)) {
3121
entry.configurationNames = entry.configurationNames.filter(
32-
(name) => name !== EXPERIMENTAL_IAST_PREFIX && !name.startsWith(`${EXPERIMENTAL_IAST_PREFIX}.`)
22+
(name) =>
23+
name !== EXPERIMENTAL_APPSEC_PREFIX &&
24+
name !== EXPERIMENTAL_IAST_PREFIX &&
25+
!name.startsWith(`${EXPERIMENTAL_APPSEC_PREFIX}.`) &&
26+
!name.startsWith(`${EXPERIMENTAL_IAST_PREFIX}.`) &&
27+
!name.startsWith(INGESTION_PREFIX)
3328
)
29+
if (entry.configurationNames.length === 0) delete entry.configurationNames
3430
}
3531
}
3632
}
37-
33+
delete supportedConfigurations.DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED
3834
delete supportedConfigurations.DD_TRACE_EXPERIMENTAL_B3_ENABLED
3935

4036
/* eslint-disable eslint-rules/eslint-env-aliases */
@@ -62,10 +58,6 @@ function applyMajorVersionAliasFilters (supportedConfigurations, majorVersion) {
6258
}
6359

6460
/**
65-
* Filter aliases on a canonical entry in-place. `dropPredicate` may be a string (exact match) or
66-
* a function called per alias. No-op when the canonical is missing so this stays usable against
67-
* the eslint sync test fixtures.
68-
*
6961
* @param {SupportedConfigurations[string] | undefined} entries
7062
* @param {string | ((alias: string) => boolean)} dropPredicate
7163
*/
@@ -76,7 +68,9 @@ function dropAlias (entries, dropPredicate) {
7668
? (alias) => alias === dropPredicate
7769
: dropPredicate
7870
entry.aliases = entry.aliases.filter((alias) => !matches(alias))
79-
if (entry.aliases.length === 0) delete entry.aliases
71+
if (entry.aliases.length === 0) {
72+
delete entry.aliases
73+
}
8074
}
8175

82-
module.exports = { applyMajorVersionAliasFilters }
76+
module.exports = applyMajorOverrides

0 commit comments

Comments
 (0)