@@ -29,9 +29,9 @@ function addLog(log: Log): void {
29
29
return ;
30
30
}
31
31
32
- // if (!client.getOptions()._experiments?.logSupport) {
33
- // return;
34
- // }
32
+ if ( ! client . getOptions ( ) . _experiments ?. logSupport ) {
33
+ return ;
34
+ }
35
35
36
36
const globalScope = getGlobalScope ( ) ;
37
37
const dsn = client . getDsn ( ) ;
@@ -41,74 +41,86 @@ function addLog(log: Log): void {
41
41
trace_id : globalScope . getPropagationContext ( ) . traceId ,
42
42
public_key : dsn ?. publicKey ,
43
43
} ,
44
- ...( dsn ? { dsn : dsnToString ( dsn ) } : { } ) ,
45
- }
46
- if ( ! log . traceId ) {
44
+ ...( dsn ? { dsn : dsnToString ( dsn ) } : { } ) ,
45
+ } ;
46
+ if ( ! log . traceId ) {
47
47
log . traceId = globalScope . getPropagationContext ( ) . traceId || '00000000-0000-0000-0000-000000000000' ;
48
48
}
49
- if ( ! log . timeUnixNano ) {
50
- log . timeUnixNano = `${ ( new Date ( ) ) . getTime ( ) . toString ( ) } 000000` ;
49
+ if ( ! log . timeUnixNano ) {
50
+ log . timeUnixNano = `${ new Date ( ) . getTime ( ) . toString ( ) } 000000` ;
51
51
}
52
52
53
53
const envelope = createEnvelope < LogEnvelope > ( headers , [ createLogEnvelopeItem ( log ) ] ) ;
54
54
55
- client . sendEnvelope ( envelope ) . then ( null , ex => console . error ( ex ) ) ;
55
+ // sendEnvelope should not throw
56
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
57
+ client . sendEnvelope ( envelope ) ;
56
58
}
57
59
58
60
function valueToAttribute ( key : string , value : unknown ) : LogAttribute {
59
61
if ( typeof value === 'number' ) {
60
- if ( Number . isInteger ( value ) ) {
62
+ if ( Number . isInteger ( value ) ) {
61
63
return {
62
64
key,
63
65
value : {
64
- intValue : value
65
- }
66
- }
66
+ intValue : value ,
67
+ } ,
68
+ } ;
67
69
}
68
70
return {
69
71
key,
70
72
value : {
71
- doubleValue : value
72
- }
73
- }
73
+ doubleValue : value ,
74
+ } ,
75
+ } ;
74
76
} else if ( typeof value === 'boolean' ) {
75
77
return {
76
78
key,
77
79
value : {
78
- boolValue : value
79
- }
80
- }
80
+ boolValue : value ,
81
+ } ,
82
+ } ;
81
83
} else if ( typeof value === 'string' ) {
82
84
return {
83
85
key,
84
86
value : {
85
- stringValue : value
86
- }
87
- }
87
+ stringValue : value ,
88
+ } ,
89
+ } ;
88
90
} else {
89
91
return {
90
92
key,
91
93
value : {
92
- stringValue : JSON . stringify ( value )
93
- }
94
- }
94
+ stringValue : JSON . stringify ( value ) ,
95
+ } ,
96
+ } ;
95
97
}
96
98
}
97
99
98
100
/**
99
101
* A utility function to be able to create methods like Sentry.info`...`
100
102
*
101
103
* The first parameter is bound with, e.g., const info = captureLog.bind(null, 'info')
102
- * The other parameters are in the format to be passed a template, Sentry.info`hello ${world}`
104
+ * The other parameters are in the format to be passed a tagged template, Sentry.info`hello ${world}`
103
105
*/
104
106
export function captureLog ( level : LogSeverityLevel , messages : string [ ] | string , ...values : unknown [ ] ) : void {
105
- const message = Array . isArray ( messages ) ? messages . reduce ( ( acc , str , i ) => acc + str + ( values [ i ] ?? '' ) , '' ) : messages ;
106
-
107
+ const message = Array . isArray ( messages )
108
+ ? messages . reduce ( ( acc , str , i ) => acc + str + ( values [ i ] ?? '' ) , '' )
109
+ : messages ;
110
+ const attributes = values . map < LogAttribute > ( ( value , index ) => valueToAttribute ( `param${ index } ` , value ) ) ;
111
+ if ( Array . isArray ( messages ) ) {
112
+ attributes . push ( {
113
+ key : 'sentry.template' ,
114
+ value : {
115
+ stringValue : messages . map ( ( s , i ) => s + ( i < messages . length - 1 ? `$param${ i } ` : '' ) ) . join ( '' ) ,
116
+ } ,
117
+ } ) ;
118
+ }
107
119
addLog ( {
108
120
severityText : level ,
109
121
body : {
110
122
stringValue : message ,
111
123
} ,
112
- attributes : values . map < LogAttribute > ( ( value , index ) => valueToAttribute ( `param ${ index } ` , value ) ) ,
113
- } )
124
+ attributes : attributes ,
125
+ } ) ;
114
126
}
0 commit comments