Skip to content

feat(tracing): Move tracing code to internal package #7451

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 14, 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/nextjs/test/integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@sentry/react": "file:../../../react",
"@sentry/replay": "file:../../../replay",
"@sentry/tracing": "file:../../../tracing",
"@sentry-internal/tracing": "file:../../../tracing-internal",
"@sentry/types": "file:../../../types",
"@sentry/utils": "file:../../../utils"
}
Expand Down
1 change: 1 addition & 0 deletions packages/remix/test/integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@sentry/react": "file:../../../react",
"@sentry/replay": "file:../../../replay",
"@sentry/tracing": "file:../../../tracing",
"@sentry-internal/tracing": "file:../../../tracing-internal",
"@sentry/types": "file:../../../types",
"@sentry/utils": "file:../../../utils"
},
Expand Down
File renamed without changes.
35 changes: 34 additions & 1 deletion packages/tracing-internal/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,34 @@
export {};
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 { BrowserTracing } from './browser';

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
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"
Copy link
Member

Choose a reason for hiding this comment

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

Think we still need tslib here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Probably not!

"@sentry-internal/tracing": "7.43.0"
},
"devDependencies": {
"@sentry/browser": "7.43.0",
"@sentry-internal/integration-shims": "7.43.0",
"@sentry/browser": "7.43.0",
"@sentry/core": "7.43.0",
"@sentry/types": "7.43.0",
"@sentry/utils": "7.43.0",
"@types/express": "^4.17.14"
},
"scripts": {
Expand Down
4 changes: 1 addition & 3 deletions packages/tracing/src/index.bundle.base.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 Down
32 changes: 2 additions & 30 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 Down
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
7 changes: 3 additions & 4 deletions packages/tracing/test/integrations/graphql.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 { GraphQL } from '../../src/node/integrations/graphql';
import { Integrations, Span } from '../../src';
import { getTestClient } from '../testutils';

const GQLExecute = {
Expand Down Expand Up @@ -33,7 +32,7 @@ describe('setupOnce', () => {
let childSpan: Span;

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

const integration = new GraphQL();
const integration = new Integrations.GraphQL();
integration.setupOnce(
() => {},
() => hub,
Expand Down
7 changes: 3 additions & 4 deletions packages/tracing/test/integrations/node/mongo.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 { Mongo } from '../../../src/node/integrations/mongo';
import { Integrations, Span } from '../../../src';
import { getTestClient } from '../../testutils';

class Collection {
Expand Down Expand Up @@ -52,7 +51,7 @@ describe('patchOperation()', () => {
let childSpan: Span;

beforeAll(() => {
new Mongo({
new Integrations.Mongo({
operations: ['insertOne', 'initializeOrderedBulkOp'],
}).setupOnce(
() => undefined,
Expand Down Expand Up @@ -124,7 +123,7 @@ describe('patchOperation()', () => {
const client = getTestClient({ instrumenter: 'otel' });
const hub = new Hub(client);

const integration = new Mongo();
const integration = new Integrations.Mongo();
integration.setupOnce(
() => {},
() => hub,
Expand Down
7 changes: 3 additions & 4 deletions packages/tracing/test/integrations/node/postgres.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 { Postgres } from '../../../src/node/integrations/postgres';
import { Integrations, Span } from '../../../src';
import { getTestClient } from '../../testutils';

class PgClient {
Expand Down Expand Up @@ -51,7 +50,7 @@ describe('setupOnce', () => {
let childSpan: Span;

beforeAll(() => {
(pgApi === 'pg' ? new Postgres() : new Postgres({ usePgNative: true })).setupOnce(
(pgApi === 'pg' ? new Integrations.Postgres() : new Integrations.Postgres({ usePgNative: true })).setupOnce(
() => undefined,
() => new Hub(undefined, scope),
);
Expand Down Expand Up @@ -107,7 +106,7 @@ describe('setupOnce', () => {
const client = getTestClient({ instrumenter: 'otel' });
const hub = new Hub(client);

const integration = new Postgres();
const integration = new Integrations.Postgres();
integration.setupOnce(
() => {},
() => hub,
Expand Down
7 changes: 3 additions & 4 deletions packages/tracing/test/integrations/node/prisma.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 { Prisma } from '../../../src/node/integrations/prisma';
import { Integrations, Span } from '../../../src';
import { getTestClient } from '../../testutils';

type PrismaMiddleware = (params: unknown, next: (params?: unknown) => Promise<unknown>) => Promise<unknown>;
Expand Down Expand Up @@ -32,7 +31,7 @@ describe('setupOnce', function () {
let childSpan: Span;

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

const integration = new Prisma({ client: Client });
const integration = new Integrations.Prisma({ client: Client });
integration.setupOnce(
() => {},
() => hub,
Expand Down