Skip to content

Commit 205a001

Browse files
authored
Enable log injection by default for structured loggers (#5859)
1 parent fc288e7 commit 205a001

File tree

14 files changed

+106
-19
lines changed

14 files changed

+106
-19
lines changed

integration-tests/automatic-log-submission.spec.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,10 @@ describe('test visibility automatic log submission', () => {
174174
)
175175
childProcess.on('exit', () => {
176176
assert.include(testOutput, 'Hello simple log!')
177-
assert.notInclude(testOutput, 'span_id')
178-
done()
177+
assert.include(testOutput, 'span_id')
178+
logsPromise.then(() => {
179+
done()
180+
}).catch(done)
179181
})
180182

181183
childProcess.stdout.on('data', (chunk) => {
@@ -184,6 +186,13 @@ describe('test visibility automatic log submission', () => {
184186
childProcess.stderr.on('data', (chunk) => {
185187
testOutput += chunk.toString()
186188
})
189+
190+
const logsPromise = receiver
191+
.gatherPayloadsMaxTimeout(({ url }) => url.includes('/api/v2/logs'), payloads => {
192+
if (payloads.length > 0) {
193+
throw new Error('Unexpected logs')
194+
}
195+
}, 5000)
187196
})
188197

189198
it('does not submit logs when DD_AGENTLESS_LOG_SUBMISSION_ENABLED is set but DD_API_KEY is not', (done) => {

integration-tests/pino.spec.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const { FakeAgent, spawnProc, createSandbox, curl } = require('./helpers')
3+
const { FakeAgent, spawnProc, createSandbox, curl, assertObjectContains } = require('./helpers')
44
const path = require('path')
55
const { assert } = require('chai')
66
const { once } = require('events')
@@ -32,6 +32,27 @@ describe('pino test', () => {
3232
await agent.stop()
3333
})
3434

35+
it('Log injection enabled by default', async () => {
36+
proc = await spawnProc(startupTestFile, {
37+
cwd,
38+
env: {
39+
AGENT_PORT: agent.port
40+
},
41+
stdio: 'pipe',
42+
})
43+
const [data] = await Promise.all([once(proc.stdout, 'data'), curl(proc)])
44+
const stdoutData = JSON.parse(data.toString())
45+
assertObjectContains(stdoutData, {
46+
dd: {
47+
trace_id: stdoutData.custom.trace_id,
48+
span_id: stdoutData.custom.span_id
49+
},
50+
custom: {
51+
trace_id: stdoutData.dd.trace_id,
52+
span_id: stdoutData.dd.span_id
53+
}
54+
})
55+
})
3556
it('Log injection enabled', async () => {
3657
proc = await spawnProc(startupTestFile, {
3758
cwd,
@@ -60,6 +81,7 @@ describe('pino test', () => {
6081
cwd,
6182
env: {
6283
AGENT_PORT: agent.port,
84+
lOG_INJECTION: false
6385
},
6486
stdio: 'pipe',
6587
})

integration-tests/telemetry.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ describe('telemetry', () => {
6666
await agent.assertTelemetryReceived(msg => {
6767
const { configuration } = msg.payload.payload
6868
assertObjectContains(configuration, [
69-
{ name: 'DD_LOG_INJECTION', value: false, origin: 'default' },
69+
{ name: 'DD_LOG_INJECTION', value: 'structured', origin: 'default' },
7070
{ name: 'DD_LOG_INJECTION', value: true, origin: 'env_var' },
7171
{ name: 'DD_LOG_INJECTION', value: false, origin: 'code' }
7272
])

packages/datadog-plugin-bunyan/src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict'
22

3-
const LogPlugin = require('../../dd-trace/src/plugins/log_plugin')
3+
const StructuredLogPlugin = require('../../dd-trace/src/plugins/structured_log_plugin')
44

5-
class BunyanPlugin extends LogPlugin {
5+
class BunyanPlugin extends StructuredLogPlugin {
66
static get id () {
77
return 'bunyan'
88
}

packages/datadog-plugin-bunyan/test/index.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe('Plugin', () => {
4949

5050
const record = JSON.parse(stream.write.firstCall.args[0].toString())
5151

52-
expect(record).to.not.have.property('dd')
52+
expect(record).to.have.property('dd')
5353
})
5454
})
5555
})

packages/datadog-plugin-pino/src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict'
22

3-
const LogPlugin = require('../../dd-trace/src/plugins/log_plugin')
3+
const StructuredLogPlugin = require('../../dd-trace/src/plugins/structured_log_plugin')
44

5-
class PinoPlugin extends LogPlugin {
5+
class PinoPlugin extends StructuredLogPlugin {
66
static get id () {
77
return 'pino'
88
}

packages/datadog-plugin-pino/test/index.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe('Plugin', () => {
6464

6565
const record = JSON.parse(stream.write.firstCall.args[0].toString())
6666

67-
expect(record).to.not.have.property('dd')
67+
expect(record).to.have.property('dd')
6868
expect(record).to.have.deep.property('msg', 'message')
6969
})
7070
})
@@ -80,8 +80,8 @@ describe('Plugin', () => {
8080

8181
const record = stream.write.firstCall.args[0].toString()
8282

83-
expect(record).to.not.include('trace_id')
84-
expect(record).to.not.include('span_id')
83+
expect(record).to.include('trace_id')
84+
expect(record).to.include('span_id')
8585
expect(record).to.include('message')
8686
})
8787
})

packages/datadog-plugin-winston/src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict'
22

3-
const LogPlugin = require('../../dd-trace/src/plugins/log_plugin')
3+
const StructuredLogPlugin = require('../../dd-trace/src/plugins/structured_log_plugin')
44

5-
class WinstonPlugin extends LogPlugin {
5+
class WinstonPlugin extends StructuredLogPlugin {
66
static get id () {
77
return 'winston'
88
}

packages/datadog-plugin-winston/test/index.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ describe('Plugin', () => {
131131
tracer.scope().activate(span, () => {
132132
winston.info('message')
133133

134-
expect(spy).to.not.have.been.calledWithMatch(meta.dd)
134+
expect(spy).to.have.been.calledWithMatch(meta.dd)
135135
})
136136
})
137137
})
@@ -336,6 +336,7 @@ describe('Plugin', () => {
336336
expect(await logServer.logPromise).to.include(meta.dd)
337337
})
338338
})
339+
339340
// Only run this test with Winston v3.17.0+ since it uses newer format functions
340341
if (semver.intersects(version, '>=3.17.0')) {
341342
describe('with error formatting matching temp.js example', () => {

packages/dd-trace/src/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ class Config {
545545
defaults.testManagementAttemptToFixRetries = 20
546546
defaults.isTestManagementEnabled = false
547547
defaults.isImpactedTestsEnabled = false
548-
defaults.logInjection = false
548+
defaults.logInjection = 'structured'
549549
defaults.lookup = undefined
550550
defaults.inferredProxyServicesEnabled = false
551551
defaults.memcachedCommandEnabled = false

0 commit comments

Comments
 (0)