Skip to content

Commit 2d2ed5b

Browse files
authored
test: make sure unknown config entries cause an error (#8152)
Unknown configurations now have a test against being added to prevent unknown telemetry being reported.
1 parent 9c8fd58 commit 2d2ed5b

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

packages/dd-trace/test/config/index.spec.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,33 @@ describe('Config', () => {
162162
})
163163
})
164164

165+
describe('property surface', () => {
166+
// Mirror of the runtime-only fields in `ConfigProperties` (config-types.d.ts).
167+
const INTERNAL_RUNTIME_PROPERTIES = [
168+
'commitSHA',
169+
'debug',
170+
'isServiceNameInferred',
171+
'repositoryUrl',
172+
'sampler',
173+
'stableConfig',
174+
]
175+
176+
it('does not expose own properties beyond supported-configurations.json and index.d.ts', () => {
177+
// Top-level segment only: nested defaults (e.g. `foo.bar`) live as `foo` on the instance.
178+
const known = new Set(Object.keys(defaults).map(name => name.split('.', 1)[0]))
179+
for (const name of INTERNAL_RUNTIME_PROPERTIES) {
180+
known.add(name)
181+
}
182+
183+
const config = getConfig()
184+
const unknownConfigurations = Object.keys(config).filter(name => !known.has(name))
185+
186+
assert.deepStrictEqual(unknownConfigurations, [], 'Unknown Config properties detected.\n' +
187+
'Add it to supported-configurations.json (or index.d.ts), if it truly is a Config property.\n' +
188+
'Otherwise, remove / handle elsewhere. This reports telemetry about unrecognized properties.')
189+
})
190+
})
191+
165192
it('should initialize its own logging config based off the loggers config', () => {
166193
process.env.DD_TRACE_DEBUG = 'true'
167194
process.env.DD_TRACE_LOG_LEVEL = 'error'

0 commit comments

Comments
 (0)