Skip to content

feat(browser): Export BrowserTracing from package #7366

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

Closed
wants to merge 12 commits into from
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@
"packages/wasm"
],
"devDependencies": {
"@rollup/plugin-commonjs": "^21.0.1",
"@rollup/plugin-node-resolve": "^13.1.3",
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-replace": "^3.0.1",
"@rollup/plugin-sucrase": "^4.0.3",
"@rollup/plugin-typescript": "^8.3.1",
"@size-limit/preset-small-lib": "^4.5.5",
"@size-limit/preset-small-lib": "^8.2.3",
"@strictsoftware/typedoc-plugin-monorepo": "^0.3.1",
"@types/chai": "^4.1.3",
"@types/jest": "^27.4.1",
Expand Down Expand Up @@ -107,15 +107,16 @@
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.31.2",
"sinon": "^7.3.2",
"size-limit": "^4.5.5",
"size-limit": "^8.2.3",
"ts-jest": "^27.1.4",
"ts-node": "10.9.1",
"tslib": "^2.3.1",
"typedoc": "^0.18.0",
"typescript": "3.8.3"
},
"resolutions": {
"**/agent-base": "5"
"**/agent-base": "5",
"**/jest-resolve": "29.5.0"
Copy link
Member Author

Choose a reason for hiding this comment

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

Have to bump this so that we get around jestjs/jest#9771, which requires Jest >= 28

},
"version": "0.0.0",
"name": "sentry-javascript"
Expand Down
5 changes: 3 additions & 2 deletions packages/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"dependencies": {
"@sentry/core": "7.41.0",
"@sentry/replay": "7.41.0",
"@sentry/tracing": "7.41.0",
"@sentry/types": "7.41.0",
"@sentry/utils": "7.41.0",
"tslib": "^1.9.3"
Expand All @@ -42,11 +43,11 @@
"node-fetch": "^2.6.0",
"playwright": "^1.31.1",
"sinon": "^7.3.2",
"webpack": "^4.30.0"
"webpack": "^5.75.0"
},
"scripts": {
"build": "run-p build:transpile build:bundle build:types",
"build:dev": "yarn build",
"build:dev": "run-p build:transpile build:types",
"build:bundle": "rollup --config rollup.bundle.config.js",
"build:transpile": "rollup -c rollup.npm.config.js",
"build:types": "tsc -p tsconfig.types.json",
Expand Down
3 changes: 3 additions & 0 deletions packages/browser/rollup.npm.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ export default makeNPMConfigVariants(
makeBaseNPMConfig({
// packages with bundles have a different build directory structure
hasBundles: true,
packageSpecificConfig: {
external: ['@sentry/tracing/browser'],
},
}),
);
7 changes: 7 additions & 0 deletions packages/browser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,10 @@ export { makeBrowserOfflineTransport } from './transports/offline';
export { onProfilingStartRouteTransaction } from './profiling/hubextensions';
export { BrowserProfilingIntegration } from './profiling/integration';
// __ROLLUP_EXCLUDE_BROWSER_PROFILING_FROM_BUNDLES_END__

// __ROLLUP_EXCLUDE_BROWSER_TRACING_FROM_BUNDLES_BEGIN__
// Need to disable import/no-unresolved since it does not work with the exports field
// https://github.com/import-js/eslint-plugin-import/issues/1810
// eslint-disable-next-line import/no-unresolved
export { addTracingExtensions, BrowserTracing, instrumentOutgoingRequests } from '@sentry/tracing/browser';
// __ROLLUP_EXCLUDE_BROWSER_TRACING_FROM_BUNDLES_END__
2 changes: 1 addition & 1 deletion packages/browser/test/unit/profiling/integration.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getCurrentHub } from '@sentry/browser';
import { getCurrentHub } from '@sentry/core';
import type { Event } from '@sentry/types';
import { TextDecoder, TextEncoder } from 'util';

Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"access": "public"
},
"dependencies": {
"@rollup/plugin-commonjs": "24.0.0",
"@rollup/plugin-commonjs": "24.0.1",
"@sentry/core": "7.41.0",
"@sentry/integrations": "7.41.0",
"@sentry/node": "7.41.0",
Expand Down
3 changes: 3 additions & 0 deletions packages/node-integration-tests/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ module.exports = {
globalSetup: '<rootDir>/utils/setup-tests.ts',
...baseConfig,
testMatch: ['**/test.ts'],
moduleNameMapper: {
uuid: require.resolve('uuid'),
},
setupFilesAfterEnv: ['./jest.setup.js'],
};
9 changes: 8 additions & 1 deletion packages/serverless/jest.config.js
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
module.exports = require('../../jest/jest.config.js');
const baseConfig = require('../../jest/jest.config.js');

module.exports = {
...baseConfig,
moduleNameMapper: {
uuid: require.resolve('uuid'),
},
};
6 changes: 3 additions & 3 deletions packages/tracing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@
".": {
"import": "./build/npm/esm/index.js",
"require": "./build/npm/cjs/index.js",
"types": "./build/npm/types/index.d.ts"
"default": "./build/npm/cjs/index.js"
},
"./node": {
"import": "./build/npm/esm/node/index.js",
"require": "./build/npm/cjs/node/index.js",
"types": "./build/npm/types/node/index.d.ts"
"default": "./build/npm/cjs/node/index.js"
},
"./browser": {
"import": "./build/npm/esm/browser/index.js",
"require": "./build/npm/cjs/browser/index.js",
"types": "./build/npm/types/browser/index.d.ts"
"default": "./build/npm/browser/node/index.js"
}
},
"typesVersions": {
Expand Down
4 changes: 3 additions & 1 deletion packages/tracing/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 @@ -165,6 +165,8 @@ export class BrowserTracing implements Integration {
private _latestRouteSource?: TransactionSource;

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

this.options = {
...DEFAULT_BROWSER_TRACING_OPTIONS,
..._options,
Expand Down
1 change: 1 addition & 0 deletions packages/tracing/src/exports/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export {
extractTraceparentData,
getActiveTransaction,
hasTracingEnabled,
addTracingExtensions,
IdleTransaction,
Span,
// eslint-disable-next-line deprecation/deprecation
Expand Down
14 changes: 10 additions & 4 deletions rollup/bundleHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function makeBaseBundleConfig(options) {
includeReplay,
includeOffline,
includeBrowserProfiling,
includeBrowserTracing,
} = options;

const nodeResolvePlugin = makeNodeResolvePlugin();
Expand All @@ -43,8 +44,9 @@ export function makeBaseBundleConfig(options) {
const licensePlugin = makeLicensePlugin(licenseTitle);
const tsPlugin = makeTSPlugin(jsVersion.toLowerCase());
const excludeReplayPlugin = makeExcludeBlockPlugin('REPLAY');
const excludeOfflineTransport = makeExcludeBlockPlugin('OFFLINE');
const excludeBrowserProfiling = makeExcludeBlockPlugin('BROWSER_PROFILING');
const excludeOfflineTransportPlugin = makeExcludeBlockPlugin('OFFLINE');
const excludeBrowserProfilingPlugin = makeExcludeBlockPlugin('BROWSER_PROFILING');
const excludeBrowserTracingPlugin = makeExcludeBlockPlugin('BROWSER_TRACING');

// The `commonjs` plugin is the `esModuleInterop` of the bundling world. When used with `transformMixedEsModules`, it
// will include all dependencies, imported or required, in the final bundle. (Without it, CJS modules aren't included
Expand All @@ -66,11 +68,15 @@ export function makeBaseBundleConfig(options) {
}

if (!includeOffline) {
standAloneBundleConfig.plugins.push(excludeOfflineTransport);
standAloneBundleConfig.plugins.push(excludeOfflineTransportPlugin);
}

if (!includeBrowserProfiling) {
standAloneBundleConfig.plugins.push(excludeBrowserProfiling);
standAloneBundleConfig.plugins.push(excludeBrowserProfilingPlugin);
}

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

// used by `@sentry/integrations` and `@sentry/wasm` (bundles which need to be combined with a stand-alone SDK bundle)
Expand Down
10 changes: 8 additions & 2 deletions scripts/node-unit-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,21 @@ const DEFAULT_SKIP_TESTS_PACKAGES = [
];

// These packages don't support Node 8 for syntax or dependency reasons.
const NODE_8_SKIP_TESTS_PACKAGES = ['@sentry/gatsby', '@sentry/serverless', '@sentry/nextjs', '@sentry/remix', '@sentry/sveltekit'];
const NODE_8_SKIP_TESTS_PACKAGES = [
'@sentry/gatsby',
'@sentry/serverless',
'@sentry/nextjs',
'@sentry/remix',
'@sentry/sveltekit',
];

// We have to downgrade some of our dependencies in order to run tests in Node 8 and 10.
const NODE_8_LEGACY_DEPENDENCIES = [
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
];
Expand All @@ -36,7 +43,6 @@ const NODE_12_LEGACY_DEPENDENCIES = ['[email protected]'];

const NODE_14_SKIP_TESTS_PACKAGES = ['@sentry/sveltekit'];


type JSONValue = string | number | boolean | null | JSONArray | JSONObject;

type JSONObject = {
Expand Down
Loading