Skip to content

Commit 2ad5d24

Browse files
watsonrochdev
authored andcommitted
[DI] Use custom error property for errors reporting state snapshot (#5731)
If for whatever reason the probe state snapshot cannot be captured or included in the payload, an error message should be included instead. The backend doesn’t support a root `notCapturedReason`, so instead a new `debugger.snapshot.captureError` should be introduced to hold a string error message.
1 parent 7d64523 commit 2ad5d24

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,13 @@ 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, {
17-
lines: {
18-
[t.breakpoint.line]: {
19-
locals: {
20-
notCapturedReason: 'Snapshot was too large',
21-
size: 6
22-
}
23-
}
24-
}
25-
})
16+
assert.notProperty(payload.debugger.snapshot, 'captures')
17+
assert.strictEqual(
18+
payload.debugger.snapshot.captureError,
19+
'Snapshot was too large (max allowed size is 1 MiB). ' +
20+
'Consider reducing the capture depth or turn off "Capture Variables" completely, ' +
21+
'and instead include the variables of interest directly in the message template.'
22+
)
2623
done()
2724
})
2825

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ const { version } = require('../../../../../package.json')
1313
module.exports = send
1414

1515
const MAX_MESSAGE_LENGTH = 8 * 1024 // 8KB
16-
const MAX_LOG_PAYLOAD_SIZE = 1024 * 1024 // 1MB
16+
const MAX_LOG_PAYLOAD_SIZE_MB = 1
17+
const MAX_LOG_PAYLOAD_SIZE_BYTES = MAX_LOG_PAYLOAD_SIZE_MB * 1024 * 1024
1718

1819
const ddsource = 'dd_debugger'
1920
const hostname = getHostname()
@@ -48,13 +49,13 @@ function send (message, logger, dd, snapshot) {
4849
let json = JSON.stringify(payload)
4950
let size = Buffer.byteLength(json)
5051

51-
if (size > MAX_LOG_PAYLOAD_SIZE) {
52+
if (size > MAX_LOG_PAYLOAD_SIZE_BYTES) {
5253
// TODO: This is a very crude way to handle large payloads. Proper pruning will be implemented later (DEBUG-2624)
53-
const line = Object.values(payload.debugger.snapshot.captures.lines)[0]
54-
line.locals = {
55-
notCapturedReason: 'Snapshot was too large',
56-
size: Object.keys(line.locals).length
57-
}
54+
delete payload.debugger.snapshot.captures
55+
payload.debugger.snapshot.captureError =
56+
`Snapshot was too large (max allowed size is ${MAX_LOG_PAYLOAD_SIZE_MB} MiB). ` +
57+
'Consider reducing the capture depth or turn off "Capture Variables" completely, ' +
58+
'and instead include the variables of interest directly in the message template.'
5859
json = JSON.stringify(payload)
5960
size = Buffer.byteLength(json)
6061
}

0 commit comments

Comments
 (0)