Skip to content

Commit 52c89d2

Browse files
authored
fix: add data_streams_enabled to startup log output (#7454)
* Add data_streams_enabled to startup log output Go, Java, and .NET tracers already include data_streams_enabled in the DATADOG TRACER CONFIGURATION startup log. This adds parity for the Node.js tracer, making it easier to debug DSM configuration issues in customer environments. * Add test coverage for data_streams_enabled in startup log Tests the three key scenarios: 1. env var true, config unset → true (env var applies) 2. env var unset, config true → true (code option applies) 3. env var true, config false → false (code option takes precedence) * Add dsmEnabled to TracerOptions interface Exposes dsmEnabled as a documented, first-class option in dd.init(). The config system already supports this internally — this change just makes it visible in the public TypeScript types. When not provided, the value of DD_DATA_STREAMS_ENABLED env var is used. When explicitly set, the code option takes precedence over the env var (consistent with all other config options).
1 parent c57a18c commit 52c89d2

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

index.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,14 @@ declare namespace tracer {
760760
*/
761761
dbmPropagationMode?: 'disabled' | 'service' | 'full'
762762

763+
/**
764+
* Whether to enable Data Streams Monitoring.
765+
* Can also be enabled via the DD_DATA_STREAMS_ENABLED environment variable.
766+
* When not provided, the value of DD_DATA_STREAMS_ENABLED is used.
767+
* @default false
768+
*/
769+
dsmEnabled?: boolean
770+
763771
/**
764772
* Configuration of the AppSec protection. Can be a boolean as an alias to `appsec.enabled`.
765773
*/

packages/dd-trace/src/startup-log.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ function tracerInfo () {
7575
profiling_enabled: config.profiling?.enabled === 'true' || config.profiling?.enabled === 'auto',
7676
integrations_loaded: Object.keys(pluginManager._pluginsByName),
7777
appsec_enabled: !!config.appsec.enabled,
78+
data_streams_enabled: !!config.dsmEnabled,
7879
}
7980

8081
return out

packages/dd-trace/test/startup-log.spec.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ describe('startup logging', () => {
5151
runtimeMetrics: true,
5252
startupLogs: true,
5353
appsec: { enabled: true },
54+
dsmEnabled: true,
5455
})
5556
setSamplingRules([
5657
new SamplingRule({ name: 'rule1', sampleRate: 0.4 }),
@@ -98,6 +99,7 @@ describe('startup logging', () => {
9899
profiling_enabled: false,
99100
integrations_loaded: ['http', 'fs', 'semver'],
100101
appsec_enabled: true,
102+
data_streams_enabled: true,
101103
})
102104
})
103105

@@ -106,6 +108,72 @@ describe('startup logging', () => {
106108
})
107109
})
108110

111+
describe('data_streams_enabled', () => {
112+
afterEach(() => {
113+
delete process.env.DD_DATA_STREAMS_ENABLED
114+
})
115+
116+
it('should be true when env var is true and config is unset', () => {
117+
sinon.stub(console, 'info')
118+
delete require.cache[require.resolve('../src/startup-log')]
119+
const {
120+
setStartupLogConfig,
121+
setStartupLogPluginManager,
122+
startupLog,
123+
} = require('../src/startup-log')
124+
process.env.DD_DATA_STREAMS_ENABLED = 'true'
125+
process.env.DD_TRACE_STARTUP_LOGS = 'true'
126+
setStartupLogConfig(getConfigFresh())
127+
setStartupLogPluginManager({ _pluginsByName: {} })
128+
startupLog()
129+
/* eslint-disable-next-line no-console */
130+
const infoStub = /** @type {sinon.SinonStub} */ (console.info)
131+
const logObj = JSON.parse(infoStub.firstCall.args[0].replace('DATADOG TRACER CONFIGURATION - ', ''))
132+
infoStub.restore()
133+
assert.strictEqual(logObj.data_streams_enabled, true)
134+
})
135+
136+
it('should be true when env var is not set and config is true', () => {
137+
sinon.stub(console, 'info')
138+
delete require.cache[require.resolve('../src/startup-log')]
139+
const {
140+
setStartupLogConfig,
141+
setStartupLogPluginManager,
142+
startupLog,
143+
} = require('../src/startup-log')
144+
delete process.env.DD_DATA_STREAMS_ENABLED
145+
process.env.DD_TRACE_STARTUP_LOGS = 'true'
146+
setStartupLogConfig(getConfigFresh({ dsmEnabled: true }))
147+
setStartupLogPluginManager({ _pluginsByName: {} })
148+
startupLog()
149+
/* eslint-disable-next-line no-console */
150+
const infoStub = /** @type {sinon.SinonStub} */ (console.info)
151+
const logObj = JSON.parse(infoStub.firstCall.args[0].replace('DATADOG TRACER CONFIGURATION - ', ''))
152+
infoStub.restore()
153+
assert.strictEqual(logObj.data_streams_enabled, true)
154+
})
155+
156+
it('should be false when env var is true but config is false', () => {
157+
sinon.stub(console, 'info')
158+
delete require.cache[require.resolve('../src/startup-log')]
159+
const {
160+
setStartupLogConfig,
161+
setStartupLogPluginManager,
162+
startupLog,
163+
} = require('../src/startup-log')
164+
process.env.DD_DATA_STREAMS_ENABLED = 'true'
165+
process.env.DD_TRACE_STARTUP_LOGS = 'true'
166+
setStartupLogConfig(getConfigFresh({ dsmEnabled: false }))
167+
setStartupLogPluginManager({ _pluginsByName: {} })
168+
startupLog()
169+
/* eslint-disable-next-line no-console */
170+
const infoStub = /** @type {sinon.SinonStub} */ (console.info)
171+
const logObj = JSON.parse(infoStub.firstCall.args[0].replace('DATADOG TRACER CONFIGURATION - ', ''))
172+
infoStub.restore()
173+
assert.strictEqual(logObj.data_streams_enabled, false)
174+
})
175+
})
176+
109177
describe('profiling_enabled', () => {
110178
it('should be correctly logged', () => {
111179
[

0 commit comments

Comments
 (0)