Skip to content

Commit 76d688e

Browse files
authored
[DI] Don't rely on logs track to split JSON keys on periods (#5539)
The logs track will split a JSON key like `debugger.snapshot` into `debugger: { snapshot }`. This saves a tiny amount of object creation client side, but makes each installed tracer dependant on this custom behavior from the logs track. To allow us more flexibility in the future, better not rely on this oddity.
1 parent 6590e70 commit 76d688e

8 files changed

Lines changed: 34 additions & 32 deletions

File tree

integration-tests/debugger/basic.spec.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ describe('Dynamic Instrumentation', function () {
318318
})
319319

320320
t.agent.on('debugger-input', ({ payload }) => {
321-
payload.forEach(({ 'debugger.snapshot': { timestamp } }) => {
321+
payload.forEach(({ debugger: { snapshot: { timestamp } } }) => {
322322
if (prev !== undefined) {
323323
const duration = timestamp - prev
324324
clearTimeout(timer)
@@ -364,8 +364,8 @@ describe('Dynamic Instrumentation', function () {
364364

365365
t.agent.on('debugger-input', ({ payload }) => {
366366
payload.forEach((result) => {
367-
const _state = state[result['debugger.snapshot'].probe.id]
368-
const { timestamp } = result['debugger.snapshot']
367+
const _state = state[result.debugger.snapshot.probe.id]
368+
const { timestamp } = result.debugger.snapshot
369369
if (_state.prev !== undefined) {
370370
const duration = timestamp - _state.prev
371371
clearTimeout(_state.timer)
@@ -588,36 +588,38 @@ function assertBasicInputPayload (t, payload) {
588588
version,
589589
thread_name: 'MainThread'
590590
},
591-
'debugger.snapshot': {
592-
probe: {
593-
id: t.rcConfig.config.id,
594-
version: 0,
595-
location: { file: t.breakpoint.deployedFile, lines: [String(t.breakpoint.line)] }
596-
},
597-
language: 'javascript'
591+
debugger: {
592+
snapshot: {
593+
probe: {
594+
id: t.rcConfig.config.id,
595+
version: 0,
596+
location: { file: t.breakpoint.deployedFile, lines: [String(t.breakpoint.line)] }
597+
},
598+
language: 'javascript'
599+
}
598600
}
599601
}
600602

601603
assertObjectContains(payload, expected)
602604

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

605-
assertUUID(payload['debugger.snapshot'].id)
606-
assert.isNumber(payload['debugger.snapshot'].timestamp)
607-
assert.isTrue(payload['debugger.snapshot'].timestamp > Date.now() - 1000 * 60)
608-
assert.isTrue(payload['debugger.snapshot'].timestamp <= Date.now())
607+
assertUUID(payload.debugger.snapshot.id)
608+
assert.isNumber(payload.debugger.snapshot.timestamp)
609+
assert.isTrue(payload.debugger.snapshot.timestamp > Date.now() - 1000 * 60)
610+
assert.isTrue(payload.debugger.snapshot.timestamp <= Date.now())
609611

610-
assert.isArray(payload['debugger.snapshot'].stack)
611-
assert.isAbove(payload['debugger.snapshot'].stack.length, 0)
612-
for (const frame of payload['debugger.snapshot'].stack) {
612+
assert.isArray(payload.debugger.snapshot.stack)
613+
assert.isAbove(payload.debugger.snapshot.stack.length, 0)
614+
for (const frame of payload.debugger.snapshot.stack) {
613615
assert.isObject(frame)
614616
assert.hasAllKeys(frame, ['fileName', 'function', 'lineNumber', 'columnNumber'])
615617
assert.isString(frame.fileName)
616618
assert.isString(frame.function)
617619
assert.isAbove(frame.lineNumber, 0)
618620
assert.isAbove(frame.columnNumber, 0)
619621
}
620-
const topFrame = payload['debugger.snapshot'].stack[0]
622+
const topFrame = payload.debugger.snapshot.stack[0]
621623
// path seems to be prefeixed with `/private` on Mac
622624
assert.match(topFrame.fileName, new RegExp(`${t.appFile}$`))
623625
assert.strictEqual(topFrame.function, 'fooHandler')

integration-tests/debugger/redact.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('Dynamic Instrumentation snapshot PII redaction', function () {
1616

1717
t.agent.addRemoteConfig(t.generateRemoteConfig({ captureSnapshot: true }))
1818

19-
const [{ payload: [{ 'debugger.snapshot': { captures } }] }] = await promise
19+
const [{ payload: [{ debugger: { snapshot: { captures } } }] }] = await promise
2020
const { locals } = captures.lines[t.breakpoint.line]
2121

2222
assert.deepPropertyVal(locals, 'foo', { type: 'string', notCapturedReason: 'redactedIdent' })
@@ -38,7 +38,7 @@ describe('Dynamic Instrumentation snapshot PII redaction', function () {
3838

3939
t.agent.addRemoteConfig(t.generateRemoteConfig({ captureSnapshot: true }))
4040

41-
const [{ payload: [{ 'debugger.snapshot': { captures } }] }] = await promise
41+
const [{ payload: [{ debugger: { snapshot: { captures } } }] }] = await promise
4242
const { locals } = captures.lines[t.breakpoint.line]
4343

4444
assert.deepPropertyVal(locals, 'secret', { type: 'string', value: 'shh!' })

integration-tests/debugger/snapshot-global-sample-rate.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ describe('Dynamic Instrumentation', function () {
5050
})
5151

5252
t.agent.on('debugger-input', ({ payload }) => {
53-
payload.forEach(({ 'debugger.snapshot': { timestamp } }) => {
53+
payload.forEach(({ debugger: { snapshot: { timestamp } } }) => {
5454
if (isDone) return
5555
if (start === 0) start = timestamp
5656
if (++hitBreakpoints <= MAX_SNAPSHOTS_PER_SECOND_GLOBALLY) {

integration-tests/debugger/snapshot-pruning.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('Dynamic Instrumentation', function () {
1313
it('should prune snapshot if payload is too large', function (done) {
1414
t.agent.on('debugger-input', ({ payload: [payload] }) => {
1515
assert.isBelow(Buffer.byteLength(JSON.stringify(payload)), 1024 * 1024) // 1MB
16-
assert.deepEqual(payload['debugger.snapshot'].captures, {
16+
assert.deepEqual(payload.debugger.snapshot.captures, {
1717
lines: {
1818
[t.breakpoint.line]: {
1919
locals: {

integration-tests/debugger/snapshot.spec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('Dynamic Instrumentation', function () {
1111
beforeEach(t.triggerBreakpoint)
1212

1313
it('should capture a snapshot', function (done) {
14-
t.agent.on('debugger-input', ({ payload: [{ 'debugger.snapshot': { captures } }] }) => {
14+
t.agent.on('debugger-input', ({ payload: [{ debugger: { snapshot: { captures } } }] }) => {
1515
assert.deepEqual(Object.keys(captures), ['lines'])
1616
assert.deepEqual(Object.keys(captures.lines), [String(t.breakpoint.line)])
1717

@@ -114,7 +114,7 @@ describe('Dynamic Instrumentation', function () {
114114
})
115115

116116
it('should respect maxReferenceDepth', function (done) {
117-
t.agent.on('debugger-input', ({ payload: [{ 'debugger.snapshot': { captures } }] }) => {
117+
t.agent.on('debugger-input', ({ payload: [{ debugger: { snapshot: { captures } } }] }) => {
118118
const { locals } = captures.lines[t.breakpoint.line]
119119
delete locals.request
120120
delete locals.fastify
@@ -150,7 +150,7 @@ describe('Dynamic Instrumentation', function () {
150150
})
151151

152152
it('should respect maxLength', function (done) {
153-
t.agent.on('debugger-input', ({ payload: [{ 'debugger.snapshot': { captures } }] }) => {
153+
t.agent.on('debugger-input', ({ payload: [{ debugger: { snapshot: { captures } } }] }) => {
154154
const { locals } = captures.lines[t.breakpoint.line]
155155

156156
assert.deepEqual(locals.lstr, {
@@ -167,7 +167,7 @@ describe('Dynamic Instrumentation', function () {
167167
})
168168

169169
it('should respect maxCollectionSize', function (done) {
170-
t.agent.on('debugger-input', ({ payload: [{ 'debugger.snapshot': { captures } }] }) => {
170+
t.agent.on('debugger-input', ({ payload: [{ debugger: { snapshot: { captures } } }] }) => {
171171
const { locals } = captures.lines[t.breakpoint.line]
172172

173173
assert.deepEqual(locals.arr, {
@@ -205,7 +205,7 @@ describe('Dynamic Instrumentation', function () {
205205
}
206206
}
207207

208-
t.agent.on('debugger-input', ({ payload: [{ 'debugger.snapshot': { captures } }] }) => {
208+
t.agent.on('debugger-input', ({ payload: [{ debugger: { snapshot: { captures } } }] }) => {
209209
const { locals } = captures.lines[t.breakpoint.line]
210210

211211
assert.deepStrictEqual(Object.keys(locals), [

integration-tests/debugger/source-map-support.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('Dynamic Instrumentation', function () {
1414
beforeEach(t.triggerBreakpoint)
1515

1616
it('should support source maps', function (done) {
17-
t.agent.on('debugger-input', ({ payload: [{ 'debugger.snapshot': { probe: { location } } }] }) => {
17+
t.agent.on('debugger-input', ({ payload: [{ debugger: { snapshot: { probe: { location } } } }] }) => {
1818
assert.deepEqual(location, {
1919
file: 'target-app/source-map-support/typescript.ts',
2020
lines: ['9']
@@ -35,7 +35,7 @@ describe('Dynamic Instrumentation', function () {
3535
beforeEach(t.triggerBreakpoint)
3636

3737
it('should support source maps', function (done) {
38-
t.agent.on('debugger-input', ({ payload: [{ 'debugger.snapshot': { probe: { location } } }] }) => {
38+
t.agent.on('debugger-input', ({ payload: [{ debugger: { snapshot: { probe: { location } } } }] }) => {
3939
assert.deepEqual(location, {
4040
file: 'target-app/source-map-support/minify.js',
4141
lines: ['6']

packages/dd-trace/src/debugger/devtools_client/send.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ function send (message, logger, dd, snapshot) {
3939
message,
4040
logger,
4141
dd,
42-
'debugger.snapshot': snapshot
42+
debugger: { snapshot }
4343
}
4444

4545
let json = JSON.stringify(payload)
4646
let size = Buffer.byteLength(json)
4747

4848
if (size > MAX_LOG_PAYLOAD_SIZE) {
4949
// TODO: This is a very crude way to handle large payloads. Proper pruning will be implemented later (DEBUG-2624)
50-
const line = Object.values(payload['debugger.snapshot'].captures.lines)[0]
50+
const line = Object.values(payload.debugger.snapshot.captures.lines)[0]
5151
line.locals = {
5252
notCapturedReason: 'Snapshot was too large',
5353
size: Object.keys(line.locals).length

packages/dd-trace/test/debugger/devtools_client/send.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,6 @@ function getPayload (_message = message) {
9292
message: _message,
9393
logger,
9494
dd,
95-
'debugger.snapshot': snapshot
95+
debugger: { snapshot }
9696
}
9797
}

0 commit comments

Comments
 (0)