-
Notifications
You must be signed in to change notification settings - Fork 306
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
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
9 changed files
with
143 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
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 | ||
}) | ||
}) | ||
} | ||
} |
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 } |