Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion packages/core/src/integrations/reportSdkConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { Integration, IntegrationFn } from '../types/integration';
import { debug } from '../utils/debug-logger';
import { fnv1a32 } from '../utils/hash';
import { isPlainObject } from '../utils/is';
import { isBrowser } from '../utils/isBrowser';
import { safeUnref } from '../utils/timer';

const _experimentalReportSdkConfigIntegration = (() => ({
Expand Down Expand Up @@ -106,7 +107,8 @@ function buildConfigAttributes(client: Client): Record<string, string> {
} = client.getSdkMetadata() || {};
const clientOptions = client.getOptions();
const { environment } = clientOptions;
const runtime = 'runtime' in clientOptions ? clientOptions.runtime : undefined;
// Server clients set their runtime as an option; browser clients have none.
const runtime = 'runtime' in clientOptions ? clientOptions.runtime : isBrowser() ? { name: 'browser' } : undefined;

// Only what the user passed, so SDK defaults never show up as config.
const options: Record<string, unknown> = Object.fromEntries(
Expand Down
51 changes: 48 additions & 3 deletions packages/core/test/lib/integrations/reportSdkConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { Integration } from '../../../src/types/integration';
import { experimentalReportSdkConfigIntegration } from '../../../src/integrations/reportSdkConfig';
import type * as metricsApi from '../../../src/metrics/public-api';
import { count } from '../../../src/metrics/public-api';
import { isBrowser } from '../../../src/utils/isBrowser';
import { captureOptionsSetByUser } from '../../../src/utils/sdkMetadata';
import { getDefaultTestClientOptions, TestClient } from '../../mocks/client';

Expand All @@ -13,20 +14,26 @@ vi.mock('../../../src/metrics/public-api', async importOriginal => ({
count: vi.fn(),
}));

vi.mock('../../../src/utils/isBrowser', () => ({ isBrowser: vi.fn(() => false) }));

const tagIntegration = defineIntegration((_options: { tag?: string; filter?: RegExp } = {}) => ({ name: 'Tag' }));

function reportConfig(options: ReturnType<typeof getDefaultTestClientOptions>): Record<string, unknown> {
let payload: Record<string, unknown> = {};
return JSON.parse(reportAttributes(options)['sentry.sdk_config.payload'] as string);
}

function reportAttributes(options: ReturnType<typeof getDefaultTestClientOptions>): Record<string, unknown> {
let attributes: Record<string, unknown> = {};
vi.mocked(count).mockImplementation((_name, _value, metricOptions) => {
payload = JSON.parse(String(metricOptions?.attributes?.['sentry.sdk_config.payload']));
attributes = metricOptions?.attributes ?? {};
});

const client = new TestClient(options);
setCurrentClient(client);
client.init();
vi.advanceTimersByTime(0);

return payload;
return attributes;
}

describe('experimentalReportSdkConfigIntegration', () => {
Expand Down Expand Up @@ -108,6 +115,44 @@ describe('experimentalReportSdkConfigIntegration', () => {
});
});

it('reports a browser runtime when the client sets none', () => {
vi.mocked(isBrowser).mockReturnValueOnce(true);

const payload = reportConfig(
getDefaultTestClientOptions({
dsn: 'https://username@domain/123',
integrations: [experimentalReportSdkConfigIntegration()],
}),
);

expect(payload.runtime).toEqual({ name: 'browser' });
});

it('reports no runtime outside the browser when the client sets none', () => {
const payload = reportConfig(
getDefaultTestClientOptions({
dsn: 'https://username@domain/123',
integrations: [experimentalReportSdkConfigIntegration()],
}),
);

expect(payload).not.toHaveProperty('runtime');
});

it('reports a different hash for a different runtime', () => {
const options = { dsn: 'https://username@domain/123', integrations: [experimentalReportSdkConfigIntegration()] };
// Server clients set the runtime; the test client's options type doesn't declare it.
const nodeRuntime = { runtime: { name: 'node', version: 'v24.22.1' } };
const otherNodeRuntime = { runtime: { name: 'node', version: 'v26.0.0' } };

const node = reportAttributes(getDefaultTestClientOptions({ ...options, ...nodeRuntime }));
const otherNode = reportAttributes(getDefaultTestClientOptions({ ...options, ...otherNodeRuntime }));
vi.mocked(isBrowser).mockReturnValueOnce(true);
const browser = reportAttributes(getDefaultTestClientOptions(options));

expect(new Set([node, otherNode, browser].map(attributes => attributes['sentry.sdk_config.hash'])).size).toBe(3);
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Feat lacks integration or E2E test

Low Severity

This feat only adds unit tests that mock isBrowser(), so they never prove a real browser client reports { name: 'browser' }. Feat PRs need at least one integration or E2E test; this was flagged because it was mentioned in the review rules.

Additional Locations (1)
Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Reviewed by Cursor Bugbot for commit e268386. Configure here.


it('reports the names of the default integrations the user passed', () => {
const userOptions = captureOptionsSetByUser({
defaultIntegrations: [experimentalReportSdkConfigIntegration()],
Expand Down
Loading