Skip to content

feat(tracing): Add tracing-internal package #7418

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 3 commits into from
Closed
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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"packages/svelte",
"packages/sveltekit",
"packages/tracing",
"packages/tracing-internal",
"packages/types",
"packages/typescript",
"packages/utils",
Expand Down
11 changes: 11 additions & 0 deletions packages/tracing-internal/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
extends: ['../../.eslintrc.js'],
overrides: [
{
files: ['src/node/**'],
rules: {
'@sentry-internal/sdk/no-optional-chaining': 'off',
},
},
],
};
14 changes: 14 additions & 0 deletions packages/tracing-internal/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Copyright (c) 2020 Sentry (https://sentry.io) and individual contributors. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11 changes: 11 additions & 0 deletions packages/tracing-internal/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<p align="center">
<a href="https://sentry.io/?utm_source=github&utm_medium=logo" target="_blank">
<img src="https://sentry-brand.storage.googleapis.com/sentry-wordmark-dark-280x84.png" alt="Sentry" width="280" height="84">
</a>
</p>

## Sentry Internal Tracing Package - Do not use directly, for internal use only

This is an internal package that is being used to migrate @sentry/tracing code to its respective runtime packages.

For v8, @sentry/tracing will be dropped and the code in this package will be split into @sentry/browser and @sentry/node.
1 change: 1 addition & 0 deletions packages/tracing-internal/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('../../jest/jest.config.js');
52 changes: 52 additions & 0 deletions packages/tracing-internal/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"name": "@sentry-internal/tracing",
"version": "7.43.0",
"description": "Sentry Internal Tracing Package",
"repository": "git://github.com/getsentry/sentry-javascript.git",
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/tracing-internal",
"author": "Sentry",
"license": "MIT",
"engines": {
"node": ">=8"
},
"main": "build/cjs/index.js",
"module": "build/esm/index.js",
"types": "build/types/index.d.ts",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@sentry/core": "7.43.0",
"@sentry/types": "7.43.0",
"@sentry/utils": "7.43.0",
"tslib": "^1.9.3"
},
"devDependencies": {
"@sentry/browser": "7.43.0",
"@types/express": "^4.17.14"
},
"scripts": {
"build": "run-p build:transpile build:types",
"build:dev": "yarn build",
"build:transpile": "rollup -c rollup.npm.config.js",
"build:types": "tsc -p tsconfig.types.json",
"build:watch": "run-p build:transpile:watch build:types:watch",
"build:dev:watch": "run-p build:transpile:watch build:types:watch",
"build:transpile:watch": "rollup -c rollup.npm.config.js --watch",
"build:types:watch": "tsc -p tsconfig.types.json --watch",
"build:tarball": "ts-node ../../scripts/prepack.ts --bundles && npm pack ./build/npm",
"clean": "rimraf build coverage sentry-tracing-*.tgz",
"fix": "run-s fix:eslint fix:prettier",
"fix:eslint": "eslint . --format stylish --fix",
"fix:prettier": "prettier --write \"{src,test,scripts}/**/**.ts\"",
"lint": "run-s lint:prettier lint:eslint",
"lint:eslint": "eslint . --format stylish",
"lint:prettier": "prettier --check \"{src,test,scripts}/**/**.ts\"",
"test:unit": "jest",
"test": "jest",
"test:watch": "jest --watch"
},
"volta": {
"extends": "../../package.json"
}
}
3 changes: 3 additions & 0 deletions packages/tracing-internal/rollup.npm.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { makeBaseNPMConfig, makeNPMConfigVariants } from '../../rollup/index.js';

export default makeNPMConfigVariants(makeBaseNPMConfig());
File renamed without changes.
34 changes: 34 additions & 0 deletions packages/tracing-internal/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
export * from './exports';

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

export { Integrations };

// BrowserTracing is already exported as part of `Integrations` above (and for the moment will remain so for
// backwards compatibility), but that interferes with treeshaking, so we also export it separately
// here.
//
// Previously we expected users to import tracing integrations like
//
// import { Integrations } from '@sentry/tracing';
// const instance = new Integrations.BrowserTracing();
//
// This makes the integrations unable to be treeshaken though. To address this, we now have
// this individual export. We now expect users to consume BrowserTracing like so:
//
// import { BrowserTracing } from '@sentry/tracing';
// const instance = new BrowserTracing();
//
// For an example of of the new usage of BrowserTracing, see @sentry/nextjs index.client.ts
export const BrowserTracing = Integrations.BrowserTracing;

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

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

