Skip to content

Commit e130d50

Browse files
bm1549claude
andauthored
fix(startup-log): send startup logs to stderr (#7502)
Changed startup logs to output to stderr (via console.warn) instead of stdout (via console.info), following Unix conventions and aligning with other Datadog language tracers. This is a minimal change that only swaps the output stream - no changes to timing or function structure. Changes: - Changed startupLog() to use warn() instead of info() for stderr output - Updated all tests to expect console.warn instead of console.info Related to #7470 (which was reverted in #7478 due to regression from immediate emission timing change). This PR includes only the stderr output change without any timing modifications. Co-authored-by: Claude Sonnet 4.5 <[email protected]>
1 parent d0e5d6e commit e130d50

2 files changed

Lines changed: 20 additions & 24 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const os = require('os')
44
const { inspect } = require('util')
55
const tracerVersion = require('../../../package.json').version
66
const { getAgentUrl } = require('./agent/url')
7-
const { info, warn } = require('./log/writer')
7+
const { warn } = require('./log/writer')
88

99
const errors = {}
1010
let config
@@ -29,7 +29,7 @@ function startupLog (agentError) {
2929
out.agent_error = agentError.message
3030
}
3131

32-
info('DATADOG TRACER CONFIGURATION - ' + out)
32+
warn('DATADOG TRACER CONFIGURATION - ' + out)
3333
if (agentError) {
3434
warn('DATADOG TRACER DIAGNOSTIC - Agent Error: ' + agentError.message)
3535
errors.agentError = {

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

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ describe('startup logging', () => {
1717
let tracerInfoMethod
1818

1919
before(() => {
20-
sinon.stub(console, 'info')
2120
sinon.stub(console, 'warn')
2221
delete require.cache[require.resolve('../src/startup-log')]
2322
const {
@@ -60,13 +59,10 @@ describe('startup logging', () => {
6059
])
6160
// Use sinon's stub instance directly to avoid type errors
6261
// eslint-disable-next-line no-console
63-
const infoStub = /** @type {sinon.SinonStub} */ (console.info)
64-
// eslint-disable-next-line no-console
6562
const warnStub = /** @type {sinon.SinonStub} */ (console.warn)
6663
startupLog({ message: 'Error: fake error' })
67-
firstStderrCall = infoStub.firstCall
68-
secondStderrCall = warnStub.firstCall
69-
infoStub.restore()
64+
firstStderrCall = warnStub.firstCall
65+
secondStderrCall = warnStub.secondCall
7066
warnStub.restore()
7167
})
7268

@@ -114,7 +110,7 @@ describe('data_streams_enabled', () => {
114110
})
115111

116112
it('should be true when env var is true and config is unset', () => {
117-
sinon.stub(console, 'info')
113+
sinon.stub(console, 'warn')
118114
delete require.cache[require.resolve('../src/startup-log')]
119115
const {
120116
setStartupLogConfig,
@@ -127,14 +123,14 @@ describe('data_streams_enabled', () => {
127123
setStartupLogPluginManager({ _pluginsByName: {} })
128124
startupLog()
129125
/* 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()
126+
const warnStub = /** @type {sinon.SinonStub} */ (console.warn)
127+
const logObj = JSON.parse(warnStub.firstCall.args[0].replace('DATADOG TRACER CONFIGURATION - ', ''))
128+
warnStub.restore()
133129
assert.strictEqual(logObj.data_streams_enabled, true)
134130
})
135131

136132
it('should be true when env var is not set and config is true', () => {
137-
sinon.stub(console, 'info')
133+
sinon.stub(console, 'warn')
138134
delete require.cache[require.resolve('../src/startup-log')]
139135
const {
140136
setStartupLogConfig,
@@ -147,14 +143,14 @@ describe('data_streams_enabled', () => {
147143
setStartupLogPluginManager({ _pluginsByName: {} })
148144
startupLog()
149145
/* 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()
146+
const warnStub = /** @type {sinon.SinonStub} */ (console.warn)
147+
const logObj = JSON.parse(warnStub.firstCall.args[0].replace('DATADOG TRACER CONFIGURATION - ', ''))
148+
warnStub.restore()
153149
assert.strictEqual(logObj.data_streams_enabled, true)
154150
})
155151

156152
it('should be false when env var is true but config is false', () => {
157-
sinon.stub(console, 'info')
153+
sinon.stub(console, 'warn')
158154
delete require.cache[require.resolve('../src/startup-log')]
159155
const {
160156
setStartupLogConfig,
@@ -167,9 +163,9 @@ describe('data_streams_enabled', () => {
167163
setStartupLogPluginManager({ _pluginsByName: {} })
168164
startupLog()
169165
/* 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()
166+
const warnStub = /** @type {sinon.SinonStub} */ (console.warn)
167+
const logObj = JSON.parse(warnStub.firstCall.args[0].replace('DATADOG TRACER CONFIGURATION - ', ''))
168+
warnStub.restore()
173169
assert.strictEqual(logObj.data_streams_enabled, false)
174170
})
175171
})
@@ -183,7 +179,7 @@ describe('profiling_enabled', () => {
183179
['auto', true],
184180
['true', true],
185181
].forEach(([envVar, expected]) => {
186-
sinon.stub(console, 'info')
182+
sinon.stub(console, 'warn')
187183
delete require.cache[require.resolve('../src/startup-log')]
188184
const {
189185
setStartupLogConfig,
@@ -196,9 +192,9 @@ describe('profiling_enabled', () => {
196192
setStartupLogPluginManager({ _pluginsByName: {} })
197193
startupLog()
198194
/* eslint-disable-next-line no-console */
199-
const infoStub = /** @type {sinon.SinonStub} */ (console.info)
200-
const logObj = JSON.parse(infoStub.firstCall.args[0].replace('DATADOG TRACER CONFIGURATION - ', ''))
201-
infoStub.restore()
195+
const warnStub = /** @type {sinon.SinonStub} */ (console.warn)
196+
const logObj = JSON.parse(warnStub.firstCall.args[0].replace('DATADOG TRACER CONFIGURATION - ', ''))
197+
warnStub.restore()
202198
assert.strictEqual(logObj.profiling_enabled, expected)
203199
})
204200
})

0 commit comments

Comments
 (0)