@@ -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 ( ) ;
@@ -99,16 +99,24 @@ function valueToAttribute(key: string, value: unknown): LogAttribute {
99
99
* A utility function to be able to create methods like Sentry.info`...`
100
100
*
101
101
* 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}`
102
+ * The other parameters are in the format to be passed a tagged template, Sentry.info`hello ${world}`
103
103
*/
104
104
export function captureLog ( level : LogSeverityLevel , messages : string [ ] | string , ...values : unknown [ ] ) : void {
105
105
const message = Array . isArray ( messages ) ? messages . reduce ( ( acc , str , i ) => acc + str + ( values [ i ] ?? '' ) , '' ) : messages ;
106
-
106
+ const attributes = values . map < LogAttribute > ( ( value , index ) => valueToAttribute ( `param${ index } ` , value ) ) ;
107
+ if ( Array . isArray ( messages ) ) {
108
+ attributes . push ( {
109
+ key : 'sentry.template' ,
110
+ value : {
111
+ stringValue : messages . map ( ( s , i ) => s + ( i < messages . length - 1 ? `$param${ i } ` : '' ) ) . join ( '' )
112
+ }
113
+ } )
114
+ }
107
115
addLog ( {
108
116
severityText : level ,
109
117
body : {
110
118
stringValue : message ,
111
119
} ,
112
- attributes : values . map < LogAttribute > ( ( value , index ) => valueToAttribute ( `param ${ index } ` , value ) ) ,
120
+ attributes : attributes ,
113
121
} )
114
122
}
0 commit comments