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
6 changes: 4 additions & 2 deletions packages/bundler-plugins/src/core/options-mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type NormalizedOptions = {
org: string | undefined;
project: string | string[] | undefined;
authToken: string | undefined;
url: string;
url: string | undefined;
headers: Record<string, string> | undefined;
debug: boolean;
silent: boolean;
Expand Down Expand Up @@ -101,7 +101,9 @@ export function normalizeUserOptions(userOptions: UserOptions): NormalizedOption
? process.env['SENTRY_PROJECT'].split(',').map(p => p.trim())
: process.env['SENTRY_PROJECT']),
authToken: userOptions.authToken ?? process.env['SENTRY_AUTH_TOKEN'],
url: userOptions.url ?? process.env['SENTRY_URL'] ?? SENTRY_SAAS_URL,
// No sentry.io default: the CLI then uses the server an `sntrys_` org token was issued for, and
// sentry.io otherwise. A default here would send self-hosted tokens to sentry.io.
url: userOptions.url ?? process.env['SENTRY_URL'],
headers: userOptions.headers,
debug: userOptions.debug ?? false,
silent: userOptions.silent ?? false,
Expand Down
3 changes: 2 additions & 1 deletion packages/bundler-plugins/src/core/sentry/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ export function setTelemetryDataOnScope(
}

export async function allowedToSendTelemetry(options: NormalizedOptions): Promise<boolean> {
const { telemetry, url } = options;
const { telemetry } = options;
const url = options.url ?? SENTRY_SAAS_URL;

// `options.telemetry` defaults to true
if (telemetry === false) {
Expand Down
2 changes: 1 addition & 1 deletion packages/bundler-plugins/src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export interface Options {
*
* This value can also be set via the `SENTRY_URL` environment variable.
*
* @default "https://sentry.io" (correct value for SaaS customers)
* @default The server that a `sntrys_` organization auth token was created on, otherwise "https://sentry.io"
*/
url?: string;

Expand Down
19 changes: 19 additions & 0 deletions packages/bundler-plugins/test/core/cli-contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { startMockSentryServer } from '@sentry-internal/test-utils';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import { SentryCliAdapter } from '../../src/core/cli';
import type { NormalizedOptions } from '../../src/core/options-mapping';
import { normalizeUserOptions } from '../../src/core/options-mapping';

const PORT = 3037;

Expand Down Expand Up @@ -123,6 +124,24 @@ describe('SentryCliAdapter against the real CLI', () => {
);
});

it('sends a self-hosted org token to its own server when no url is configured', async () => {
const claim = Buffer.from(
JSON.stringify({
iat: 1,
url: `http://localhost:${PORT}`,
region_url: `http://localhost:${PORT}`,
org: 'test-org',
}),
).toString('base64');
const before = recordedRequests();

await new SentryCliAdapter(
normalizeUserOptions({ authToken: `sntrys_${claim}_secret`, org: 'test-org', project: 'test-project' }),
).createRelease('1.0.0');

expect(requestsSince(before)).toContain('POST /api/0/organizations/test-org/releases/');
});

it('sends the configured headers with every request', async () => {
const before = recordedRequestRecords();

Expand Down
4 changes: 2 additions & 2 deletions packages/bundler-plugins/test/core/option-mappings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('normalizeUserOptions()', () => {
metaFramework: undefined,
},
},
url: 'https://sentry.io',
url: undefined,
});
});

Expand Down Expand Up @@ -97,7 +97,7 @@ describe('normalizeUserOptions()', () => {
metaFramework: undefined,
},
},
url: 'https://sentry.io',
url: undefined,
});
});

Expand Down
13 changes: 11 additions & 2 deletions packages/bundler-plugins/test/core/sentry/telemetry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,21 @@ describe('shouldSendTelemetry', () => {

it('should return false if CLI returns a URL other than sentry.io', async () => {
mockRun.mockResolvedValue({ config: { url: 'https://selfhostedSentry.io' } });
expect(await allowedToSendTelemetry({ release: {} } as NormalizedOptions)).toBe(false);
expect(await allowedToSendTelemetry({ url: 'https://sentry.example.com', release: {} } as NormalizedOptions)).toBe(
false,
);
});

it('should not ask the CLI when no url is configured', async () => {
expect(await allowedToSendTelemetry({ release: {} } as NormalizedOptions)).toBe(true);
expect(mockRun).not.toHaveBeenCalled();
});

it('should return true if CLI returns sentry.io as a URL', async () => {
mockRun.mockResolvedValue({ config: { url: 'https://sentry.io' } });
expect(await allowedToSendTelemetry({ release: {} } as NormalizedOptions)).toBe(true);
expect(await allowedToSendTelemetry({ url: 'https://sentry.example.com', release: {} } as NormalizedOptions)).toBe(
true,
);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export interface BuildTimeOptionsBase {
*
* This value can also be set via the `SENTRY_URL` environment variable.
*
* @default "https://sentry.io"
* @default The server that a `sntrys_` organization auth token was created on, otherwise "https://sentry.io"
*/
sentryUrl?: string;

Expand Down
Loading