@@ -11,7 +11,6 @@ import type {
11
11
Extra ,
12
12
Extras ,
13
13
FinishedCheckIn ,
14
- LogSeverityLevel ,
15
14
MonitorConfig ,
16
15
Primitive ,
17
16
Session ,
@@ -24,6 +23,7 @@ import { logger } from './utils-hoist/logger';
24
23
import { uuid4 } from './utils-hoist/misc' ;
25
24
import { timestampInSeconds } from './utils-hoist/time' ;
26
25
import { GLOBAL_OBJ } from './utils-hoist/worldwide' ;
26
+ import { parameterize } from './utils/parameterize' ;
27
27
import type { ExclusiveEventHintOrCaptureContext } from './utils/prepareEvent' ;
28
28
import { parseEventHintOrCaptureContext } from './utils/prepareEvent' ;
29
29
@@ -337,8 +337,6 @@ export function captureSession(end: boolean = false): void {
337
337
_sendSessionUpdate ( ) ;
338
338
}
339
339
340
- type OmitFirstArg < F > = F extends ( x : LogSeverityLevel , ...args : infer P ) => infer R ? ( ...args : P ) => R : never ;
341
-
342
340
/**
343
341
* A namespace for experimental logging functions.
344
342
*
@@ -349,55 +347,106 @@ export const _experiment_log = {
349
347
* A utility to record a log with level 'TRACE' and send it to sentry.
350
348
*
351
349
* Logs represent a message and some parameters which provide context for a trace or error.
352
- * Ex: Sentry._experiment_log.trace`user ${username} just bought ${item}!`
350
+ *
351
+ * @example
352
+ * ```js
353
+ * const { trace, fmt } = Sentry._experiment_log;
354
+ * trace(fmt`user ${username} just bought ${item}!`);
355
+ * ```
353
356
*/
354
- trace : sendLog . bind ( null , 'trace' ) as OmitFirstArg < typeof sendLog > ,
357
+ trace : sendLog ( 'trace' ) ,
355
358
/**
356
359
* A utility to record a log with level 'DEBUG' and send it to sentry.
357
360
*
358
361
* Logs represent a message and some parameters which provide context for a trace or error.
359
- * Ex: Sentry._experiment_log.debug`user ${username} just bought ${item}!`
362
+ *
363
+ * @example
364
+ * ```js
365
+ * const { debug, fmt } = Sentry._experiment_log;
366
+ * debug(fmt`user ${username} just bought ${item}!`);
367
+ * ```
360
368
*/
361
- debug : sendLog . bind ( null , 'debug' ) as OmitFirstArg < typeof sendLog > ,
369
+ debug : sendLog ( 'debug' ) ,
362
370
/**
363
371
* A utility to record a log with level 'INFO' and send it to sentry.
364
372
*
365
373
* Logs represent a message and some parameters which provide context for a trace or error.
366
- * Ex: Sentry._experiment_log.info`user ${username} just bought ${item}!`
374
+ *
375
+ * @example
376
+ * ```js
377
+ * const { info, fmt } = Sentry._experiment_log;
378
+ * info(fmt`user ${username} just bought ${item}!`);
379
+ * ```
367
380
*/
368
- info : sendLog . bind ( null , 'info' ) as OmitFirstArg < typeof sendLog > ,
381
+ info : sendLog ( 'info' ) ,
369
382
/**
370
383
* A utility to record a log with level 'INFO' and send it to sentry.
371
384
*
372
385
* Logs represent a message and some parameters which provide context for a trace or error.
373
- * Ex: Sentry._experiment_log.log`user ${username} just bought ${item}!`
386
+ *
387
+ * @example
388
+ * ```js
389
+ * const { log, fmt } = Sentry._experiment_log;
390
+ * log(fmt`user ${username} just bought ${item}!`);
391
+ * ```
374
392
*/
375
- log : sendLog . bind ( null , 'log' ) as OmitFirstArg < typeof sendLog > ,
393
+ log : sendLog ( 'info' , 10 ) ,
376
394
/**
377
395
* A utility to record a log with level 'ERROR' and send it to sentry.
378
396
*
379
397
* Logs represent a message and some parameters which provide context for a trace or error.
380
- * Ex: Sentry._experiment_log.error`user ${username} just bought ${item}!`
398
+ *
399
+ * @example
400
+ * ```js
401
+ * const { error, fmt } = Sentry._experiment_log;
402
+ * error(fmt`user ${username} just bought ${item}!`);
403
+ * ```
381
404
*/
382
- error : sendLog . bind ( null , 'error' ) as OmitFirstArg < typeof sendLog > ,
405
+ error : sendLog ( 'error' ) ,
383
406
/**
384
407
* A utility to record a log with level 'WARN' and send it to sentry.
385
408
*
386
409
* Logs represent a message and some parameters which provide context for a trace or error.
387
- * Ex: Sentry._experiment_log.warn`user ${username} just bought ${item}!`
410
+ *
411
+ * @example
412
+ * ```js
413
+ * const { warn, fmt } = Sentry._experiment_log;
414
+ * warn(fmt`user ${username} just bought ${item}!`);
415
+ * ```
388
416
*/
389
- warn : sendLog . bind ( null , 'warn' ) as OmitFirstArg < typeof sendLog > ,
417
+ warn : sendLog ( 'warn' ) ,
390
418
/**
391
419
* A utility to record a log with level 'FATAL' and send it to sentry.
392
420
*
393
421
* Logs represent a message and some parameters which provide context for a trace or error.
394
- * Ex: Sentry._experiment_log.warn`user ${username} just bought ${item}!`
422
+ *
423
+ * @example
424
+ * ```js
425
+ * const { fatal, fmt } = Sentry._experiment_log;
426
+ * fatal(fmt`user ${username} just bought ${item}!`);
427
+ * ```
395
428
*/
396
- fatal : sendLog . bind ( null , 'fatal' ) as OmitFirstArg < typeof sendLog > ,
429
+ fatal : sendLog ( 'fatal' ) ,
430
+
431
+ /**
432
+ * Tagged template function which returns parameterized representation of the message
433
+ *
434
+ * @example
435
+ * ```js
436
+ * Sentry._experiment_log.fmt`This is a log statement with ${x} and ${y} params`
437
+ * ```
438
+ */
439
+ fmt : parameterize ,
440
+
397
441
/**
398
442
* A flexible utility to record a log with a custom level and send it to sentry.
399
443
*
400
444
* You can optionally pass in custom attributes and a custom severity number to be attached to the log.
445
+ *
446
+ * @example
447
+ * ```js
448
+ * Sentry._experiment_log.emit({ level: 'info', message: Sentry._experiment_log.fmt`user ${username }just bought ${item}`, attributes: { extra: 123 } })
449
+ * ```
401
450
*/
402
- captureLog,
451
+ emit : captureLog ,
403
452
} ;
0 commit comments