@@ -8,13 +8,12 @@ import type { InitializedProbe } from './probes'
88import {
99 checkConditionErrorBudget ,
1010 checkGlobalSnapshotBudget ,
11- hasProbeLifetimeBudgetRemaining ,
12- removeProbe ,
11+ enforceProbeLifetimeBudget ,
12+ recordProbeEventSent ,
1313 resetProbeBudgetConfiguration ,
1414 setProbeBudgetConfiguration ,
1515} from './probes'
1616import type { ActiveEntry } from './activeEntries'
17- import { active } from './activeEntries'
1817import { captureStackTrace , parseStackTrace } from './stacktrace'
1918import { evaluateProbeMessage } from './template'
2019import { evaluateProbeCondition , isConditionEvaluationError } from './condition'
@@ -40,7 +39,6 @@ export function resetDebuggerTransport(): void {
4039 debuggerBatch = undefined
4140 debuggerConfig = undefined
4241 cachedDDtags = undefined
43- active . clear ( )
4442 resetProbeBudgetConfiguration ( )
4543}
4644
@@ -57,22 +55,16 @@ export function onEntry(probes: InitializedProbe[], self: any, args: Record<stri
5755
5856 // TODO: A lot of repeated work performed for each probe that could be shared between probes
5957 for ( const probe of probes ) {
60- if ( ! hasProbeLifetimeBudgetRemaining ( probe ) ) {
58+ if ( ! enforceProbeLifetimeBudget ( probe ) ) {
6159 continue
6260 }
6361
64- let stack = active . get ( probe . id ) // TODO: Should we use the functionId instead?
65- if ( ! stack ) {
66- stack = [ ]
67- active . set ( probe . id , stack )
68- }
69-
7062 // Skip if sampling budget is exceeded
7163 if (
7264 start - probe . lastCaptureMs < probe . msBetweenSampling ||
7365 ! checkGlobalSnapshotBudget ( start , probe . captureSnapshot )
7466 ) {
75- stack . push ( null )
67+ probe . activeEntries . push ( null )
7668 continue
7769 }
7870
@@ -89,7 +81,7 @@ export function onEntry(probes: InitializedProbe[], self: any, args: Record<stri
8981 // Check condition - if it fails, don't evaluate or capture anything
9082 if ( ! evaluateProbeCondition ( probe , context ) ) {
9183 // Still push to stack so onReturn/onThrow can pop it, but mark as skipped
92- stack . push ( null )
84+ probe . activeEntries . push ( null )
9385 continue
9486 }
9587 } catch ( error ) {
@@ -101,7 +93,7 @@ export function onEntry(probes: InitializedProbe[], self: any, args: Record<stri
10193 } )
10294 }
10395 // Still push to stack so onReturn/onThrow can pop it, but mark as skipped
104- stack . push ( null )
96+ probe . activeEntries . push ( null )
10597 continue
10698 }
10799
@@ -120,12 +112,12 @@ export function onEntry(probes: InitializedProbe[], self: any, args: Record<stri
120112 } ,
121113 }
122114 if ( captureCtx . timedOut ) {
123- stack . push ( null )
115+ probe . activeEntries . push ( null )
124116 continue
125117 }
126118 }
127119
128- stack . push ( {
120+ probe . activeEntries . push ( {
129121 start,
130122 timestamp,
131123 message,
@@ -154,23 +146,10 @@ export function onReturn(
154146) : any {
155147 const end = performance . now ( )
156148 const captureCtx : CaptureContext = { deadline : performance . now ( ) + SNAPSHOT_TIMEOUT_MS , timedOut : false }
157- let exhaustedProbeIds : string [ ] | undefined
158149
159150 // TODO: A lot of repeated work performed for each probe that could be shared between probes
160151 for ( const probe of probes ) {
161- if ( ! hasProbeLifetimeBudgetRemaining ( probe ) ) {
162- ; ( exhaustedProbeIds ??= [ ] ) . push ( probe . id )
163- continue
164- }
165-
166- const stack = active . get ( probe . id ) // TODO: Should we use the functionId instead?
167- if ( ! stack ) {
168- continue // TODO: This shouldn't be possible, do we need it? Should we warn?
169- }
170- const result = stack . pop ( )
171- if ( stack . length === 0 ) {
172- active . delete ( probe . id )
173- }
152+ const result = probe . activeEntries . pop ( )
174153 if ( ! result ) {
175154 continue
176155 }
@@ -226,12 +205,6 @@ export function onReturn(
226205 queueDebuggerSnapshot ( probe , result )
227206 }
228207
229- if ( exhaustedProbeIds ) {
230- for ( const id of exhaustedProbeIds ) {
231- removeProbe ( id )
232- }
233- }
234-
235208 return value
236209}
237210
@@ -246,23 +219,10 @@ export function onReturn(
246219export function onThrow ( probes : InitializedProbe [ ] , error : Error , self : any , args : Record < string , any > = { } ) : void {
247220 const end = performance . now ( )
248221 const captureCtx : CaptureContext = { deadline : performance . now ( ) + SNAPSHOT_TIMEOUT_MS , timedOut : false }
249- let exhaustedProbeIds : string [ ] | undefined
250222
251223 // TODO: A lot of repeated work performed for each probe that could be shared between probes
252224 for ( const probe of probes ) {
253- if ( ! hasProbeLifetimeBudgetRemaining ( probe ) ) {
254- ; ( exhaustedProbeIds ??= [ ] ) . push ( probe . id )
255- continue
256- }
257-
258- const stack = active . get ( probe . id ) // TODO: Should we use the functionId instead?
259- if ( ! stack ) {
260- continue // TODO: This shouldn't be possible, do we need it? Should we warn?
261- }
262- const result = stack . pop ( )
263- if ( stack . length === 0 ) {
264- active . delete ( probe . id )
265- }
225+ const result = probe . activeEntries . pop ( )
266226 if ( ! result ) {
267227 continue
268228 }
@@ -320,12 +280,6 @@ export function onThrow(probes: InitializedProbe[], error: Error, self: any, arg
320280
321281 queueDebuggerSnapshot ( probe , result )
322282 }
323-
324- if ( exhaustedProbeIds ) {
325- for ( const id of exhaustedProbeIds ) {
326- removeProbe ( id )
327- }
328- }
329283}
330284
331285/**
@@ -383,7 +337,7 @@ function queueDebuggerSnapshot(probe: InitializedProbe, result: ActiveEntry): vo
383337 }
384338
385339 debuggerBatch . add ( payload )
386- probe . eventsSentInLifetime ++
340+ recordProbeEventSent ( probe )
387341}
388342
389343function getDebuggerDDtags ( debuggerVersion : string ) : string {
0 commit comments