Skip to content

feat(core): Remove hub check in isSentryRequestUrl #11407

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 2 commits into from
Apr 3, 2024
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
18 changes: 3 additions & 15 deletions packages/core/src/utils/isSentryRequestUrl.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
import type { Client, DsnComponents, Hub } from '@sentry/types';
import type { Client, DsnComponents } from '@sentry/types';

/**
* Checks whether given url points to Sentry server
* @param url url to verify
*
* TODO(v8): Remove Hub fallback type
* @param url url to verify
*/
export function isSentryRequestUrl(url: string, hubOrClient: Hub | Client | undefined): boolean {
const client =
hubOrClient && isHub(hubOrClient)
? // eslint-disable-next-line deprecation/deprecation
hubOrClient.getClient()
: hubOrClient;
export function isSentryRequestUrl(url: string, client: Client | undefined): boolean {
const dsn = client && client.getDsn();
const tunnel = client && client.getOptions().tunnel;

return checkDsn(url, dsn) || checkTunnel(url, tunnel);
}

Expand All @@ -33,8 +26,3 @@ function checkDsn(url: string, dsn: DsnComponents | undefined): boolean {
function removeTrailingSlash(str: string): string {
return str[str.length - 1] === '/' ? str.slice(0, -1) : str;
}

function isHub(hubOrClient: Hub | Client | undefined): hubOrClient is Hub {
// eslint-disable-next-line deprecation/deprecation
return (hubOrClient as Hub).getClient !== undefined;
}
11 changes: 1 addition & 10 deletions packages/core/test/lib/utils/isSentryRequestUrl.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Client, Hub } from '@sentry/types';
import type { Client } from '@sentry/types';

import { isSentryRequestUrl } from '../../../src';

Expand All @@ -17,15 +17,6 @@ describe('isSentryRequestUrl', () => {
getDsn: () => ({ host: dsn }),
} as unknown as Client;

const hub = {
getClient: () => {
return client;
},
} as unknown as Hub;

// Works with hub passed
expect(isSentryRequestUrl(url, hub)).toBe(expected);

// Works with client passed
expect(isSentryRequestUrl(url, client)).toBe(expected);
});
Expand Down