Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(node): Truncate breadcrumb messages created by console integration #14006

Merged
merged 3 commits into from
Oct 18, 2024
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
@@ -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,
@@ -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
Member 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],