Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/node/src/integrations/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { addConsoleInstrumentationHandler, severityLevelFromString } from '@sent

const INTEGRATION_NAME = 'Console';

const TRUNCATION_MSG = ' (breadcrumb truncated)';
const MAX_BREADCRUMB_MSG_LENGTH = 2048; // 2 KB

const _consoleIntegration = (() => {
return {
name: INTEGRATION_NAME,
Expand All @@ -14,11 +17,17 @@ const _consoleIntegration = (() => {
return;
}

// Truncate the breadcrumb length to max 2KB including the truncated snippet
let formattedMessage: string = util.format.apply(undefined, args);
if (formattedMessage.length > MAX_BREADCRUMB_MSG_LENGTH) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: Why not just use truncate from @sentry/utils? :)

Copy link
Contributor Author

@lforst lforst Oct 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not know that existed 🧠 nice

formattedMessage = formattedMessage.slice(MAX_BREADCRUMB_MSG_LENGTH - TRUNCATION_MSG.length) + TRUNCATION_MSG;
}

addBreadcrumb(
{
category: 'console',
level: severityLevelFromString(level),
message: util.format.apply(undefined, args),
message: formattedMessage,
},
{
input: [...args],
Expand Down
Loading