@@ -6,27 +6,15 @@ import { playtypusUserIdStorage } from '../middlewares';
6
6
function addMessageToTraceSpan (
7
7
method : 'log' | 'error' | 'warn' ,
8
8
message : string ,
9
- args : unknown [ ] = [ ] ,
9
+ args ? : unknown [ ] ,
10
10
) {
11
11
const span = trace . getSpan ( context . active ( ) ) ;
12
- if ( ! span ) {
13
- return ;
12
+ if ( span ) {
13
+ span . addEvent ( method , {
14
+ message,
15
+ args : args ? args . map ( ( arg ) => JSON . stringify ( arg ) ) . join ( ',' ) : '' ,
16
+ } ) ;
14
17
}
15
-
16
- const data = args ;
17
- const userId = playtypusUserIdStorage . getStore ( ) ;
18
-
19
- if ( userId ) {
20
- data . push ( { platypusUserId : userId } ) ;
21
- }
22
-
23
- span . addEvent ( method , {
24
- message,
25
- args :
26
- data ?. length !== 0
27
- ? data . map ( ( arg ) => JSON . stringify ( arg ) ) . join ( ',' )
28
- : '' ,
29
- } ) ;
30
18
}
31
19
32
20
/**
@@ -89,14 +77,7 @@ const logger = (
89
77
apiKey : string | undefined ,
90
78
...args : unknown [ ]
91
79
) : void => {
92
- // eslint-disable-next-line no-console
93
- const anonymizedApiKey = apiKey ? anonymizeKey ( apiKey ) : undefined ;
94
-
95
- const formatedMessage = constructLogMessage (
96
- anonymizedApiKey ? `[${ anonymizedApiKey } ]` : undefined ,
97
- `[${ source } ]` ,
98
- message ,
99
- ) ;
80
+ const formatedMessage = constructLogMessage ( `[${ source } ]` , message ) ;
100
81
101
82
if ( process . env . NODE_ENV === 'development' ) {
102
83
logFn ( formatedMessage , ...args ) ;
@@ -110,6 +91,12 @@ const logger = (
110
91
data . platypusUserId = userId ;
111
92
}
112
93
94
+ const anonymizedApiKey = apiKey ? anonymizeKey ( apiKey ) : undefined ;
95
+
96
+ if ( anonymizedApiKey ) {
97
+ data . apiKey = anonymizedApiKey ;
98
+ }
99
+
113
100
logFn (
114
101
JSON . stringify ( {
115
102
message : formatedMessage ,
0 commit comments