@@ -108,7 +108,10 @@ interface StateHandlersBase<AllPossibleScopesT> {
108
108
[ handler : string ] : (
109
109
// eslint-disable-next-line @typescript-eslint/no-explicit-any
110
110
payload : any ,
111
- ) => void | undefined | Transition < AllPossibleScopesT >
111
+ ) =>
112
+ | void
113
+ | undefined
114
+ | ( Transition < AllPossibleScopesT > & { transitionFromState ?: never } )
112
115
}
113
116
114
117
type StatesBase < AllPossibleScopesT > = Record <
@@ -244,7 +247,7 @@ export class TraceStateMachine<
244
247
#provisionalBuffer: SpanAndAnnotation < AllPossibleScopesT > [ ] = [ ]
245
248
246
249
// eslint-disable-next-line consistent-return
247
- #processProvisionalBuffer( ) : OnEnterStatePayload < AllPossibleScopesT > | void {
250
+ #processProvisionalBuffer( ) : Transition < AllPossibleScopesT > | void {
248
251
// process items in the buffer (stick the scope in the entries) (if its empty, well we can skip this!)
249
252
let span : SpanAndAnnotation < AllPossibleScopesT > | undefined
250
253
// eslint-disable-next-line no-cond-assign
@@ -264,9 +267,9 @@ export class TraceStateMachine<
264
267
] ! . timeoutDuration ,
265
268
)
266
269
} ,
270
+
267
271
onActive : ( ) => ( {
268
272
transitionToState : 'active' ,
269
- transitionFromState : INITIAL_STATE ,
270
273
} ) ,
271
274
272
275
onProcessSpan : (
@@ -863,12 +866,13 @@ export class TraceStateMachine<
863
866
>
864
867
>
865
868
const transitionPayload = currentStateHandlers [ event ] ?.( payload )
869
+ console . log ( 'transitionPayload' , transitionPayload )
866
870
if ( transitionPayload ) {
867
871
const transitionFromState = this . currentState as NonTerminalTraceStates
868
872
this . currentState = transitionPayload . transitionToState
869
873
const onEnterStateEvent : OnEnterStatePayload < AllPossibleScopesT > = {
870
- transitionFromState,
871
874
...transitionPayload ,
875
+ transitionFromState,
872
876
}
873
877
return this . emit ( 'onEnterState' , onEnterStateEvent ) ?? onEnterStateEvent
874
878
}
@@ -1022,18 +1026,21 @@ export class ActiveTrace<
1022
1026
this . stateMachine . emit ( 'onInterrupt' , reason )
1023
1027
}
1024
1028
1025
- transitionDraftToActive (
1029
+ transitionDraftToActive ( {
1030
+ inputAndDefinitionModifications,
1031
+ onEnd,
1032
+ } : {
1026
1033
inputAndDefinitionModifications : TraceModifications <
1027
1034
TracerScopeKeysT ,
1028
1035
AllPossibleScopesT ,
1029
1036
OriginatedFromT
1030
- > ,
1037
+ >
1031
1038
onEnd : SingleTraceReportFn <
1032
1039
TracerScopeKeysT ,
1033
1040
AllPossibleScopesT ,
1034
1041
OriginatedFromT
1035
- > ,
1036
- ) {
1042
+ >
1043
+ } ) {
1037
1044
const { attributes } = this . draftInput
1038
1045
1039
1046
this . input = {
@@ -1198,10 +1205,11 @@ export class ActiveTrace<
1198
1205
endOfOperationSpan . span . duration ,
1199
1206
)
1200
1207
: [ ...this . recordedItems ] ,
1201
- input : this . input ,
1208
+ input : this . draftInput ,
1202
1209
} ,
1203
1210
transition ,
1204
1211
)
1212
+ // TODO: move the onEnd being ActiveTrace
1205
1213
this . input . onEnd ( traceRecording , this )
1206
1214
1207
1215
// memory clean-up in case something retains the ActiveTrace instance
@@ -1212,3 +1220,15 @@ export class ActiveTrace<
1212
1220
}
1213
1221
}
1214
1222
}
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
0 commit comments