export { addExtensionMethods };
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { BrowserClient } from '@sentry/browser';
import { Hub, makeMain } from '@sentry/core';
import { JSDOM } from 'jsdom';

import { addExtensionMethods } from '../../src';
import { addExtensionMethods } from '../../../tracing/src';
import { getDefaultBrowserClientOptions } from '../../../tracing/test/testutils';
import { registerBackgroundTabDetection } from '../../src/browser/backgroundtab';
import { getDefaultBrowserClientOptions } from '../testutils';

describe('registerBackgroundTabDetection', () => {
let events: Record<string, any> = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import type { BaseTransportOptions, ClientOptions, DsnComponents } from '@sentry
import type { InstrumentHandlerCallback, InstrumentHandlerType } from '@sentry/utils';
import { JSDOM } from 'jsdom';

import type { IdleTransaction } from '../../src';
import { getActiveTransaction } from '../../src';
import type { IdleTransaction } from '../../../tracing/src';
import { getActiveTransaction } from '../../../tracing/src';
import { getDefaultBrowserClientOptions } from '../../../tracing/test/testutils';
import type { BrowserTracingOptions } from '../../src/browser/browsertracing';
import { BrowserTracing, getMetaContent } from '../../src/browser/browsertracing';
import { defaultRequestInstrumentationOptions } from '../../src/browser/request';
import { instrumentRoutingWithDefaults } from '../../src/browser/router';
import { getDefaultBrowserClientOptions } from '../testutils';

let mockChangeHistory: ({ to, from }: { to: string; from?: string }) => void = () => undefined;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { BrowserClient } from '@sentry/browser';
import * as sentryCore from '@sentry/core';
import * as utils from '@sentry/utils';

import type { Transaction } from '../../src';
import { addExtensionMethods, Span, spanStatusfromHttpCode } from '../../src';
import type { Transaction } from '../../../tracing/src';
import { addExtensionMethods, Span, spanStatusfromHttpCode } from '../../../tracing/src';
import { getDefaultBrowserClientOptions } from '../../../tracing/test/testutils';
import type { FetchData, XHRData } from '../../src/browser/request';
import { fetchCallback, instrumentOutgoingRequests, shouldAttachHeaders, xhrCallback } from '../../src/browser/request';
import { getDefaultBrowserClientOptions } from '../testutils';

beforeAll(() => {
addExtensionMethods();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { BrowserClient } from '@sentry/browser';
import { addTracingExtensions, Hub, makeMain } from '@sentry/core';
import type { InstrumentHandlerCallback, InstrumentHandlerType } from '@sentry/utils';

import { getDefaultBrowserClientOptions } from '../../tracing/test/testutils';
import { registerErrorInstrumentation } from '../src/errors';
import { getDefaultBrowserClientOptions } from './testutils';

const mockAddInstrumentationHandler = jest.fn();
let mockErrorCallback: InstrumentHandlerCallback = () => undefined;
Expand Down
9 changes: 9 additions & 0 deletions packages/tracing-internal/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",

"include": ["src/**/*"],

"compilerOptions": {
// package-specific options
}
}
12 changes: 12 additions & 0 deletions packages/tracing-internal/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "./tsconfig.json",

"include": ["test/**/*"],

"compilerOptions": {
// should include all types from `./tsconfig.json` plus types for all test frameworks used
"types": ["node", "jest"]

// other package-specific, test-specific options
}
}
9 changes: 9 additions & 0 deletions packages/tracing-internal/tsconfig.types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": true,
"outDir": "build/types"
}
}
10 changes: 5 additions & 5 deletions packages/tracing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
"access": "public"
},
"dependencies": {
"@sentry/core": "7.43.0",
"@sentry/types": "7.43.0",
"@sentry/utils": "7.43.0",
"tslib": "^1.9.3"
"@sentry-internal/tracing": "7.43.0"
},
"devDependencies": {
"@sentry/browser": "7.43.0",
"@types/express": "^4.17.14"
"@types/express": "^4.17.14",
"@sentry/core": "7.43.0",
"@sentry/types": "7.43.0",
"@sentry/utils": "7.43.0"
},
"scripts": {
"build": "run-p build:transpile build:types build:bundle",
Expand Down
11 changes: 2 additions & 9 deletions packages/tracing/src/index.bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,11 @@ export {
} from '@sentry/browser';
export { SDK_VERSION } from '@sentry/browser';

import { addExtensionMethods, BrowserTracing } from '@sentry-internal/tracing';
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 = {};
Expand All @@ -79,12 +77,7 @@ const INTEGRATIONS: Record<
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 };
export { INTEGRATIONS as Integrations, BrowserTracing };

