Skip to content

Commit

Permalink
[DI] Improve trace/span-id probe results tests (#5036)
Browse files Browse the repository at this point in the history
Add test that checks if everything works as expected even if tracing is
disabled.
  • Loading branch information
watson authored Dec 18, 2024
1 parent 50619f7 commit 28bca83
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
38 changes: 28 additions & 10 deletions integration-tests/debugger/basic.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,17 @@ const { ACKNOWLEDGED, ERROR } = require('../../packages/dd-trace/src/appsec/remo
const { version } = require('../../package.json')

describe('Dynamic Instrumentation', function () {
const t = setup()
describe('DD_TRACING_ENABLED=true', function () {
testWithTracingEnabled()
})

describe('DD_TRACING_ENABLED=false', function () {
testWithTracingEnabled(false)
})
})

function testWithTracingEnabled (tracingEnabled = true) {
const t = setup({ DD_TRACING_ENABLED: tracingEnabled })

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

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

assert.isObject(payload.dd)
assert.hasAllKeys(payload.dd, ['trace_id', 'span_id'])
assert.typeOf(payload.dd.trace_id, 'string')
assert.typeOf(payload.dd.span_id, 'string')
assert.isAbove(payload.dd.trace_id.length, 0)
assert.isAbove(payload.dd.span_id.length, 0)
dd = payload.dd
if (tracingEnabled) {
assert.isObject(payload.dd)
assert.hasAllKeys(payload.dd, ['trace_id', 'span_id'])
assert.typeOf(payload.dd.trace_id, 'string')
assert.typeOf(payload.dd.span_id, 'string')
assert.isAbove(payload.dd.trace_id.length, 0)
assert.isAbove(payload.dd.span_id.length, 0)
dd = payload.dd
} else {
assert.doesNotHaveAnyKeys(payload, ['dd'])
}

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

assertDD()
if (tracingEnabled) {
assertDD()
} else {
done()
}
})

t.agent.addRemoteConfig(t.rcConfig)
Expand Down Expand Up @@ -501,4 +519,4 @@ describe('Dynamic Instrumentation', function () {
t.agent.addRemoteConfig(t.rcConfig)
})
})
})
}
5 changes: 3 additions & 2 deletions integration-tests/debugger/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = {
setup
}

function setup () {
function setup (env) {
let sandbox, cwd, appPort
const breakpoints = getBreakpointInfo(1) // `1` to disregard the `setup` function
const t = {
Expand Down Expand Up @@ -91,7 +91,8 @@ function setup () {
DD_DYNAMIC_INSTRUMENTATION_ENABLED: true,
DD_TRACE_AGENT_PORT: t.agent.port,
DD_TRACE_DEBUG: process.env.DD_TRACE_DEBUG, // inherit to make debugging the sandbox easier
DD_REMOTE_CONFIG_POLL_INTERVAL_SECONDS: pollInterval
DD_REMOTE_CONFIG_POLL_INTERVAL_SECONDS: pollInterval,
...env
}
})
t.axios = Axios.create({
Expand Down

0 comments on commit 28bca83

Please sign in to comment.