Skip to content

feat(browser): Export BrowserTracing from @sentry/browser #7472

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 7 commits into from
Mar 17, 2023
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
1 change: 1 addition & 0 deletions packages/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@sentry/replay": "7.43.0",
"@sentry/types": "7.43.0",
"@sentry/utils": "7.43.0",
"@sentry-internal/tracing": "7.43.0",
"tslib": "^1.9.3"
},
"devDependencies": {
Expand Down
4 changes: 4 additions & 0 deletions packages/browser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export { INTEGRATIONS as Integrations };
export { Replay } from '@sentry/replay';
// __ROLLUP_EXCLUDE_REPLAY_FROM_BUNDLES_END__

// __ROLLUP_EXCLUDE_BROWSER_TRACING_FROM_BUNDLES_BEGIN__
export { BrowserTracing } from '@sentry-internal/tracing';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, should we export this from src/integrations/index.ts instead? As this is where you'd currently get this from e.g. in CDN bundles. Also where I hooked this in for #7479.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might make more sense to put it in src/integrations/index.ts since it IS an integration. However, the Replay integration is exported just above this and I thought it might be better to keep all the __ROLLUP_EXCLUDE wrapped exports together near the comments describing why they shouldn't be deleted.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, good question... So I think either way we have to make sure it is available in both places, as that's where we currently have it. So both of these work as of today for CDN bundles:

new Sentry.BrowserTracing();
new Sentry.Integrations.BrowserTracing();

So TLDR I guess it's fine to export it from the root, but we need to make sure that it is also on Sentry.Integrations in CDN bundles.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do this in a follow up given the bundle is already being generated from https://github.com/getsentry/sentry-javascript/blob/develop/packages/tracing/src/index.bundle.base.ts - so I think we should be fine.

// __ROLLUP_EXCLUDE_BROWSER_TRACING_FROM_BUNDLES_END__

// __ROLLUP_EXCLUDE_OFFLINE_FROM_BUNDLES_BEGIN__
export { makeBrowserOfflineTransport } from './transports/offline';
// __ROLLUP_EXCLUDE_OFFLINE_FROM_BUNDLES_END__
Expand Down
4 changes: 3 additions & 1 deletion packages/tracing-internal/src/browser/browsertracing.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable max-lines */
import type { Hub, IdleTransaction } from '@sentry/core';
import { extractTraceparentData, startIdleTransaction, TRACING_DEFAULTS } from '@sentry/core';
import { addTracingExtensions, extractTraceparentData, startIdleTransaction, TRACING_DEFAULTS } from '@sentry/core';
import type { EventProcessor, Integration, Transaction, TransactionContext, TransactionSource } from '@sentry/types';
import { baggageHeaderToDynamicSamplingContext, getDomElement, logger } from '@sentry/utils';

Expand Down Expand Up @@ -172,6 +172,8 @@ export class BrowserTracing implements Integration {
private _collectWebVitals: () => void;

public constructor(_options?: Partial<BrowserTracingOptions>) {
addTracingExtensions();

this.options = {
...DEFAULT_BROWSER_TRACING_OPTIONS,
..._options,
Expand Down
6 changes: 6 additions & 0 deletions rollup/bundleHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export function makeBaseBundleConfig(options) {
includeReplay,
includeOffline,
includeBrowserProfiling,
includeBrowserTracing,
} = options;

const nodeResolvePlugin = makeNodeResolvePlugin();
Expand All @@ -47,6 +48,7 @@ export function makeBaseBundleConfig(options) {
const excludeReplayShimPlugin = makeExcludeBlockPlugin('REPLAY_SHIM');
const excludeOfflineTransport = makeExcludeBlockPlugin('OFFLINE');
const excludeBrowserProfiling = makeExcludeBlockPlugin('BROWSER_PROFILING');
const excludeBrowserTracing = makeExcludeBlockPlugin('BROWSER_TRACING');
const replayShimPlugin = makeReplayShimPlugin();

// The `commonjs` plugin is the `esModuleInterop` of the bundling world. When used with `transformMixedEsModules`, it
Expand Down Expand Up @@ -82,6 +84,10 @@ export function makeBaseBundleConfig(options) {
standAloneBundleConfig.plugins.push(excludeBrowserProfiling);
}

if (!includeBrowserTracing) {
standAloneBundleConfig.plugins.push(excludeBrowserTracing);
}

// used by `@sentry/integrations` and `@sentry/wasm` (bundles which need to be combined with a stand-alone SDK bundle)
const addOnBundleConfig = {
// These output settings are designed to mimic an IIFE. We don't use Rollup's `iife` format because we don't want to
Expand Down