Skip to content

Commit deb41bc

Browse files
authored
ref: Cleanup browser profiling integration (#10766)
This does two things: 1. Remove the deprecated class-based `BrowserProfilingIntegration` 2. Remove the `onProfilingStartRouteTransaction` method - this shouldn't be needed anymore, as now the execution order of browser tracing is ensured to be after browser profiling, ensuring that we had the chance to register the `startTransaction` hook before browser tracing started a transaction (as that now runs in `afterAllSetup`)
1 parent 972298d commit deb41bc

File tree

5 files changed

+7
-163
lines changed

5 files changed

+7
-163
lines changed

packages/browser/src/index.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,4 @@ export {
7979
export type { SpanStatusType } from '@sentry/core';
8080
export type { Span } from '@sentry/types';
8181
export { makeBrowserOfflineTransport } from './transports/offline';
82-
export { onProfilingStartRouteTransaction } from './profiling/hubextensions';
83-
export {
84-
// eslint-disable-next-line deprecation/deprecation
85-
BrowserProfilingIntegration,
86-
browserProfilingIntegration,
87-
} from './profiling/integration';
82+
export { browserProfilingIntegration } from './profiling/integration';

packages/browser/src/profiling/integration.ts

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { convertIntegrationFnToClass, defineIntegration, getCurrentScope } from '@sentry/core';
2-
import type { Client, EventEnvelope, Integration, IntegrationClass, IntegrationFn, Transaction } from '@sentry/types';
1+
import { defineIntegration, getCurrentScope } from '@sentry/core';
2+
import type { EventEnvelope, IntegrationFn, Transaction } from '@sentry/types';
33
import type { Profile } from '@sentry/types/src/profiling';
44
import { logger } from '@sentry/utils';
55

66
import { DEBUG_BUILD } from '../debug-build';
7-
import { startProfileForTransaction } from './hubextensions';
7+
import { startProfileForTransaction } from './startProfileForTransaction';
88
import type { ProfiledEvent } from './utils';
99
import {
1010
addProfilesToEnvelope,
@@ -97,22 +97,3 @@ const _browserProfilingIntegration = (() => {
9797
}) satisfies IntegrationFn;
9898

9999
export const browserProfilingIntegration = defineIntegration(_browserProfilingIntegration);
100-
101-
/**
102-
* Browser profiling integration. Stores any event that has contexts["profile"]["profile_id"]
103-
* This exists because we do not want to await async profiler.stop calls as transaction.finish is called
104-
* in a synchronous context. Instead, we handle sending the profile async from the promise callback and
105-
* rely on being able to pull the event from the cache when we need to construct the envelope. This makes the
106-
* integration less reliable as we might be dropping profiles when the cache is full.
107-
*
108-
* @experimental
109-
* @deprecated Use `browserProfilingIntegration()` instead.
110-
*/
111-
// eslint-disable-next-line deprecation/deprecation
112-
export const BrowserProfilingIntegration = convertIntegrationFnToClass(
113-
INTEGRATION_NAME,
114-
browserProfilingIntegration,
115-
) as IntegrationClass<Integration & { setup: (client: Client) => void }>;
116-
117-
// eslint-disable-next-line deprecation/deprecation
118-
export type BrowserProfilingIntegration = typeof BrowserProfilingIntegration;

packages/browser/src/profiling/hubextensions.ts renamed to packages/browser/src/profiling/startProfileForTransaction.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable complexity */
21
import { spanToJSON } from '@sentry/core';
32
import type { Transaction } from '@sentry/types';
43
import { logger, timestampInSeconds, uuid4 } from '@sentry/utils';
@@ -10,32 +9,9 @@ import {
109
MAX_PROFILE_DURATION_MS,
1110
addProfileToGlobalCache,
1211
isAutomatedPageLoadTransaction,
13-
shouldProfileTransaction,
1412
startJSSelfProfile,
1513
} from './utils';
1614

17-
/**
18-
* Safety wrapper for startTransaction for the unlikely case that transaction starts before tracing is imported -
19-
* if that happens we want to avoid throwing an error from profiling code.
20-
* see https://github.com/getsentry/sentry-javascript/issues/4731.
21-
*
22-
* @experimental
23-
*/
24-
export function onProfilingStartRouteTransaction(transaction: Transaction | undefined): Transaction | undefined {
25-
if (!transaction) {
26-
if (DEBUG_BUILD) {
27-
logger.log('[Profiling] Transaction is undefined, skipping profiling');
28-
}
29-
return transaction;
30-
}
31-
32-
if (shouldProfileTransaction(transaction)) {
33-
return startProfileForTransaction(transaction);
34-
}
35-
36-
return transaction;
37-
}
38-
3915
/**
4016
* Wraps startTransaction and stopTransaction with profiling related logic.
4117
* startProfileForTransaction is called after the call to startTransaction in order to avoid our own code from

packages/browser/test/unit/profiling/hubextensions.test.ts

Lines changed: 0 additions & 108 deletions
This file was deleted.

packages/browser/test/unit/profiling/integration.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ describe('BrowserProfilingIntegration', () => {
4848

4949
const client = Sentry.getClient<BrowserClient>();
5050

51-
// eslint-disable-next-line deprecation/deprecation
52-
const currentTransaction = Sentry.getCurrentScope().getTransaction();
53-
expect(currentTransaction?.op).toBe('pageload');
51+
const currentTransaction = Sentry.getActiveSpan();
52+
expect(currentTransaction).toBeDefined();
53+
expect(Sentry.spanToJSON(currentTransaction!).op).toBe('pageload');
5454
currentTransaction?.end();
5555
await client?.flush(1000);
5656

0 commit comments

Comments
 (0)