Skip to content

ref: Cleanup browser profiling integration #10766

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
Feb 21, 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
7 changes: 1 addition & 6 deletions packages/browser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,4 @@ export {
export type { SpanStatusType } from '@sentry/core';
export type { Span } from '@sentry/types';
export { makeBrowserOfflineTransport } from './transports/offline';
export { onProfilingStartRouteTransaction } from './profiling/hubextensions';
export {
// eslint-disable-next-line deprecation/deprecation
BrowserProfilingIntegration,
browserProfilingIntegration,
} from './profiling/integration';
export { browserProfilingIntegration } from './profiling/integration';
25 changes: 3 additions & 22 deletions packages/browser/src/profiling/integration.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { convertIntegrationFnToClass, defineIntegration, getCurrentScope } from '@sentry/core';
import type { Client, EventEnvelope, Integration, IntegrationClass, IntegrationFn, Transaction } from '@sentry/types';
import { defineIntegration, getCurrentScope } from '@sentry/core';
import type { EventEnvelope, IntegrationFn, Transaction } from '@sentry/types';
import type { Profile } from '@sentry/types/src/profiling';
import { logger } from '@sentry/utils';

import { DEBUG_BUILD } from '../debug-build';
import { startProfileForTransaction } from './hubextensions';
import { startProfileForTransaction } from './startProfileForTransaction';
import type { ProfiledEvent } from './utils';
import {
addProfilesToEnvelope,
Expand Down Expand Up @@ -97,22 +97,3 @@ const _browserProfilingIntegration = (() => {
}) satisfies IntegrationFn;

export const browserProfilingIntegration = defineIntegration(_browserProfilingIntegration);

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

// eslint-disable-next-line deprecation/deprecation
export type BrowserProfilingIntegration = typeof BrowserProfilingIntegration;
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable complexity */
import { spanToJSON } from '@sentry/core';
import type { Transaction } from '@sentry/types';
import { logger, timestampInSeconds, uuid4 } from '@sentry/utils';
Expand All @@ -10,32 +9,9 @@ import {
MAX_PROFILE_DURATION_MS,
addProfileToGlobalCache,
isAutomatedPageLoadTransaction,
shouldProfileTransaction,
startJSSelfProfile,
} from './utils';

/**
* Safety wrapper for startTransaction for the unlikely case that transaction starts before tracing is imported -
* if that happens we want to avoid throwing an error from profiling code.
* see https://github.com/getsentry/sentry-javascript/issues/4731.
*
* @experimental
*/
export function onProfilingStartRouteTransaction(transaction: Transaction | undefined): Transaction | undefined {
if (!transaction) {
if (DEBUG_BUILD) {
logger.log('[Profiling] Transaction is undefined, skipping profiling');
}
return transaction;
}

if (shouldProfileTransaction(transaction)) {
return startProfileForTransaction(transaction);
}

return transaction;
}

/**
* Wraps startTransaction and stopTransaction with profiling related logic.
* startProfileForTransaction is called after the call to startTransaction in order to avoid our own code from
Expand Down
108 changes: 0 additions & 108 deletions packages/browser/test/unit/profiling/hubextensions.test.ts

This file was deleted.

6 changes: 3 additions & 3 deletions packages/browser/test/unit/profiling/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ describe('BrowserProfilingIntegration', () => {

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

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

Expand Down