Skip to content

Commit 3f928f1

Browse files
committed
Address review comments
1 parent 5ddd0f1 commit 3f928f1

3 files changed

Lines changed: 17 additions & 26 deletions

File tree

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,13 @@ function lock (fn) {
320320
* @returns {Promise<void>}
321321
*/
322322
async function removeProbeFromSampler (id) {
323-
await session.post('Runtime.evaluate', {
324-
expression: getRemoveProbeExpression(id),
325-
}).catch(err => {
323+
try {
324+
await session.post('Runtime.evaluate', {
325+
expression: getRemoveProbeExpression(id),
326+
})
327+
} catch (err) {
326328
log.error('[debugger:devtools_client] Error removing probe %s from sampler', id, err)
327-
})
329+
}
328330
}
329331

330332
function generateLocationKey (scriptId, lineNumber, columnNumber) {

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
const { DD_TRACE_SYMBOL, PROBE_SAMPLER_SYMBOL } = require('../probe_sampler_constants')
44

5+
const SAMPLER_EXPRESSION = `globalThis[Symbol.for(${JSON.stringify(DD_TRACE_SYMBOL)})]?.` +
6+
`[Symbol.for(${JSON.stringify(PROBE_SAMPLER_SYMBOL)})]`
7+
58
module.exports = {
69
compileBreakpointCondition,
710
getRemoveProbeExpression,
@@ -15,7 +18,7 @@ module.exports = {
1518
* @returns {string}
1619
*/
1720
function getRemoveProbeExpression (id) {
18-
return `${getSamplerExpression()}?.remove(${JSON.stringify(id)})`
21+
return `${SAMPLER_EXPRESSION}?.remove(${JSON.stringify(id)})`
1922
}
2023

2124
/**
@@ -43,7 +46,7 @@ function compileBreakpointCondition (probes) {
4346
// file-path filename) won't see it and will silently never fire. Known limitation: a breakpoint
4447
// condition has no realm-independent handle to reach, so we degrade rather than crash.
4548
return `(() => {
46-
const $dd_sampler = ${getSamplerExpression()}
49+
const $dd_sampler = ${SAMPLER_EXPRESSION}
4750
if ($dd_sampler === undefined) return false
4851
let $dd_sampled = false
4952
${probeConditions.join('\n ')}
@@ -78,8 +81,3 @@ function compileProbeCondition (probe) {
7881
}
7982
} catch {}`
8083
}
81-
82-
function getSamplerExpression () {
83-
return `globalThis[Symbol.for(${JSON.stringify(DD_TRACE_SYMBOL)})]?.` +
84-
`[Symbol.for(${JSON.stringify(PROBE_SAMPLER_SYMBOL)})]`
85-
}

packages/dd-trace/src/debugger/probe_sampler.js

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ const {
1010
SAMPLED_PROBE_OVERFLOW_INDEX,
1111
} = require('./probe_sampler_constants')
1212

13+
const ddTraceGlobal = /** @type {Record<symbol, SharedArrayBuffer | object | undefined>} */ (
14+
/** @type {Record<symbol, unknown>} */ (globalThis)[Symbol.for(DD_TRACE_SYMBOL)]
15+
)
16+
1317
module.exports = {
1418
installProbeSampler,
1519
uninstallProbeSampler,
@@ -21,7 +25,6 @@ module.exports = {
2125
* @returns {SharedArrayBuffer} The shared sampler buffer to pass to the debugger worker.
2226
*/
2327
function installProbeSampler () {
24-
const ddTrace = getDatadogGlobal()
2528
const buffer = createProbeSamplerBuffer()
2629

2730
const lastCaptureNsByProbeId = new Map()
@@ -33,7 +36,7 @@ function installProbeSampler () {
3336
let globalSnapshotSamplingRateWindowStart = 0n
3437
let snapshotsSampledWithinTheLastSecond = 0
3538

36-
ddTrace[Symbol.for(PROBE_SAMPLER_SYMBOL)] = {
39+
ddTraceGlobal[Symbol.for(PROBE_SAMPLER_SYMBOL)] = {
3740
/**
3841
* Decide if a probe should be sampled and store sampled probe indexes for the debugger worker.
3942
*
@@ -94,19 +97,7 @@ function installProbeSampler () {
9497
* Remove the runtime sampler from the debuggee context.
9598
*/
9699
function uninstallProbeSampler () {
97-
const ddTrace = getDatadogGlobal()
98-
delete ddTrace[Symbol.for(PROBE_SAMPLER_SYMBOL)]
99-
}
100-
101-
/**
102-
* Get the Datadog global object.
103-
*
104-
* @returns {Record<symbol, SharedArrayBuffer | object | undefined>}
105-
*/
106-
function getDatadogGlobal () {
107-
return /** @type {Record<symbol, SharedArrayBuffer | object | undefined>} */ (
108-
/** @type {Record<symbol, unknown>} */ (globalThis)[Symbol.for(DD_TRACE_SYMBOL)]
109-
)
100+
delete ddTraceGlobal[Symbol.for(PROBE_SAMPLER_SYMBOL)]
110101
}
111102

112103
/**

0 commit comments

Comments
 (0)