diff --git a/packages/core/src/api.ts b/packages/core/src/api.ts index c46a09b3484d..f345e14b1514 100644 --- a/packages/core/src/api.ts +++ b/packages/core/src/api.ts @@ -1,4 +1,4 @@ -import type { ClientOptions, DsnComponents, DsnLike, SdkInfo } from '@sentry/types'; +import type { DsnComponents, DsnLike, SdkInfo } from '@sentry/types'; import { dsnToString, makeDsn, urlEncode } from '@sentry/utils'; const SENTRY_API_VERSION = '7'; @@ -31,20 +31,7 @@ function _encodedAuth(dsn: DsnComponents, sdkInfo: SdkInfo | undefined): string * * Sending auth as part of the query string and not as custom HTTP headers avoids CORS preflight requests. */ -export function getEnvelopeEndpointWithUrlEncodedAuth( - dsn: DsnComponents, - // TODO (v8): Remove `tunnelOrOptions` in favor of `options`, and use the substitute code below - // options: ClientOptions = {} as ClientOptions, - tunnelOrOptions: string | ClientOptions = {} as ClientOptions, -): string { - // TODO (v8): Use this code instead - // const { tunnel, _metadata = {} } = options; - // return tunnel ? tunnel : `${_getIngestEndpoint(dsn)}?${_encodedAuth(dsn, _metadata.sdk)}`; - - const tunnel = typeof tunnelOrOptions === 'string' ? tunnelOrOptions : tunnelOrOptions.tunnel; - const sdkInfo = - typeof tunnelOrOptions === 'string' || !tunnelOrOptions._metadata ? undefined : tunnelOrOptions._metadata.sdk; - +export function getEnvelopeEndpointWithUrlEncodedAuth(dsn: DsnComponents, tunnel?: string, sdkInfo?: SdkInfo): string { return tunnel ? tunnel : `${_getIngestEndpoint(dsn)}?${_encodedAuth(dsn, sdkInfo)}`; } diff --git a/packages/core/src/baseclient.ts b/packages/core/src/baseclient.ts index f6e040b53a1d..d24a168614de 100644 --- a/packages/core/src/baseclient.ts +++ b/packages/core/src/baseclient.ts @@ -135,7 +135,11 @@ export abstract class BaseClient implements Client { } if (this._dsn) { - const url = getEnvelopeEndpointWithUrlEncodedAuth(this._dsn, options); + const url = getEnvelopeEndpointWithUrlEncodedAuth( + this._dsn, + options.tunnel, + options._metadata ? options._metadata.sdk : undefined, + ); this._transport = options.transport({ recordDroppedEvent: this.recordDroppedEvent.bind(this), ...options.transportOptions, diff --git a/packages/core/test/lib/api.test.ts b/packages/core/test/lib/api.test.ts index e370d7026516..d2e500776228 100644 --- a/packages/core/test/lib/api.test.ts +++ b/packages/core/test/lib/api.test.ts @@ -1,4 +1,4 @@ -import type { ClientOptions, DsnComponents } from '@sentry/types'; +import type { DsnComponents, SdkInfo } from '@sentry/types'; import { makeDsn } from '@sentry/utils'; import { getEnvelopeEndpointWithUrlEncodedAuth, getReportDialogEndpoint } from '../../src/api'; @@ -6,7 +6,7 @@ import { getEnvelopeEndpointWithUrlEncodedAuth, getReportDialogEndpoint } from ' const ingestDsn = 'https://abc@xxxx.ingest.sentry.io:1234/subpath/123'; const dsnPublic = 'https://abc@sentry.io:1234/subpath/123'; const tunnel = 'https://hello.com/world'; -const _metadata = { sdk: { name: 'sentry.javascript.browser', version: '12.31.12' } } as ClientOptions['_metadata']; +const sdkInfo = { name: 'sentry.javascript.browser', version: '12.31.12' }; const dsnPublicComponents = makeDsn(dsnPublic)!; @@ -17,25 +17,22 @@ describe('API', () => { "doesn't include `sentry_client` when called with only DSN", dsnPublicComponents, undefined, + undefined, 'https://sentry.io:1234/subpath/api/123/envelope/?sentry_key=abc&sentry_version=7', ], - ['uses `tunnel` value when called with `tunnel` as string', dsnPublicComponents, tunnel, tunnel], + ['uses `tunnel` value when called with `tunnel` option', dsnPublicComponents, tunnel, undefined, tunnel], [ - 'uses `tunnel` value when called with `tunnel` in options', + 'uses `tunnel` value when called with `tunnel` and `sdkInfo` options', dsnPublicComponents, - { tunnel } as ClientOptions, tunnel, - ], - [ - 'uses `tunnel` value when called with `tunnel` and `_metadata` in options', - dsnPublicComponents, - { tunnel, _metadata } as ClientOptions, + sdkInfo, tunnel, ], [ - 'includes `sentry_client` when called with `_metadata` in options and no tunnel', + 'includes `sentry_client` when called with `sdkInfo` in options and no tunnel', dsnPublicComponents, - { _metadata } as ClientOptions, + undefined, + sdkInfo, 'https://sentry.io:1234/subpath/api/123/envelope/?sentry_key=abc&sentry_version=7&sentry_client=sentry.javascript.browser%2F12.31.12', ], ])( @@ -43,10 +40,11 @@ describe('API', () => { ( _testName: string, dsnComponents: DsnComponents, - tunnelOrOptions: string | ClientOptions | undefined, + tunnel: string | undefined, + sdkInfo: SdkInfo | undefined, expected: string, ) => { - expect(getEnvelopeEndpointWithUrlEncodedAuth(dsnComponents, tunnelOrOptions)).toBe(expected); + expect(getEnvelopeEndpointWithUrlEncodedAuth(dsnComponents, tunnel, sdkInfo)).toBe(expected); }, ); }); diff --git a/packages/node-experimental/src/integrations/anr/common.ts b/packages/node-experimental/src/integrations/anr/common.ts index 5617871ccb24..e2e50fae4179 100644 --- a/packages/node-experimental/src/integrations/anr/common.ts +++ b/packages/node-experimental/src/integrations/anr/common.ts @@ -37,6 +37,7 @@ export interface WorkerStartData extends AnrIntegrationOptions { debug: boolean; sdkMetadata: SdkMetadata; dsn: DsnComponents; + tunnel: string | undefined; release: string | undefined; environment: string; dist: string | undefined; diff --git a/packages/node-experimental/src/integrations/anr/index.ts b/packages/node-experimental/src/integrations/anr/index.ts index 40aeafcf08ed..6ef1b5d58ac3 100644 --- a/packages/node-experimental/src/integrations/anr/index.ts +++ b/packages/node-experimental/src/integrations/anr/index.ts @@ -73,6 +73,7 @@ async function _startWorker(client: NodeClient, _options: Partial { @@ -47,7 +47,7 @@ async function sendAbnormalSession(): Promise { log('Sending abnormal session'); updateSession(session, { status: 'abnormal', abnormal_mechanism: 'anr_foreground' }); - const envelope = createSessionEnvelope(session, options.dsn, options.sdkMetadata); + const envelope = createSessionEnvelope(session, options.dsn, options.sdkMetadata, options.tunnel); // Log the envelope so to aid in testing log(JSON.stringify(envelope)); @@ -119,15 +119,15 @@ async function sendAnrEvent(frames?: StackFrame[], traceContext?: TraceContext): tags: options.staticTags, }; - const envelope = createEventEnvelope(event, options.dsn, options.sdkMetadata); - // Log the envelope so to aid in testing + const envelope = createEventEnvelope(event, options.dsn, options.sdkMetadata, options.tunnel); + // Log the envelope to aid in testing log(JSON.stringify(envelope)); await transport.send(envelope); await transport.flush(2000); - // Delay for 5 seconds so that stdio can flush in the main event loop ever restarts. - // This is mainly for the benefit of logging/debugging issues. + // Delay for 5 seconds so that stdio can flush if the main event loop ever restarts. + // This is mainly for the benefit of logging or debugging. setTimeout(() => { process.exit(0); }, 5_000);