@@ -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 ( ) ; 
@@ -41,74 +41,86 @@ function addLog(log: Log): void {
4141      trace_id : globalScope . getPropagationContext ( ) . traceId , 
4242      public_key : dsn ?. publicKey , 
4343    } , 
44-     ...( dsn  ? { dsn : dsnToString ( dsn ) }  : { } ) , 
45-   } 
46-   if ( ! log . traceId )  { 
44+     ...( dsn  ? {   dsn : dsnToString ( dsn )   }  : { } ) , 
45+   } ; 
46+   if   ( ! log . traceId )  { 
4747    log . traceId  =  globalScope . getPropagationContext ( ) . traceId  ||  '00000000-0000-0000-0000-000000000000' ; 
4848  } 
49-   if ( ! log . timeUnixNano )  { 
50-     log . timeUnixNano  =  `${ ( new  Date ( ) ) . getTime ( ) . toString ( ) }  000000` ; 
49+   if   ( ! log . timeUnixNano )  { 
50+     log . timeUnixNano  =  `${ new  Date ( ) . getTime ( ) . toString ( ) }  000000` ; 
5151  } 
5252
5353  const  envelope  =  createEnvelope < LogEnvelope > ( headers ,  [ createLogEnvelopeItem ( log ) ] ) ; 
5454
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 ) ; 
5658} 
5759
5860function  valueToAttribute ( key : string ,  value : unknown ) : LogAttribute  { 
5961  if  ( typeof  value  ===  'number' )  { 
60-     if ( Number . isInteger ( value ) )  { 
62+     if   ( Number . isInteger ( value ) )  { 
6163      return  { 
6264        key, 
6365        value : { 
64-           intValue : value 
65-         } 
66-       } 
66+           intValue : value , 
67+         } , 
68+       } ; 
6769    } 
6870    return  { 
6971      key, 
7072      value : { 
71-         doubleValue : value 
72-       } 
73-     } 
73+         doubleValue : value , 
74+       } , 
75+     } ; 
7476  }  else  if  ( typeof  value  ===  'boolean' )  { 
7577    return  { 
7678      key, 
7779      value : { 
78-         boolValue : value 
79-       } 
80-     } 
80+         boolValue : value , 
81+       } , 
82+     } ; 
8183  }  else  if  ( typeof  value  ===  'string' )  { 
8284    return  { 
8385      key, 
8486      value : { 
85-         stringValue : value 
86-       } 
87-     } 
87+         stringValue : value , 
88+       } , 
89+     } ; 
8890  }  else  { 
8991    return  { 
9092      key, 
9193      value : { 
92-         stringValue : JSON . stringify ( value ) 
93-       } 
94-     } 
94+         stringValue : JSON . stringify ( value ) , 
95+       } , 
96+     } ; 
9597  } 
9698} 
9799
98100/** 
99101 * A utility function to be able to create methods like Sentry.info`...` 
100102 * 
101103 * 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}` 
103105 */ 
104106export  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+   } 
107119  addLog ( { 
108120    severityText : level , 
109121    body : { 
110122      stringValue : message , 
111123    } , 
112-     attributes : values . map < LogAttribute > ( ( value ,   index )   =>   valueToAttribute ( `param ${ index } ` ,   value ) ) , 
113-   } ) 
124+     attributes : attributes , 
125+   } ) ; 
114126} 
0 commit comments