// We are patching the global object with our hub extension methods
addExtensionMethods();
Expand Down
34 changes: 2 additions & 32 deletions packages/tracing/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,6 @@
export * from './exports';
export * from '@sentry-internal/tracing';

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

export { Integrations };

// This is already exported as part of `Integrations` above (and for the moment will remain so for
// backwards compatibility), but that interferes with treeshaking, so we also export it separately
// here.
//
// Previously we expected users to import tracing integrations like
//
// import { Integrations } from '@sentry/tracing';
// const instance = new Integrations.BrowserTracing();
//
// This makes the integrations unable to be treeshaken though. To address this, we now have
// this individual export. We now expect users to consume BrowserTracing like so:
//
// import { BrowserTracing } from '@sentry/tracing';
// 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,
instrumentOutgoingRequests,
defaultRequestInstrumentationOptions,
} from './browser';

export type { RequestInstrumentationOptions } from './browser';
import { addExtensionMethods } from '@sentry-internal/tracing';

// Treeshakable guard to remove all code related to tracing
declare const __SENTRY_TRACING__: boolean;
Expand All @@ -38,5 +10,3 @@ if (typeof __SENTRY_TRACING__ === 'undefined' || __SENTRY_TRACING__) {
// We are patching the global object with our hub extension methods
addExtensionMethods();
}

export { addExtensionMethods };
3 changes: 1 addition & 2 deletions packages/tracing/test/hub.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { Hub, makeMain } from '@sentry/core';
import * as utilsModule from '@sentry/utils'; // for mocking
import { logger } from '@sentry/utils';

import { addExtensionMethods, extractTraceparentData, TRACEPARENT_REGEXP, Transaction } from '../src';
import { BrowserTracing } from '../src/browser/browsertracing';
import { addExtensionMethods, BrowserTracing, extractTraceparentData, TRACEPARENT_REGEXP, Transaction } from '../src';
import {
addDOMPropertiesToGlobal,
getDefaultBrowserClientOptions,
Expand Down
7 changes: 3 additions & 4 deletions packages/tracing/test/integrations/apollo-nestjs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import { Hub, Scope } from '@sentry/core';
import { logger } from '@sentry/utils';

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

type ApolloResolverGroup = {
Expand Down Expand Up @@ -67,7 +66,7 @@ describe('setupOnce', () => {
let GraphQLFactoryInstance: GraphQLFactory;

beforeAll(() => {
new Apollo({
new Integrations.Apollo({
useNestjs: true,
}).setupOnce(
() => undefined,
Expand Down Expand Up @@ -113,7 +112,7 @@ describe('setupOnce', () => {
const client = getTestClient({ instrumenter: 'otel' });
const hub = new Hub(client);

const integration = new Apollo({ useNestjs: true });
const integration = new Integrations.Apollo({ useNestjs: true });
integration.setupOnce(
() => {},
() => hub,
Expand Down
7 changes: 3 additions & 4 deletions packages/tracing/test/integrations/apollo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import { Hub, Scope } from '@sentry/core';
import { logger } from '@sentry/utils';

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

type ApolloResolverGroup = {
Expand Down Expand Up @@ -69,7 +68,7 @@ describe('setupOnce', () => {
let ApolloServer: ApolloServerBase;

beforeAll(() => {
new Apollo().setupOnce(
new Integrations.Apollo().setupOnce(
() => undefined,
() => new Hub(undefined, scope),
);
Expand Down Expand Up @@ -113,7 +112,7 @@ describe('setupOnce', () => {
const client = getTestClient({ instrumenter: 'otel' });
const hub = new Hub(client);

const integration = new Apollo();
const integration = new Integrations.Apollo();
integration.setupOnce(
() => {},
() => hub,
Expand Down
Loading