@@ -29,9 +29,9 @@ function addLog(log: Log): void {
2929 return ;
3030 }
3131
32- // if (!client.getOptions()._experiments?.logSupport) {
33- // return;
34- // }
32+ if ( ! client . getOptions ( ) . _experiments ?. logSupport ) {
33+ return ;
34+ }
3535
3636 const globalScope = getGlobalScope ( ) ;
3737 const dsn = client . getDsn ( ) ;
@@ -99,16 +99,24 @@ function valueToAttribute(key: string, value: unknown): LogAttribute {
9999 * A utility function to be able to create methods like Sentry.info`...`
100100 *
101101 * 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}`
103103 */
104104export function captureLog ( level : LogSeverityLevel , messages : string [ ] | string , ...values : unknown [ ] ) : void {
105105 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+ }
107115 addLog ( {
108116 severityText : level ,
109117 body : {
110118 stringValue : message ,
111119 } ,
112- attributes : values . map < LogAttribute > ( ( value , index ) => valueToAttribute ( `param ${ index } ` , value ) ) ,
120+ attributes : attributes ,
113121 } )
114122}
0 commit comments