Skip to content

Commit 6436bcd

Browse files
committed
fix: commit to keep current process, update types, create Tracer
1 parent 07a4c93 commit 6436bcd

9 files changed

+352
-280
lines changed

src/v3/ActiveTrace.ts

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ interface StateHandlersBase<AllPossibleScopesT> {
108108
[handler: string]: (
109109
// eslint-disable-next-line @typescript-eslint/no-explicit-any
110110
payload: any,
111-
) => void | undefined | Transition<AllPossibleScopesT>
111+
) =>
112+
| void
113+
| undefined
114+
| (Transition<AllPossibleScopesT> & { transitionFromState?: never })
112115
}
113116

114117
type StatesBase<AllPossibleScopesT> = Record<
@@ -244,7 +247,7 @@ export class TraceStateMachine<
244247
#provisionalBuffer: SpanAndAnnotation<AllPossibleScopesT>[] = []
245248

246249
// eslint-disable-next-line consistent-return
247-
#processProvisionalBuffer(): OnEnterStatePayload<AllPossibleScopesT> | void {
250+
#processProvisionalBuffer(): Transition<AllPossibleScopesT> | void {
248251
// process items in the buffer (stick the scope in the entries) (if its empty, well we can skip this!)
249252
let span: SpanAndAnnotation<AllPossibleScopesT> | undefined
250253
// eslint-disable-next-line no-cond-assign
@@ -264,9 +267,9 @@ export class TraceStateMachine<
264267
]!.timeoutDuration,
265268
)
266269
},
270+
267271
onActive: () => ({
268272
transitionToState: 'active',
269-
transitionFromState: INITIAL_STATE,
270273
}),
271274

272275
onProcessSpan: (
@@ -863,12 +866,13 @@ export class TraceStateMachine<
863866
>
864867
>
865868
const transitionPayload = currentStateHandlers[event]?.(payload)
869+
console.log('transitionPayload', transitionPayload)
866870
if (transitionPayload) {
867871
const transitionFromState = this.currentState as NonTerminalTraceStates
868872
this.currentState = transitionPayload.transitionToState
869873
const onEnterStateEvent: OnEnterStatePayload<AllPossibleScopesT> = {
870-
transitionFromState,
871874
...transitionPayload,
875+
transitionFromState,
872876
}
873877
return this.emit('onEnterState', onEnterStateEvent) ?? onEnterStateEvent
874878
}
@@ -1022,18 +1026,21 @@ export class ActiveTrace<
10221026
this.stateMachine.emit('onInterrupt', reason)
10231027
}
10241028

1025-
transitionDraftToActive(
1029+
transitionDraftToActive({
1030+
inputAndDefinitionModifications,
1031+
onEnd,
1032+
}: {
10261033
inputAndDefinitionModifications: TraceModifications<
10271034
TracerScopeKeysT,
10281035
AllPossibleScopesT,
10291036
OriginatedFromT
1030-
>,
1037+
>
10311038
onEnd: SingleTraceReportFn<
10321039
TracerScopeKeysT,
10331040
AllPossibleScopesT,
10341041
OriginatedFromT
1035-
>,
1036-
) {
1042+
>
1043+
}) {
10371044
const { attributes } = this.draftInput
10381045

10391046
this.input = {
@@ -1198,10 +1205,11 @@ export class ActiveTrace<
11981205
endOfOperationSpan.span.duration,
11991206
)
12001207
: [...this.recordedItems],
1201-
input: this.input,
1208+
input: this.draftInput,
12021209
},
12031210
transition,
12041211
)
1212+
// TODO: move the onEnd being ActiveTrace
12051213
this.input.onEnd(traceRecording, this)
12061214

12071215
// memory clean-up in case something retains the ActiveTrace instance
@@ -1212,3 +1220,15 @@ export class ActiveTrace<
12121220
}
12131221
}
12141222
}
1223+
1224+
export type AllPossibleActiveTraces<
1225+
ForEachPossibleScopeT,
1226+
AllPossibleScopesT = ForEachPossibleScopeT,
1227+
> = ForEachPossibleScopeT extends ForEachPossibleScopeT
1228+
? ActiveTrace<
1229+
KeysOfUnion<ForEachPossibleScopeT> & KeysOfUnion<AllPossibleScopesT>,
1230+
AllPossibleScopesT,
1231+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1232+
any
1233+
>
1234+
: never

src/v3/convertToRum.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ export interface SpanSummaryAttributes {
2525

2626
export interface RumTraceRecording<TracerScopeT>
2727
extends TraceRecordingBase<TracerScopeT> {
28-
scope: TracerScopeT
29-
3028
// spans that don't exist as separate spans in the DB
3129
// useful for things like renders, which can repeat tens of times
3230
// during the same operation

src/v3/recordingComputeUtils.ts

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable no-continue */
22
import type { FinalState } from './ActiveTrace'
33
import type { SpanAndAnnotation } from './spanAnnotationTypes'
4-
import type { ActiveTraceInput } from './spanTypes'
4+
import type { ActiveTraceInput, DraftTraceInput } from './spanTypes'
55
import type { TraceRecording } from './traceRecordingTypes'
66
import type {
77
PossibleScopeObject,
@@ -303,6 +303,27 @@ function getComputedRenderBeaconSpans<
303303
return computedRenderBeaconSpans
304304
}
305305

306+
function isActiveTraceInput<
307+
TracerScopeKeysT extends KeysOfUnion<AllPossibleScopesT>,
308+
AllPossibleScopesT,
309+
const OriginatedFromT extends string,
310+
>(
311+
input:
312+
| DraftTraceInput<
313+
SelectScopeByKey<TracerScopeKeysT, AllPossibleScopesT>,
314+
OriginatedFromT
315+
>
316+
| ActiveTraceInput<
317+
SelectScopeByKey<TracerScopeKeysT, AllPossibleScopesT>,
318+
OriginatedFromT
319+
>,
320+
): input is ActiveTraceInput<
321+
SelectScopeByKey<TracerScopeKeysT, AllPossibleScopesT>,
322+
OriginatedFromT
323+
> {
324+
return Boolean(input.scope)
325+
}
326+
306327
export function createTraceRecording<
307328
TracerScopeKeysT extends KeysOfUnion<AllPossibleScopesT>,
308329
AllPossibleScopesT,
@@ -329,9 +350,10 @@ export function createTraceRecording<
329350
interruptionReason && transitionFromState !== 'waiting-for-interactive'
330351
const computedSpans = !wasInterrupted ? getComputedSpans(data) : {}
331352
const computedValues = !wasInterrupted ? getComputedValues(data) : {}
332-
const computedRenderBeaconSpans = !wasInterrupted
333-
? getComputedRenderBeaconSpans(recordedItems, input)
334-
: {}
353+
const computedRenderBeaconSpans =
354+
!wasInterrupted && isActiveTraceInput(input)
355+
? getComputedRenderBeaconSpans(recordedItems, input)
356+
: {}
335357

336358
const anyNonSuppressedErrors = recordedItems.some(
337359
(spanAndAnnotation) =>

0 commit comments

Comments
 (0)