Skip to content

fix(core): Improve safeJoin usage in console logging integration #16658

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

Merged
merged 1 commit into from
Jun 20, 2025

Conversation

AbhiPrasad
Copy link
Member

@AbhiPrasad AbhiPrasad commented Jun 19, 2025

resolves #16657

Background

In the consoleLoggingIntegration (which sends logs to Sentry from console calls), we use a utility called safeJoin to join together the console args.

export function safeJoin(input: unknown[], delimiter?: string): string {
if (!Array.isArray(input)) {
return '';
}
const output = [];
// eslint-disable-next-line @typescript-eslint/prefer-for-of
for (let i = 0; i < input.length; i++) {
const value = input[i];
try {
// This is a hack to fix a Vue3-specific bug that causes an infinite loop of
// console warnings. This happens when a Vue template is rendered with
// an undeclared variable, which we try to stringify, ultimately causing
// Vue to issue another warning which repeats indefinitely.
// see: https://github.com/getsentry/sentry-javascript/pull/8981
if (isVueViewModel(value)) {
output.push('[VueViewModel]');
} else {
output.push(String(value));
}
} catch (e) {
output.push('[value cannot be serialized]');
}
}
return output.join(delimiter);
}

This utility calls String(value) to convert items to a string, which results in objects and arrays being turned into the dreaded [Object Object] or [Array].

output.push(String(value));

A user wrote in with feedback that this was annoying, and I agree!

Solution

Instead of using String(value) I chose to create a new helper that uses JSON.stringify(normalize(X)), which should result in the entire object or array being properly shown. This required me to grab normalizeDepth and normalizeMaxBreadth from the client options, but that feels fine because it's easily explainable to users.

I added tests to validate this.

Next Steps

We should really refactor our overall safeJoin usage. This should be safe in breadcrumbs, but will be a breaking change in capture-console as it'll cause issue grouping changes if console calls are being captured as messages/errors.

@AbhiPrasad AbhiPrasad self-assigned this Jun 19, 2025
@AbhiPrasad AbhiPrasad requested review from a team, Lms24 and RulaKhaled and removed request for a team June 19, 2025 19:15
Copy link
Member

@RulaKhaled RulaKhaled left a comment

Choose a reason for hiding this comment

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

nice

@AbhiPrasad AbhiPrasad merged commit c5613eb into develop Jun 20, 2025
168 checks passed
@AbhiPrasad AbhiPrasad deleted the abhi-better-console-safe-join branch June 20, 2025 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Console Logging Integration creates [Object Object] or [Array]
3 participants