Skip to content

Commit

Permalink
ref: Fix tracing bundle build without replay
Browse files Browse the repository at this point in the history
  • Loading branch information
mydea committed Mar 13, 2023
1 parent 91e8440 commit bd507e8
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 95 deletions.
2 changes: 1 addition & 1 deletion packages/tracing/rollup.bundle.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const builds = [];
entrypoints: ['src/index.bundle.ts'],
jsVersion,
licenseTitle: '@sentry/tracing & @sentry/browser',
includeReplay: 'shim',
includeReplay: false,
outputFileBase: () => `bundles/bundle.tracing${jsVersion === 'es5' ? '.es5' : ''}`,
});

Expand Down
92 changes: 92 additions & 0 deletions packages/tracing/src/index.bundle.base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
export type {
Breadcrumb,
Request,
SdkInfo,
Event,
Exception,
// eslint-disable-next-line deprecation/deprecation
Severity,
SeverityLevel,
StackFrame,
Stacktrace,
Thread,
User,
} from '@sentry/types';

export type { BrowserOptions, ReportDialogOptions } from '@sentry/browser';

export {
addGlobalEventProcessor,
addBreadcrumb,
captureException,
captureEvent,
captureMessage,
configureScope,
getHubFromCarrier,
getCurrentHub,
Hub,
Scope,
setContext,
setExtra,
setExtras,
setTag,
setTags,
setUser,
startTransaction,
makeFetchTransport,
makeXHRTransport,
withScope,
} from '@sentry/browser';

export { BrowserClient } from '@sentry/browser';
export {
defaultIntegrations,
defaultStackParser,
forceLoad,
init,
lastEventId,
onLoad,
showReportDialog,
flush,
close,
wrap,
} from '@sentry/browser';
export { SDK_VERSION } from '@sentry/browser';

import { Integrations as BrowserIntegrations } from '@sentry/browser';
import type { Integration } from '@sentry/types';
import { GLOBAL_OBJ } from '@sentry/utils';

import { BrowserTracing } from './browser';
import { addExtensionMethods } from './extensions';

export { Span } from '@sentry/core';

let windowIntegrations = {};

// This block is needed to add compatibility with the integrations packages when used with a CDN
if (GLOBAL_OBJ.Sentry && GLOBAL_OBJ.Sentry.Integrations) {
windowIntegrations = GLOBAL_OBJ.Sentry.Integrations;
}

// For whatever reason, it does not recognize BrowserTracing or some of the BrowserIntegrations as Integration
const INTEGRATIONS: Record<
string,
Integration | typeof BrowserTracing | typeof BrowserIntegrations[keyof typeof BrowserIntegrations]
> = {
...windowIntegrations,
...BrowserIntegrations,
BrowserTracing,
};

export { INTEGRATIONS as Integrations };
// Though in this case exporting `BrowserTracing` separately (in addition to exporting it as part of
// `Sentry.Integrations`) doesn't gain us any bundle size advantage (we're making the bundle here, not the user, and we
// can't leave anything out of ours), it does bring the API for using the integration in line with that recommended for
// users bundling Sentry themselves.
export { BrowserTracing };

// We are patching the global object with our hub extension methods
addExtensionMethods();

export { addExtensionMethods };
2 changes: 1 addition & 1 deletion packages/tracing/src/index.bundle.replay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ Sentry.Integrations.Replay = Replay;

export { Replay };

export * from './index.bundle';
export * from './index.bundle.base';
96 changes: 3 additions & 93 deletions packages/tracing/src/index.bundle.ts
Original file line number Diff line number Diff line change
@@ -1,94 +1,4 @@
export type {
Breadcrumb,
Request,
SdkInfo,
Event,
Exception,
// eslint-disable-next-line deprecation/deprecation
Severity,
SeverityLevel,
StackFrame,
Stacktrace,
Thread,
User,
} from '@sentry/types';
// This is exported so the loader does not fail when switching off Replay
export { Replay } from '@sentry-internal/integration-shims';

export type { BrowserOptions, ReportDialogOptions } from '@sentry/browser';

export {
addGlobalEventProcessor,
addBreadcrumb,
captureException,
captureEvent,
captureMessage,
configureScope,
getHubFromCarrier,
getCurrentHub,
Hub,
Scope,
setContext,
setExtra,
setExtras,
setTag,
setTags,
setUser,
startTransaction,
makeFetchTransport,
makeXHRTransport,
withScope,
// This is replaced with a shim in rollup
Replay,
} from '@sentry/browser';

export { BrowserClient } from '@sentry/browser';
export {
defaultIntegrations,
defaultStackParser,
forceLoad,
init,
lastEventId,
onLoad,
showReportDialog,
flush,
close,
wrap,
} from '@sentry/browser';
export { SDK_VERSION } from '@sentry/browser';

import { Integrations as BrowserIntegrations } from '@sentry/browser';
import type { Integration } from '@sentry/types';
import { GLOBAL_OBJ } from '@sentry/utils';

import { BrowserTracing } from './browser';
import { addExtensionMethods } from './extensions';

export { Span } from '@sentry/core';

let windowIntegrations = {};

// This block is needed to add compatibility with the integrations packages when used with a CDN
if (GLOBAL_OBJ.Sentry && GLOBAL_OBJ.Sentry.Integrations) {
windowIntegrations = GLOBAL_OBJ.Sentry.Integrations;
}

// For whatever reason, it does not recognize BrowserTracing or some of the BrowserIntegrations as Integration
const INTEGRATIONS: Record<
string,
Integration | typeof BrowserTracing | typeof BrowserIntegrations[keyof typeof BrowserIntegrations]
> = {
...windowIntegrations,
...BrowserIntegrations,
BrowserTracing,
};

export { INTEGRATIONS as Integrations };
// Though in this case exporting `BrowserTracing` separately (in addition to exporting it as part of
// `Sentry.Integrations`) doesn't gain us any bundle size advantage (we're making the bundle here, not the user, and we
// can't leave anything out of ours), it does bring the API for using the integration in line with that recommended for
// users bundling Sentry themselves.
export { BrowserTracing };

// We are patching the global object with our hub extension methods
addExtensionMethods();

export { addExtensionMethods };
export * from './index.bundle.base';

0 comments on commit bd507e8

Please sign in to comment.