Skip to content

Commit ef0e9f1

Browse files
committed
fix(core): Revert sendSession consolidation and URLSearchParams changes
Revert two optimizations that caused CI failures: - sendSession consolidation (client.ts): The eager `session.attrs = session.attrs || {}` added an empty `attrs` property to session aggregates, breaking node-core httpServerIntegration tests that assert on the exact shape. - getReportDialogEndpoint URLSearchParams (api.ts): URLSearchParams percent-encodes the DSN value (`://` → `%3A%2F%2F`), changing output format vs the original raw string concatenation approach. Core API tests compare exact URL strings. Both changes were functionally equivalent at runtime but broke snapshot-style test assertions in other packages. Co-Authored-By: Claude claude@anthropic.com
1 parent 9065e37 commit ef0e9f1

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

packages/core/src/api.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,32 @@ export function getReportDialogEndpoint(dsnLike: DsnLike, dialogOptions: ReportD
5353
}
5454

5555
const endpoint = `${getBaseApiEndpoint(dsn)}embed/error-page/`;
56-
const params = new URLSearchParams({ dsn: dsnToString(dsn) });
5756

57+
let encodedOptions = `dsn=${dsnToString(dsn)}`;
5858
for (const key in dialogOptions) {
59-
if (key === 'dsn' || key === 'onClose') {
59+
if (key === 'dsn') {
60+
continue;
61+
}
62+
63+
if (key === 'onClose') {
6064
continue;
6165
}
6266

6367
if (key === 'user') {
6468
const user = dialogOptions.user;
65-
if (user?.name) {
66-
params.set('name', user.name);
69+
if (!user) {
70+
continue;
71+
}
72+
if (user.name) {
73+
encodedOptions += `&name=${encodeURIComponent(user.name)}`;
6774
}
68-
if (user?.email) {
69-
params.set('email', user.email);
75+
if (user.email) {
76+
encodedOptions += `&email=${encodeURIComponent(user.email)}`;
7077
}
7178
} else {
72-
params.set(key, dialogOptions[key] as string);
79+
encodedOptions += `&${encodeURIComponent(key)}=${encodeURIComponent(dialogOptions[key] as string)}`;
7380
}
7481
}
7582

76-
return `${endpoint}?${params.toString()}`;
83+
return `${endpoint}?${encodedOptions}`;
7784
}

packages/core/src/client.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -534,16 +534,24 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
534534
public sendSession(session: Session | SessionAggregates): void {
535535
// Backfill release and environment on session
536536
const { release: clientReleaseOption, environment: clientEnvironmentOption = DEFAULT_ENVIRONMENT } = this._options;
537-
const target = 'aggregates' in session ? (session.attrs = session.attrs || {}) : session;
538-
539-
if (!target.release && !clientReleaseOption) {
540-
DEBUG_BUILD && debug.warn(MISSING_RELEASE_FOR_SESSION_ERROR);
541-
return;
537+
if ('aggregates' in session) {
538+
const sessionAttrs = session.attrs || {};
539+
if (!sessionAttrs.release && !clientReleaseOption) {
540+
DEBUG_BUILD && debug.warn(MISSING_RELEASE_FOR_SESSION_ERROR);
541+
return;
542+
}
543+
sessionAttrs.release = sessionAttrs.release || clientReleaseOption;
544+
sessionAttrs.environment = sessionAttrs.environment || clientEnvironmentOption;
545+
session.attrs = sessionAttrs;
546+
} else {
547+
if (!session.release && !clientReleaseOption) {
548+
DEBUG_BUILD && debug.warn(MISSING_RELEASE_FOR_SESSION_ERROR);
549+
return;
550+
}
551+
session.release = session.release || clientReleaseOption;
552+
session.environment = session.environment || clientEnvironmentOption;
542553
}
543554

544-
target.release = target.release || clientReleaseOption;
545-
target.environment = target.environment || clientEnvironmentOption;
546-
547555
this.emit('beforeSendSession', session);
548556

549557
const env = createSessionEnvelope(session, this._dsn, this._options._metadata, this._options.tunnel);

0 commit comments

Comments
 (0)