@@ -6,32 +6,45 @@ import type { TransportItem, Transports } from '../../transports';
6
6
import type { UnpatchedConsole } from '../../unpatchedConsole' ;
7
7
import { deepEqual , getCurrentTimestamp , isEmpty , isNull , stringifyObjectValues } from '../../utils' ;
8
8
import { timestampToIsoString } from '../../utils/date' ;
9
+ import { USER_ACTION_START_MESSAGE_TYPE } from '../const' ;
10
+ import type { ItemBuffer } from '../ItemBuffer' ;
9
11
import type { TracesAPI } from '../traces' ;
12
+ import type { ApiMessageBusMessages } from '../types' ;
10
13
11
14
import type { EventEvent , EventsAPI } from './types' ;
12
15
13
- export function initializeEventsAPI (
14
- _unpatchedConsole : UnpatchedConsole ,
15
- internalLogger : InternalLogger ,
16
- config : Config ,
17
- metas : Metas ,
18
- transports : Transports ,
19
- tracesApi : TracesAPI
20
- ) : EventsAPI {
16
+ export function initializeEventsAPI ( {
17
+ internalLogger,
18
+ config,
19
+ metas,
20
+ transports,
21
+ tracesApi,
22
+ actionBuffer,
23
+ getMessage,
24
+ } : {
25
+ unpatchedConsole : UnpatchedConsole ;
26
+ internalLogger : InternalLogger ;
27
+ config : Config ;
28
+ metas : Metas ;
29
+ transports : Transports ;
30
+ tracesApi : TracesAPI ;
31
+ actionBuffer : ItemBuffer < TransportItem > ;
32
+ getMessage : ( ) => ApiMessageBusMessages | undefined ;
33
+ } ) : EventsAPI {
21
34
let lastPayload : Pick < EventEvent , 'name' | 'domain' | 'attributes' > | null = null ;
22
35
23
36
const pushEvent : EventsAPI [ 'pushEvent' ] = (
24
37
name ,
25
38
attributes ,
26
39
domain ,
27
- { skipDedupe, spanContext, timestampOverwriteMs } = { }
40
+ { skipDedupe, spanContext, timestampOverwriteMs, customPayloadTransformer = ( payload : EventEvent ) => payload } = { }
28
41
) => {
29
42
try {
30
43
const attrs = stringifyObjectValues ( attributes ) ;
31
44
32
45
const item : TransportItem < EventEvent > = {
33
46
meta : metas . value ,
34
- payload : {
47
+ payload : customPayloadTransformer ( {
35
48
name,
36
49
domain : domain ?? config . eventDomain ,
37
50
attributes : isEmpty ( attrs ) ? undefined : attrs ,
@@ -42,7 +55,7 @@ export function initializeEventsAPI(
42
55
span_id : spanContext . spanId ,
43
56
}
44
57
: tracesApi . getTraceContext ( ) ,
45
- } ,
58
+ } ) ,
46
59
type : TransportItemType . EVENT ,
47
60
} ;
48
61
@@ -62,7 +75,12 @@ export function initializeEventsAPI(
62
75
63
76
internalLogger . debug ( 'Pushing event\n' , item ) ;
64
77
65
- transports . execute ( item ) ;
78
+ const msg = getMessage ( ) ;
79
+ if ( msg && msg . type === USER_ACTION_START_MESSAGE_TYPE ) {
80
+ actionBuffer . addItem ( item ) ;
81
+ } else {
82
+ transports . execute ( item ) ;
83
+ }
66
84
} catch ( err ) {
67
85
internalLogger . error ( 'Error pushing event' , err ) ;
68
86
}
0 commit comments