Skip to content
Merged
2 changes: 1 addition & 1 deletion packages/tracing/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
extends: ['../../.eslintrc.js'],
overrides: [
{
files: ['src/integrations/node/**'],
files: ['src/node/**'],
rules: {
'@sentry-internal/sdk/no-optional-chaining': 'off',
},
Expand Down
32 changes: 31 additions & 1 deletion packages/tracing/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@sentry/tracing",
"version": "7.41.0",
"description": "Extensions for Sentry AM",
"description": "Sentry Performance Monitoring Package",
"repository": "git://github.com/getsentry/sentry-javascript.git",
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/tracing",
"author": "Sentry",
Expand All @@ -12,6 +12,36 @@
"main": "build/npm/cjs/index.js",
"module": "build/npm/esm/index.js",
"types": "build/npm/types/index.d.ts",
"exports": {
".": {
"import": "./build/npm/esm/index.js",
"require": "./build/npm/cjs/index.js",
"types": "./build/npm/types/index.d.ts"
},
"./node": {
"import": "./build/npm/esm/node/index.js",
"require": "./build/npm/cjs/node/index.js",
"types": "./build/npm/types/node/index.d.ts"
},
"./browser": {
"import": "./build/npm/esm/browser/index.js",
"require": "./build/npm/cjs/browser/index.js",
"types": "./build/npm/types/browser/index.d.ts"
}
},
"typesVersions": {
"*": {
"*": [
"./build/npm/types/index.d.ts"
],
"node": [
"./build/npm/types/node/index.d.ts"
],
"browser": [
"./build/npm/types/browser/index.d.ts"
]
}
},
"publishConfig": {
"access": "public"
},
Expand Down
1 change: 1 addition & 0 deletions packages/tracing/rollup.npm.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { makeBaseNPMConfig, makeNPMConfigVariants } from '../../rollup/index.js'

export default makeNPMConfigVariants(
makeBaseNPMConfig({
entrypoints: ['src/browser/index.ts', 'src/node/index.ts', 'src/index.ts'],
// packages with bundles have a different build directory structure
hasBundles: true,
}),
Expand Down
2 changes: 2 additions & 0 deletions packages/tracing/src/browser/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export * from '../exports';

export type { RequestInstrumentationOptions } from './request';

export { BrowserTracing, BROWSER_TRACING_INTEGRATION_ID } from './browsertracing';
Expand Down
15 changes: 15 additions & 0 deletions packages/tracing/src/exports/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export {
extractTraceparentData,
getActiveTransaction,
hasTracingEnabled,
IdleTransaction,
Span,
// eslint-disable-next-line deprecation/deprecation
SpanStatus,
spanStatusfromHttpCode,
startIdleTransaction,
stripUrlQueryAndFragment,
TRACEPARENT_REGEXP,
Transaction,
} from '@sentry/core';
export type { SpanStatusType } from '@sentry/core';
8 changes: 4 additions & 4 deletions packages/tracing/src/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@ function _autoloadDatabaseIntegrations(): void {

const packageToIntegrationMapping: Record<string, () => Integration> = {
mongodb() {
const integration = dynamicRequire(module, './integrations/node/mongo') as {
const integration = dynamicRequire(module, './node/integrations/mongo') as {
Mongo: IntegrationClass<Integration>;
};
return new integration.Mongo();
},
mongoose() {
const integration = dynamicRequire(module, './integrations/node/mongo') as {
const integration = dynamicRequire(module, './node/integrations/mongo') as {
Mongo: IntegrationClass<Integration>;
};
return new integration.Mongo({ mongoose: true });
},
mysql() {
const integration = dynamicRequire(module, './integrations/node/mysql') as {
const integration = dynamicRequire(module, './node/integrations/mysql') as {
Mysql: IntegrationClass<Integration>;
};
return new integration.Mysql();
},
pg() {
const integration = dynamicRequire(module, './integrations/node/postgres') as {
const integration = dynamicRequire(module, './node/integrations/postgres') as {
Postgres: IntegrationClass<Integration>;
};
return new integration.Postgres();
Expand Down
29 changes: 9 additions & 20 deletions packages/tracing/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,7 @@
export {
extractTraceparentData,
getActiveTransaction,
hasTracingEnabled,
IdleTransaction,
Span,
// eslint-disable-next-line deprecation/deprecation
SpanStatus,
spanStatusfromHttpCode,
startIdleTransaction,
stripUrlQueryAndFragment,
TRACEPARENT_REGEXP,
Transaction,
} from '@sentry/core';
export type { SpanStatusType } from '@sentry/core';
export * from './exports';

import { addExtensionMethods } from './extensions';
import * as Integrations from './integrations';

export type { RequestInstrumentationOptions } from './browser';
import * as Integrations from './node/integrations';

export { Integrations };

Expand All @@ -37,9 +21,14 @@ export { Integrations };
// const instance = new BrowserTracing();
//
// For an example of of the new usage of BrowserTracing, see @sentry/nextjs index.client.ts
export { BrowserTracing, BROWSER_TRACING_INTEGRATION_ID } from './browser';
export {
BrowserTracing,
BROWSER_TRACING_INTEGRATION_ID,
instrumentOutgoingRequests,
defaultRequestInstrumentationOptions,
} from './browser';

export { instrumentOutgoingRequests, defaultRequestInstrumentationOptions } from './browser';
export type { RequestInstrumentationOptions } from './browser';

// Treeshakable guard to remove all code related to tracing
declare const __SENTRY_TRACING__: boolean;
Expand Down
11 changes: 0 additions & 11 deletions packages/tracing/src/integrations/index.ts

This file was deleted.

3 changes: 3 additions & 0 deletions packages/tracing/src/node/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from '../exports';

export * from './integrations';
11 changes: 11 additions & 0 deletions packages/tracing/src/node/integrations/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export { Express } from './express';
export { Postgres } from './postgres';
export { Mysql } from './mysql';
export { Mongo } from './mongo';
export { Prisma } from './prisma';
export { GraphQL } from './graphql';
export { Apollo } from './apollo';

// TODO(v8): Remove this export
// Please see `src/index.ts` for more details.
export { BrowserTracing } from '../../browser';
2 changes: 1 addition & 1 deletion packages/tracing/test/integrations/apollo-nestjs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Hub, Scope } from '@sentry/core';
import { logger } from '@sentry/utils';

import { Span } from '../../src';
import { Apollo } from '../../src/integrations/node/apollo';
import { Apollo } from '../../src/node/integrations/apollo';
import { getTestClient } from '../testutils';

type ApolloResolverGroup = {
Expand Down
2 changes: 1 addition & 1 deletion packages/tracing/test/integrations/apollo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Hub, Scope } from '@sentry/core';
import { logger } from '@sentry/utils';

import { Span } from '../../src';
import { Apollo } from '../../src/integrations/node/apollo';
import { Apollo } from '../../src/node/integrations/apollo';
import { getTestClient } from '../testutils';

type ApolloResolverGroup = {
Expand Down
2 changes: 1 addition & 1 deletion packages/tracing/test/integrations/graphql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Hub, Scope } from '@sentry/core';
import { logger } from '@sentry/utils';

import { Span } from '../../src';
import { GraphQL } from '../../src/integrations/node/graphql';
import { GraphQL } from '../../src/node/integrations/graphql';
import { getTestClient } from '../testutils';

const GQLExecute = {
Expand Down
2 changes: 1 addition & 1 deletion packages/tracing/test/integrations/node/mongo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Hub, Scope } from '@sentry/core';
import { logger } from '@sentry/utils';

import { Span } from '../../../src';
import { Mongo } from '../../../src/integrations/node/mongo';
import { Mongo } from '../../../src/node/integrations/mongo';
import { getTestClient } from '../../testutils';

class Collection {
Expand Down
2 changes: 1 addition & 1 deletion packages/tracing/test/integrations/node/postgres.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Hub, Scope } from '@sentry/core';
import { logger } from '@sentry/utils';

import { Span } from '../../../src';
import { Postgres } from '../../../src/integrations/node/postgres';
import { Postgres } from '../../../src/node/integrations/postgres';
import { getTestClient } from '../../testutils';

class PgClient {
Expand Down
2 changes: 1 addition & 1 deletion packages/tracing/test/integrations/node/prisma.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Hub, Scope } from '@sentry/core';
import { logger } from '@sentry/utils';

import { Span } from '../../../src';
import { Prisma } from '../../../src/integrations/node/prisma';
import { Prisma } from '../../../src/node/integrations/prisma';
import { getTestClient } from '../../testutils';

type PrismaMiddleware = (params: unknown, next: (params?: unknown) => Promise<unknown>) => Promise<unknown>;
Expand Down
45 changes: 40 additions & 5 deletions scripts/prepack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,33 @@ const NPM_BUILD_DIR = 'build/npm';
const BUILD_DIR = 'build';
const NPM_IGNORE = fs.existsSync('.npmignore') ? '.npmignore' : '../../.npmignore';

const ASSETS = ['README.md', 'LICENSE', 'package.json', NPM_IGNORE];
const ENTRY_POINTS = ['main', 'module', 'types', 'browser'];
const ASSETS = ['README.md', 'LICENSE', 'package.json', NPM_IGNORE] as const;
const ENTRY_POINTS = ['main', 'module', 'types', 'browser'] as const;
const EXPORT_MAP_ENTRY_POINT = 'exports';
const TYPES_VERSIONS_ENTRY_POINT = 'typesVersions';

const packageWithBundles = process.argv.includes('--bundles');
const buildDir = packageWithBundles ? NPM_BUILD_DIR : BUILD_DIR;

type PackageJsonEntryPoints = Record<typeof ENTRY_POINTS[number], string>;

interface PackageJson extends Record<string, unknown>, PackageJsonEntryPoints {
[EXPORT_MAP_ENTRY_POINT]: {
[key: string]: {
import: string;
require: string;
types: string;
};
};
[TYPES_VERSIONS_ENTRY_POINT]: {
[key: string]: {
[key: string]: string[];
};
};
}

// eslint-disable-next-line @typescript-eslint/no-var-requires
const pkgJson: { [key: string]: unknown } = require(path.resolve('package.json'));
const pkgJson: PackageJson = require(path.resolve('package.json'));

// check if build dir exists
if (!fs.existsSync(path.resolve(buildDir))) {
Expand All @@ -44,13 +63,29 @@ ASSETS.forEach(asset => {
// package.json modifications
const newPackageJsonPath = path.resolve(buildDir, 'package.json');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const newPkgJson: { [key: string]: unknown } = require(newPackageJsonPath);
const newPkgJson: PackageJson = require(newPackageJsonPath);

// modify entry points to point to correct paths (i.e. strip out the build directory)
ENTRY_POINTS.filter(entryPoint => newPkgJson[entryPoint]).forEach(entryPoint => {
newPkgJson[entryPoint] = (newPkgJson[entryPoint] as string).replace(`${buildDir}/`, '');
newPkgJson[entryPoint] = newPkgJson[entryPoint].replace(`${buildDir}/`, '');
});

if (newPkgJson[EXPORT_MAP_ENTRY_POINT]) {
Object.entries(newPkgJson[EXPORT_MAP_ENTRY_POINT]).forEach(([key, val]) => {
newPkgJson[EXPORT_MAP_ENTRY_POINT][key] = Object.entries(val).reduce((acc, [key, val]) => {
return { ...acc, [key]: val.replace(`${buildDir}/`, '') };
}, {} as typeof val);
});
}

if (newPkgJson[TYPES_VERSIONS_ENTRY_POINT]) {
Object.entries(newPkgJson[TYPES_VERSIONS_ENTRY_POINT]).forEach(([key, val]) => {
newPkgJson[TYPES_VERSIONS_ENTRY_POINT][key] = Object.entries(val).reduce((acc, [key, val]) => {
return { ...acc, [key]: val.map(v => v.replace(`${buildDir}/`, '')) };
}, {});
});
}

delete newPkgJson.scripts;
delete newPkgJson.volta;
delete newPkgJson.jest;
Expand Down