Skip to content

feat(tracing): Revert browser tracing integration changes #10328

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
Jan 24, 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
11 changes: 0 additions & 11 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@ npx @sentry/migr8@latest
This will let you select which updates to run, and automatically update your code. Make sure to still review all code
changes!

## Deprecate transaction-related options to `BrowserTracing`

When configuring the `BrowserTracing` integration, some options have been renamed:

- `startTransactionOnPageLoad` --> `spanOnPageLoad`
- `startTransactionOnLocationChange` --> `spanOnLocationChange`
- `markBackgroundTransactions` --> `markBackgroundSpan`

Also, `beforeNavigate` is replaced with a `beforeStartSpan` callback, which receives `StartSpanOptions`.

## Deprecate using `getClient()` to check if the SDK was initialized

In v8, `getClient()` will stop returning `undefined` if `Sentry.init()` was not called. For cases where this may be used
Expand All @@ -46,7 +36,6 @@ The following list shows how integrations should be migrated:

| Old | New | Packages |
| ------------------------- | -------------------------------- | ------------------------------------------------------------------------------------------------------- |
| `new BrowserTracing()` | `browserTracingIntegration()` | `@sentry/browser` |
| `new InboundFilters()` | `inboundFiltersIntegration()` | `@sentry/core`, `@sentry/browser`, `@sentry/node`, `@sentry/deno`, `@sentry/bun`, `@sentry/vercel-edge` |
| `new FunctionToString()` | `functionToStringIntegration()` | `@sentry/core`, `@sentry/browser`, `@sentry/node`, `@sentry/deno`, `@sentry/bun`, `@sentry/vercel-edge` |
| `new LinkedErrors()` | `linkedErrorsIntegration()` | `@sentry/core`, `@sentry/browser`, `@sentry/node`, `@sentry/deno`, `@sentry/bun`, `@sentry/vercel-edge` |
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/src/client/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { BrowserOptions } from '@sentry/browser';
import {
browserTracingIntegration,
BrowserTracing,
getDefaultIntegrations as getBrowserDefaultIntegrations,
init as initBrowserSdk,
setTag,
Expand Down Expand Up @@ -34,7 +34,7 @@ function getDefaultIntegrations(options: BrowserOptions): Integration[] | undefi
// in which case everything inside will get treeshaken away
if (typeof __SENTRY_TRACING__ === 'undefined' || __SENTRY_TRACING__) {
if (hasTracingEnabled(options)) {
return [...getBrowserDefaultIntegrations(options), browserTracingIntegration()];
return [...getBrowserDefaultIntegrations(options), new BrowserTracing()];
}
}

Expand Down
7 changes: 3 additions & 4 deletions packages/astro/test/client/sdk.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { BrowserClient, BrowserTracing } from '@sentry/browser';
import type { BrowserClient } from '@sentry/browser';
import { getCurrentScope } from '@sentry/browser';
import * as SentryBrowser from '@sentry/browser';
import { SDK_VERSION, WINDOW, browserTracingIntegration, getClient } from '@sentry/browser';
import { BrowserTracing, SDK_VERSION, WINDOW, getClient } from '@sentry/browser';
import { vi } from 'vitest';

import { init } from '../../../astro/src/client/sdk';
Expand Down Expand Up @@ -103,13 +103,12 @@ describe('Sentry client SDK', () => {
it('Overrides the automatically default BrowserTracing instance with a a user-provided instance', () => {
init({
dsn: 'https://[email protected]/1337',
integrations: [browserTracingIntegration({ finalTimeout: 10, startTransactionOnLocationChange: false })],
integrations: [new BrowserTracing({ finalTimeout: 10, startTransactionOnLocationChange: false })],
enableTracing: true,
});

const integrationsToInit = browserInit.mock.calls[0][0]?.defaultIntegrations;

// eslint-disable-next-line deprecation/deprecation
const browserTracing = getClient<BrowserClient>()?.getIntegrationByName('BrowserTracing') as BrowserTracing;
const options = browserTracing.options;

Expand Down
11 changes: 1 addition & 10 deletions packages/browser/src/index.bundle.feedback.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
// This is exported so the loader does not fail when switching off Replay/Tracing
import { Feedback, feedbackIntegration } from '@sentry-internal/feedback';
import {
BrowserTracing,
Replay,
addTracingExtensions,
browserTracingIntegration,
replayIntegration,
} from '@sentry-internal/integration-shims';
import { BrowserTracing, Replay, addTracingExtensions, replayIntegration } from '@sentry-internal/integration-shims';

import * as Sentry from './index.bundle.base';

// TODO (v8): Remove this as it was only needed for backwards compatibility
// eslint-disable-next-line deprecation/deprecation
Sentry.Integrations.Replay = Replay;

// eslint-disable-next-line deprecation/deprecation
Sentry.Integrations.BrowserTracing = BrowserTracing;

export * from './index.bundle.base';
export {
// eslint-disable-next-line deprecation/deprecation
BrowserTracing,
browserTracingIntegration,
addTracingExtensions,
// eslint-disable-next-line deprecation/deprecation
Replay,
Expand Down
4 changes: 0 additions & 4 deletions packages/browser/src/index.bundle.replay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
BrowserTracing,
Feedback,
addTracingExtensions,
browserTracingIntegration,
feedbackIntegration,
} from '@sentry-internal/integration-shims';
import { Replay, replayIntegration } from '@sentry/replay';
Expand All @@ -14,14 +13,11 @@ import * as Sentry from './index.bundle.base';
// eslint-disable-next-line deprecation/deprecation
Sentry.Integrations.Replay = Replay;

// eslint-disable-next-line deprecation/deprecation
Sentry.Integrations.BrowserTracing = BrowserTracing;

export * from './index.bundle.base';
export {
// eslint-disable-next-line deprecation/deprecation
BrowserTracing,
browserTracingIntegration,
addTracingExtensions,
// eslint-disable-next-line deprecation/deprecation
Replay,
Expand Down
5 changes: 1 addition & 4 deletions packages/browser/src/index.bundle.tracing.replay.feedback.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Feedback, feedbackIntegration } from '@sentry-internal/feedback';
import { BrowserTracing, Span, addExtensionMethods, browserTracingIntegration } from '@sentry-internal/tracing';
import { BrowserTracing, Span, addExtensionMethods } from '@sentry-internal/tracing';
import { Replay, replayIntegration } from '@sentry/replay';

import * as Sentry from './index.bundle.base';
Expand All @@ -10,7 +10,6 @@ import * as Sentry from './index.bundle.base';
// eslint-disable-next-line deprecation/deprecation
Sentry.Integrations.Replay = Replay;

// eslint-disable-next-line deprecation/deprecation
Sentry.Integrations.BrowserTracing = BrowserTracing;

// We are patching the global object with our hub extension methods
Expand All @@ -23,9 +22,7 @@ export {
Replay,
feedbackIntegration,
replayIntegration,
// eslint-disable-next-line deprecation/deprecation
BrowserTracing,
browserTracingIntegration,
Span,
addExtensionMethods,
};
Expand Down
5 changes: 1 addition & 4 deletions packages/browser/src/index.bundle.tracing.replay.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Feedback, feedbackIntegration } from '@sentry-internal/integration-shims';
import { BrowserTracing, Span, addExtensionMethods, browserTracingIntegration } from '@sentry-internal/tracing';
import { BrowserTracing, Span, addExtensionMethods } from '@sentry-internal/tracing';
import { Replay, replayIntegration } from '@sentry/replay';

import * as Sentry from './index.bundle.base';
Expand All @@ -10,7 +10,6 @@ import * as Sentry from './index.bundle.base';
// eslint-disable-next-line deprecation/deprecation
Sentry.Integrations.Replay = Replay;

// eslint-disable-next-line deprecation/deprecation
Sentry.Integrations.BrowserTracing = BrowserTracing;

// We are patching the global object with our hub extension methods
Expand All @@ -23,9 +22,7 @@ export {
Replay,
replayIntegration,
feedbackIntegration,
// eslint-disable-next-line deprecation/deprecation
BrowserTracing,
browserTracingIntegration,
Span,
addExtensionMethods,
};
Expand Down
5 changes: 1 addition & 4 deletions packages/browser/src/index.bundle.tracing.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This is exported so the loader does not fail when switching off Replay
import { Feedback, Replay, feedbackIntegration, replayIntegration } from '@sentry-internal/integration-shims';
import { BrowserTracing, Span, addExtensionMethods, browserTracingIntegration } from '@sentry-internal/tracing';
import { BrowserTracing, Span, addExtensionMethods } from '@sentry-internal/tracing';

import * as Sentry from './index.bundle.base';

Expand All @@ -10,7 +10,6 @@ import * as Sentry from './index.bundle.base';
// eslint-disable-next-line deprecation/deprecation
Sentry.Integrations.Replay = Replay;

// eslint-disable-next-line deprecation/deprecation
Sentry.Integrations.BrowserTracing = BrowserTracing;

// We are patching the global object with our hub extension methods
Expand All @@ -23,9 +22,7 @@ export {
Replay,
feedbackIntegration,
replayIntegration,
// eslint-disable-next-line deprecation/deprecation
BrowserTracing,
browserTracingIntegration,
Span,
addExtensionMethods,
};
Expand Down
4 changes: 0 additions & 4 deletions packages/browser/src/index.bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
Feedback,
Replay,
addTracingExtensions,
browserTracingIntegration,
feedbackIntegration,
replayIntegration,
} from '@sentry-internal/integration-shims';
Expand All @@ -15,19 +14,16 @@ import * as Sentry from './index.bundle.base';
// eslint-disable-next-line deprecation/deprecation
Sentry.Integrations.Replay = Replay;

// eslint-disable-next-line deprecation/deprecation
Sentry.Integrations.BrowserTracing = BrowserTracing;

export * from './index.bundle.base';
export {
// eslint-disable-next-line deprecation/deprecation
BrowserTracing,
addTracingExtensions,
// eslint-disable-next-line deprecation/deprecation
Replay,
// eslint-disable-next-line deprecation/deprecation
Feedback,
browserTracingIntegration,
feedbackIntegration,
replayIntegration,
};
Expand Down
2 changes: 0 additions & 2 deletions packages/browser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ export {
} from '@sentry-internal/feedback';

export {
// eslint-disable-next-line deprecation/deprecation
BrowserTracing,
browserTracingIntegration,
defaultRequestInstrumentationOptions,
instrumentOutgoingRequests,
} from '@sentry-internal/tracing';
Expand Down
2 changes: 1 addition & 1 deletion packages/browser/test/unit/profiling/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('BrowserProfilingIntegration', () => {
send,
};
},
integrations: [Sentry.browserTracingIntegration(), new BrowserProfilingIntegration()],
integrations: [new Sentry.BrowserTracing(), new BrowserProfilingIntegration()],
});

const client = Sentry.getClient<BrowserClient>();
Expand Down
113 changes: 111 additions & 2 deletions packages/core/src/tracing/trace.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import type { Span, SpanTimeInput, StartSpanOptions, TransactionContext } from '@sentry/types';

import type {
Instrumenter,
Primitive,
Scope,
Span,
SpanTimeInput,
TransactionContext,
TransactionMetadata,
} from '@sentry/types';
import type { SpanAttributes } from '@sentry/types';
import type { SpanOrigin } from '@sentry/types';
import type { TransactionSource } from '@sentry/types';
import { dropUndefinedKeys, logger, tracingContextFromHeaders } from '@sentry/utils';

import { DEBUG_BUILD } from '../debug-build';
Expand All @@ -10,6 +20,105 @@ import { handleCallbackErrors } from '../utils/handleCallbackErrors';
import { hasTracingEnabled } from '../utils/hasTracingEnabled';
import { spanTimeInputToSeconds, spanToJSON } from '../utils/spanUtils';

interface StartSpanOptions extends TransactionContext {
/** A manually specified start time for the created `Span` object. */
startTime?: SpanTimeInput;

/** If defined, start this span off this scope instead off the current scope. */
scope?: Scope;

/** The name of the span. */
name: string;

/** An op for the span. This is a categorization for spans. */
op?: string;

/** The origin of the span - if it comes from auto instrumenation or manual instrumentation. */
origin?: SpanOrigin;

/** Attributes for the span. */
attributes?: SpanAttributes;

// All remaining fields are deprecated

/**
* @deprecated Manually set the end timestamp instead.
*/
trimEnd?: boolean;

/**
* @deprecated This cannot be set manually anymore.
*/
parentSampled?: boolean;

/**
* @deprecated Use attributes or set data on scopes instead.
*/
metadata?: Partial<TransactionMetadata>;

/**
* The name thingy.
* @deprecated Use `name` instead.
*/
description?: string;

/**
* @deprecated Use `span.setStatus()` instead.
*/
status?: string;

/**
* @deprecated Use `scope` instead.
*/
parentSpanId?: string;

/**
* @deprecated You cannot manually set the span to sampled anymore.
*/
sampled?: boolean;

/**
* @deprecated You cannot manually set the spanId anymore.
*/
spanId?: string;

/**
* @deprecated You cannot manually set the traceId anymore.
*/
traceId?: string;

/**
* @deprecated Use an attribute instead.
*/
source?: TransactionSource;

/**
* @deprecated Use attributes or set tags on the scope instead.
*/
tags?: { [key: string]: Primitive };

/**
* @deprecated Use attributes instead.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
data?: { [key: string]: any };

/**
* @deprecated Use `startTime` instead.
*/
startTimestamp?: number;

/**
* @deprecated Use `span.end()` instead.
*/
endTimestamp?: number;

/**
* @deprecated You cannot set the instrumenter manually anymore.
*/
instrumenter?: Instrumenter;
}

/**
* Wraps a function with a transaction/span and finishes the span after the function is done.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,11 +404,11 @@ export async function instrumentForPerformance(appInstance: ApplicationInstance)
// Maintaining backwards compatibility with config.browserTracingOptions, but passing it with Sentry options is preferred.
const browserTracingOptions = config.browserTracingOptions || config.sentry.browserTracingOptions || {};

const { browserTracingIntegration } = await import('@sentry/browser');
const { BrowserTracing } = await import('@sentry/browser');

const idleTimeout = config.transitionTimeout || 5000;

const browserTracing = browserTracingIntegration({
const browserTracing = new BrowserTracing({
routingInstrumentation: (customStartTransaction, startTransactionOnPageLoad) => {
// eslint-disable-next-line ember/no-private-routing-service
const routerMain = appInstance.lookup('router:main') as EmberRouterMain;
Expand Down
4 changes: 2 additions & 2 deletions packages/ember/addon/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { BrowserOptions, browserTracingIntegration } from '@sentry/browser';
import type { BrowserOptions, BrowserTracing } from '@sentry/browser';
import type { Transaction, TransactionContext } from '@sentry/types';

type BrowserTracingOptions = Parameters<typeof browserTracingIntegration>[0];
type BrowserTracingOptions = ConstructorParameters<typeof BrowserTracing>[0];

export type EmberSentryConfig = {
sentry: BrowserOptions & { browserTracingOptions?: BrowserTracingOptions };
Expand Down
Loading