Skip to content

Commit d19c433

Browse files
authored
fix(debugger): don't expect probe config to contain capture object (#6807)
Don't throw if the probe config doesn't contain a `capture` object when `captureSnapshot: true`. Currently, all probe config objects does contain a `capture` object, but in case this ever changes in the future we'll be prepared.
1 parent 75b67c2 commit d19c433

File tree

3 files changed

+73
-13
lines changed

3 files changed

+73
-13
lines changed

integration-tests/debugger/snapshot.spec.js

Lines changed: 68 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,9 @@ describe('Dynamic Instrumentation', function () {
4040
regex: { type: 'RegExp', value: '/bar/i' },
4141
arr: {
4242
type: 'Array',
43-
elements: [
44-
{ type: 'number', value: '1' },
45-
{ type: 'number', value: '2' },
46-
{ type: 'number', value: '3' },
47-
{ type: 'number', value: '4' },
48-
{ type: 'number', value: '5' },
49-
],
43+
elements: Array.from({ length: 100 }, (_, i) => ({ type: 'number', value: (i + 1).toString() })),
44+
notCapturedReason: 'collectionSize',
45+
size: 200,
5046
},
5147
obj: {
5248
type: 'Object',
@@ -179,7 +175,7 @@ describe('Dynamic Instrumentation', function () {
179175
{ type: 'number', value: '3' },
180176
],
181177
notCapturedReason: 'collectionSize',
182-
size: 5,
178+
size: 200,
183179
})
184180

185181
done()
@@ -235,6 +231,70 @@ describe('Dynamic Instrumentation', function () {
235231

236232
t.agent.addRemoteConfig(t.generateRemoteConfig({ captureSnapshot: true, capture: { maxFieldCount } }))
237233
})
234+
235+
it('should capture a snapshot even if there is no capture object (DEBUG-4611)', function (done) {
236+
t.agent.on('debugger-input', ({ payload: [{ debugger: { snapshot: { probe } } }] }) => {
237+
assert.strictEqual(probe.id, config.config.id)
238+
done()
239+
})
240+
241+
const config = t.generateRemoteConfig({ captureSnapshot: true })
242+
delete config.config.capture
243+
t.agent.addRemoteConfig(config)
244+
})
245+
246+
it('should use default value for maxReferenceDepth if not provided', function (done) {
247+
t.agent.on('debugger-input', ({ payload: [{ debugger: { snapshot: { captures } } }] }) => {
248+
const { locals } = captures.lines[t.breakpoint.line]
249+
assert.strictEqual(locals.obj.fields.foo.fields.deep.fields.nested.notCapturedReason, 'depth')
250+
done()
251+
})
252+
253+
const config = t.generateRemoteConfig({ captureSnapshot: true })
254+
delete config.config.capture.maxReferenceDepth
255+
t.agent.addRemoteConfig(config)
256+
})
257+
258+
it('should use default value for maxLength if not provided', function (done) {
259+
t.agent.on('debugger-input', ({ payload: [{ debugger: { snapshot: { captures } } }] }) => {
260+
const { locals } = captures.lines[t.breakpoint.line]
261+
assert.strictEqual(locals.lstr.value.length, 255)
262+
assert.strictEqual(locals.lstr.truncated, true)
263+
assert.strictEqual(locals.lstr.size, 445)
264+
done()
265+
})
266+
267+
const config = t.generateRemoteConfig({ captureSnapshot: true })
268+
delete config.config.capture.maxLength
269+
t.agent.addRemoteConfig(config)
270+
})
271+
272+
it('should use default value for maxCollectionSize if not provided', function (done) {
273+
t.agent.on('debugger-input', ({ payload: [{ debugger: { snapshot: { captures } } }] }) => {
274+
const { locals } = captures.lines[t.breakpoint.line]
275+
assert.strictEqual(locals.arr.notCapturedReason, 'collectionSize')
276+
assert.strictEqual(locals.arr.elements.length, 100)
277+
done()
278+
})
279+
280+
const config = t.generateRemoteConfig({ captureSnapshot: true })
281+
delete config.config.capture.maxCollectionSize
282+
t.agent.addRemoteConfig(config)
283+
})
284+
285+
it('should use default value for maxFieldCount if not provided', function (done) {
286+
t.agent.on('debugger-input', ({ payload: [{ debugger: { snapshot: { captures } } }] }) => {
287+
const { raw } = captures.lines[t.breakpoint.line].locals.request.fields
288+
assert.strictEqual(raw.notCapturedReason, 'fieldCount')
289+
assert.strictEqual(Object.keys(raw.fields).length, 20)
290+
assert.ok(raw.size > 20)
291+
done()
292+
})
293+
294+
const config = t.generateRemoteConfig({ captureSnapshot: true })
295+
delete config.config.capture.maxFieldCount
296+
t.agent.addRemoteConfig(config)
297+
})
238298
})
239299
})
240300
})

integration-tests/debugger/target-app/snapshot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fastify.get('/:name', function handler (request) {
1919
const lstr = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'
2020
const sym = Symbol('foo')
2121
const regex = /bar/i
22-
const arr = [1, 2, 3, 4, 5]
22+
const arr = Array.from({ length: 200 }, (_, i) => i + 1)
2323
const obj = {
2424
foo: {
2525
baz: 42,

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ session.on('Debugger.paused', async ({ params }) => {
117117
}
118118

119119
snapshotProbeIndex[numberOfProbesWithSnapshots++] = probes.length
120-
maxReferenceDepth = highestOrUndefined(probe.capture.maxReferenceDepth, maxReferenceDepth)
121-
maxCollectionSize = highestOrUndefined(probe.capture.maxCollectionSize, maxCollectionSize)
122-
maxFieldCount = highestOrUndefined(probe.capture.maxFieldCount, maxFieldCount)
123-
maxLength = highestOrUndefined(probe.capture.maxLength, maxLength)
120+
maxReferenceDepth = highestOrUndefined(probe.capture?.maxReferenceDepth, maxReferenceDepth)
121+
maxCollectionSize = highestOrUndefined(probe.capture?.maxCollectionSize, maxCollectionSize)
122+
maxFieldCount = highestOrUndefined(probe.capture?.maxFieldCount, maxFieldCount)
123+
maxLength = highestOrUndefined(probe.capture?.maxLength, maxLength)
124124
}
125125

126126
if (probe.condition !== undefined) {

0 commit comments

Comments
 (0)