1
- import { anonymizeKey } from './anonymize-key' ;
2
1
import { context , trace } from '@opentelemetry/api' ;
3
2
3
+ import { anonymizeKey } from './anonymize-key' ;
4
+ import { integrationIdStorage } from '../middlewares' ;
5
+
4
6
function addMessageToTraceSpan (
5
7
method : 'log' | 'error' | 'warn' ,
6
8
message : string ,
@@ -20,75 +22,75 @@ function addMessageToTraceSpan(
20
22
* @param source the context where the log originated from (usually the function name)
21
23
* @param message the message of the log
22
24
* @param apiKey the refreshToken
23
- * @param integrationUserId platypus user id
24
25
* @param args additional data, will be stringified and appended
25
26
*/
26
27
export const infoLogger = (
27
28
source : string ,
28
29
message : string ,
29
30
apiKey ?: string ,
30
- integrationUserId ?: string ,
31
31
...args : unknown [ ]
32
32
) : void => {
33
- addMessageToTraceSpan ( 'log' , message , [ ... args , integrationUserId ] ) ;
33
+ const userId = integrationIdStorage . getStore ( ) ;
34
34
35
- logger ( console . info , source , message , apiKey , integrationUserId , ...args ) ;
35
+ addMessageToTraceSpan ( 'log' , message , [ ...args , userId ] ) ;
36
+
37
+ logger ( console . info , source , message , apiKey , ...args ) ;
36
38
} ;
37
39
38
40
/**
39
41
* Logging function equivalent to console.error
40
42
* @param source the context where the log originated from (usually the function name)
41
43
* @param message the message of the log
42
44
* @param apiKey the refreshToken
43
- * @param integrationUserId platypus user id
44
45
* @param args additional data, will be stringified and appended
45
46
*/
46
47
export const errorLogger = (
47
48
source : string ,
48
49
message : string ,
49
50
apiKey ?: string ,
50
- integrationUserId ?: string ,
51
51
...args : unknown [ ]
52
52
) : void => {
53
- addMessageToTraceSpan ( 'error' , message , [ ...args , integrationUserId ] ) ;
53
+ const userId = integrationIdStorage . getStore ( ) ;
54
+
55
+ addMessageToTraceSpan ( 'error' , message , [ ...args , userId ] ) ;
54
56
55
- logger ( console . error , source , message , apiKey , integrationUserId , ...args ) ;
57
+ logger ( console . error , source , message , apiKey , ...args ) ;
56
58
} ;
57
59
58
60
/**
59
61
* Logging function equivalent to console.warn
60
62
* @param source the context where the log originated from (usually the function name)
61
63
* @param message the message of the log
62
64
* @param apiKey the refreshToken
63
- * @param integrationUserId platypus user id
64
65
* @param args additional data, will be stringified and appended
65
66
*/
66
67
export const warnLogger = (
67
68
source : string ,
68
69
message : string ,
69
70
apiKey ?: string ,
70
- integrationUserId ?: string ,
71
71
...args : unknown [ ]
72
72
) : void => {
73
- addMessageToTraceSpan ( 'warn' , message , [ ...args , integrationUserId ] ) ;
73
+ const userId = integrationIdStorage . getStore ( ) ;
74
+
75
+ addMessageToTraceSpan ( 'warn' , message , [ ...args , userId ] ) ;
74
76
75
- logger ( console . warn , source , message , apiKey , integrationUserId , ...args ) ;
77
+ logger ( console . warn , source , message , apiKey , ...args ) ;
76
78
} ;
77
79
78
80
const logger = (
79
81
logFn : ( message ?: any , ...optionalParams : any [ ] ) => void ,
80
82
source : string ,
81
83
message : string ,
82
84
apiKey : string | undefined ,
83
- integrationUserId : string | undefined ,
84
85
...args : unknown [ ]
85
86
) : void => {
86
87
// eslint-disable-next-line no-console
87
88
const anonymizedApiKey = apiKey ? anonymizeKey ( apiKey ) : undefined ;
89
+ const userId = integrationIdStorage . getStore ( ) ;
88
90
89
91
const formatedMessage = constructLogMessage (
90
92
anonymizedApiKey ? `[${ anonymizedApiKey } ]` : undefined ,
91
- integrationUserId ? `[${ integrationUserId } ]` : undefined ,
93
+ userId ? `[${ userId } ]` : undefined ,
92
94
`[${ source } ]` ,
93
95
message ,
94
96
) ;
@@ -99,7 +101,7 @@ const logger = (
99
101
logFn (
100
102
JSON . stringify ( {
101
103
message : formatedMessage ,
102
- data : { ...args , integrationUserId } ,
104
+ data : { ...args , integrationUserId : userId } ,
103
105
} ) ,
104
106
) ;
105
107
}
0 commit comments