@@ -5,8 +5,9 @@ import { defineIntegration } from '../integration';
55import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '../semanticAttributes' ;
66import type { ConsoleLevel } from '../types-hoist/instrument' ;
77import type { IntegrationFn } from '../types-hoist/integration' ;
8+ import { isPrimitive } from '../utils/is' ;
89import { CONSOLE_LEVELS , logger } from '../utils/logger' ;
9- import { safeJoin } from '../utils/string ' ;
10+ import { normalize } from '../utils/normalize ' ;
1011import { GLOBAL_OBJ } from '../utils/worldwide' ;
1112import { _INTERNAL_captureLog } from './exports' ;
1213
@@ -32,7 +33,8 @@ const _consoleLoggingIntegration = ((options: Partial<CaptureConsoleOptions> = {
3233 return {
3334 name : INTEGRATION_NAME ,
3435 setup ( client ) {
35- if ( ! client . getOptions ( ) . _experiments ?. enableLogs ) {
36+ const { _experiments, normalizeDepth = 3 , normalizeMaxBreadth = 1_000 } = client . getOptions ( ) ;
37+ if ( ! _experiments ?. enableLogs ) {
3638 DEBUG_BUILD && logger . warn ( '`_experiments.enableLogs` is not enabled, ConsoleLogs integration disabled' ) ;
3739 return ;
3840 }
@@ -45,17 +47,19 @@ const _consoleLoggingIntegration = ((options: Partial<CaptureConsoleOptions> = {
4547 if ( level === 'assert' ) {
4648 if ( ! args [ 0 ] ) {
4749 const followingArgs = args . slice ( 1 ) ;
48- const message =
49- followingArgs . length > 0 ? `Assertion failed: ${ formatConsoleArgs ( followingArgs ) } ` : 'Assertion failed' ;
50- _INTERNAL_captureLog ( { level : 'error' , message, attributes : DEFAULT_ATTRIBUTES } ) ;
50+ const assertionMessage =
51+ followingArgs . length > 0
52+ ? `Assertion failed: ${ formatConsoleArgs ( followingArgs , normalizeDepth , normalizeMaxBreadth ) } `
53+ : 'Assertion failed' ;
54+ _INTERNAL_captureLog ( { level : 'error' , message : assertionMessage , attributes : DEFAULT_ATTRIBUTES } ) ;
5155 }
5256 return ;
5357 }
5458
5559 const isLevelLog = level === 'log' ;
5660 _INTERNAL_captureLog ( {
5761 level : isLevelLog ? 'info' : level ,
58- message : formatConsoleArgs ( args ) ,
62+ message : formatConsoleArgs ( args , normalizeDepth , normalizeMaxBreadth ) ,
5963 severityNumber : isLevelLog ? 10 : undefined ,
6064 attributes : DEFAULT_ATTRIBUTES ,
6165 } ) ;
@@ -85,8 +89,16 @@ const _consoleLoggingIntegration = ((options: Partial<CaptureConsoleOptions> = {
8589 */
8690export const consoleLoggingIntegration = defineIntegration ( _consoleLoggingIntegration ) ;
8791
88- function formatConsoleArgs ( values : unknown [ ] ) : string {
92+ function formatConsoleArgs ( values : unknown [ ] , normalizeDepth : number , normalizeMaxBreadth : number ) : string {
8993 return 'util' in GLOBAL_OBJ && typeof ( GLOBAL_OBJ as GlobalObjectWithUtil ) . util . format === 'function'
9094 ? ( GLOBAL_OBJ as GlobalObjectWithUtil ) . util . format ( ...values )
91- : safeJoin ( values , ' ' ) ;
95+ : safeJoinConsoleArgs ( values , normalizeDepth , normalizeMaxBreadth ) ;
96+ }
97+
98+ function safeJoinConsoleArgs ( values : unknown [ ] , normalizeDepth : number , normalizeMaxBreadth : number ) : string {
99+ return values
100+ . map ( value =>
101+ isPrimitive ( value ) ? String ( value ) : JSON . stringify ( normalize ( value , normalizeDepth , normalizeMaxBreadth ) ) ,
102+ )
103+ . join ( ' ' ) ;
92104}
0 commit comments