Skip to content

Commit 28bca83

Browse files
authored
[DI] Improve trace/span-id probe results tests (#5036)
Add test that checks if everything works as expected even if tracing is disabled.
1 parent 50619f7 commit 28bca83

File tree

2 files changed

+31
-12
lines changed

2 files changed

+31
-12
lines changed

integration-tests/debugger/basic.spec.js

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,17 @@ const { ACKNOWLEDGED, ERROR } = require('../../packages/dd-trace/src/appsec/remo
99
const { version } = require('../../package.json')
1010

1111
describe('Dynamic Instrumentation', function () {
12-
const t = setup()
12+
describe('DD_TRACING_ENABLED=true', function () {
13+
testWithTracingEnabled()
14+
})
15+
16+
describe('DD_TRACING_ENABLED=false', function () {
17+
testWithTracingEnabled(false)
18+
})
19+
})
20+
21+
function testWithTracingEnabled (tracingEnabled = true) {
22+
const t = setup({ DD_TRACING_ENABLED: tracingEnabled })
1323

1424
it('base case: target app should work as expected if no test probe has been added', async function () {
1525
const response = await t.axios.get(t.breakpoint.url)
@@ -273,13 +283,17 @@ describe('Dynamic Instrumentation', function () {
273283

274284
assert.match(payload.logger.thread_id, /^pid:\d+$/)
275285

276-
assert.isObject(payload.dd)
277-
assert.hasAllKeys(payload.dd, ['trace_id', 'span_id'])
278-
assert.typeOf(payload.dd.trace_id, 'string')
279-
assert.typeOf(payload.dd.span_id, 'string')
280-
assert.isAbove(payload.dd.trace_id.length, 0)
281-
assert.isAbove(payload.dd.span_id.length, 0)
282-
dd = payload.dd
286+
if (tracingEnabled) {
287+
assert.isObject(payload.dd)
288+
assert.hasAllKeys(payload.dd, ['trace_id', 'span_id'])
289+
assert.typeOf(payload.dd.trace_id, 'string')
290+
assert.typeOf(payload.dd.span_id, 'string')
291+
assert.isAbove(payload.dd.trace_id.length, 0)
292+
assert.isAbove(payload.dd.span_id.length, 0)
293+
dd = payload.dd
294+
} else {
295+
assert.doesNotHaveAnyKeys(payload, ['dd'])
296+
}
283297

284298
assertUUID(payload['debugger.snapshot'].id)
285299
assert.isNumber(payload['debugger.snapshot'].timestamp)
@@ -303,7 +317,11 @@ describe('Dynamic Instrumentation', function () {
303317
assert.strictEqual(topFrame.lineNumber, t.breakpoint.line)
304318
assert.strictEqual(topFrame.columnNumber, 3)
305319

306-
assertDD()
320+
if (tracingEnabled) {
321+
assertDD()
322+
} else {
323+
done()
324+
}
307325
})
308326

309327
t.agent.addRemoteConfig(t.rcConfig)
@@ -501,4 +519,4 @@ describe('Dynamic Instrumentation', function () {
501519
t.agent.addRemoteConfig(t.rcConfig)
502520
})
503521
})
504-
})
522+
}

integration-tests/debugger/utils.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = {
1818
setup
1919
}
2020

21-
function setup () {
21+
function setup (env) {
2222
let sandbox, cwd, appPort
2323
const breakpoints = getBreakpointInfo(1) // `1` to disregard the `setup` function
2424
const t = {
@@ -91,7 +91,8 @@ function setup () {
9191
DD_DYNAMIC_INSTRUMENTATION_ENABLED: true,
9292
DD_TRACE_AGENT_PORT: t.agent.port,
9393
DD_TRACE_DEBUG: process.env.DD_TRACE_DEBUG, // inherit to make debugging the sandbox easier
94-
DD_REMOTE_CONFIG_POLL_INTERVAL_SECONDS: pollInterval
94+
DD_REMOTE_CONFIG_POLL_INTERVAL_SECONDS: pollInterval,
95+
...env
9596
}
9697
})
9798
t.axios = Axios.create({

0 commit comments

Comments
 (0)