-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DI] Adhere to maxFieldCount limit in snapshots (#4829)
The limit controls the maximum number of properties collected on an object. The default is 20. It's also applied on each scope when collecting properties. If there's for example more than maxFieldCount properties in the current scope, they are not all collected.
- Loading branch information
Showing
11 changed files
with
190 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
packages/dd-trace/src/debugger/devtools_client/snapshot/symbols.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
'use stict' | ||
|
||
module.exports = { | ||
collectionSizeSym: Symbol('datadog.collectionSize') | ||
collectionSizeSym: Symbol('datadog.collectionSize'), | ||
fieldCountSym: Symbol('datadog.fieldCount') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
packages/dd-trace/test/debugger/devtools_client/snapshot/max-field-count-scopes.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict' | ||
|
||
require('../../../setup/mocha') | ||
|
||
const { getTargetCodePath, enable, teardown, assertOnBreakpoint, setAndTriggerBreakpoint } = require('./utils') | ||
|
||
const target = getTargetCodePath(__filename) | ||
|
||
describe('debugger -> devtools client -> snapshot.getLocalStateForCallFrame', function () { | ||
describe('maxFieldCount', function () { | ||
beforeEach(enable(__filename)) | ||
|
||
afterEach(teardown) | ||
|
||
describe('shold respect maxFieldCount on each collected scope', function () { | ||
const maxFieldCount = 3 | ||
let state | ||
|
||
beforeEach(function (done) { | ||
assertOnBreakpoint(done, { maxFieldCount }, (_state) => { | ||
state = _state | ||
}) | ||
setAndTriggerBreakpoint(target, 11) | ||
}) | ||
|
||
it('should capture expected snapshot', function () { | ||
// Expect the snapshot to have captured the first 3 fields from each scope | ||
expect(state).to.have.keys(['a1', 'b1', 'c1', 'a2', 'b2', 'c2']) | ||
}) | ||
}) | ||
}) | ||
}) |
49 changes: 49 additions & 0 deletions
49
packages/dd-trace/test/debugger/devtools_client/snapshot/max-field-count.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
'use strict' | ||
|
||
require('../../../setup/mocha') | ||
|
||
const { getTargetCodePath, enable, teardown, assertOnBreakpoint, setAndTriggerBreakpoint } = require('./utils') | ||
|
||
const DEFAULT_MAX_FIELD_COUNT = 20 | ||
const target = getTargetCodePath(__filename) | ||
|
||
describe('debugger -> devtools client -> snapshot.getLocalStateForCallFrame', function () { | ||
describe('maxFieldCount', function () { | ||
beforeEach(enable(__filename)) | ||
|
||
afterEach(teardown) | ||
|
||
describe('shold respect the default maxFieldCount if not set', generateTestCases()) | ||
|
||
describe('shold respect maxFieldCount if set to 10', generateTestCases({ maxFieldCount: 10 })) | ||
}) | ||
}) | ||
|
||
function generateTestCases (config) { | ||
const maxFieldCount = config?.maxFieldCount ?? DEFAULT_MAX_FIELD_COUNT | ||
let state | ||
|
||
const expectedFields = {} | ||
for (let i = 1; i <= maxFieldCount; i++) { | ||
expectedFields[`field${i}`] = { type: 'number', value: i.toString() } | ||
} | ||
|
||
return function () { | ||
beforeEach(function (done) { | ||
assertOnBreakpoint(done, config, (_state) => { | ||
state = _state | ||
}) | ||
setAndTriggerBreakpoint(target, 11) | ||
}) | ||
|
||
it('should capture expected snapshot', function () { | ||
expect(state).to.have.keys(['obj']) | ||
expect(state).to.have.deep.property('obj', { | ||
type: 'Object', | ||
fields: expectedFields, | ||
notCapturedReason: 'fieldCount', | ||
size: 40 | ||
}) | ||
}) | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...ges/dd-trace/test/debugger/devtools_client/snapshot/target-code/max-field-count-scopes.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use stict' | ||
|
||
function run () { | ||
// local scope | ||
const { a1, b1, c1, d1 } = {} | ||
|
||
{ | ||
// block scope | ||
const { a2, b2, c2, d2 } = {} | ||
|
||
return { a1, b1, c1, d1, a2, b2, c2, d2 } // breakpoint at this line | ||
} | ||
} | ||
|
||
module.exports = { run } |
14 changes: 14 additions & 0 deletions
14
packages/dd-trace/test/debugger/devtools_client/snapshot/target-code/max-field-count.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use stict' | ||
|
||
function run () { | ||
const obj = {} | ||
|
||
// 40 is larger the default maxFieldCount of 20 | ||
for (let i = 1; i <= 40; i++) { | ||
obj[`field${i}`] = i | ||
} | ||
|
||
return 'my return value' // breakpoint at this line | ||
} | ||
|
||
module.exports = { run } |