MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / instrumentConsole

Function instrumentConsole

packages/core/src/instrument/console.ts:54–86  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

52}
53
54function instrumentConsole(): void {
55 if (!('console' in GLOBAL_OBJ)) {
56 return;
57 }
58
59 CONSOLE_LEVELS.forEach(function (level: ConsoleLevel): void {
60 if (!(level in GLOBAL_OBJ.console)) {
61 return;
62 }
63
64 fill(GLOBAL_OBJ.console, level, function (originalConsoleMethod: () => any): Function {
65 originalConsoleMethods[level] = originalConsoleMethod;
66
67 return function (...args: any[]): void {
68 const firstArg = args[0];
69 const log = originalConsoleMethods[level];
70
71 const isFiltered = _filter.size && typeof firstArg === 'string' && stringMatchesSomePattern(firstArg, _filter);
72
73 // Only trigger handlers for non-filtered messages
74 if (!isFiltered) {
75 triggerHandlers('console', { args, level } as HandlerDataConsole);
76 }
77
78 // Only log filtered messages in debug mode
79 if (!isFiltered || (DEBUG_BUILD && debug.isEnabled())) {
80 // Call original console method
81 log?.apply(GLOBAL_OBJ.console, args);
82 }
83 };
84 });
85 });
86}

Callers

nothing calls this directly

Calls 6

fillFunction · 0.90
stringMatchesSomePatternFunction · 0.90
triggerHandlersFunction · 0.90
forEachMethod · 0.65
isEnabledMethod · 0.65
applyMethod · 0.45

Tested by

no test coverage detected