diff --git a/packages/node-experimental/src/index.ts b/packages/node-experimental/src/index.ts index 22e29a146df2..4af67b8e22dc 100644 --- a/packages/node-experimental/src/index.ts +++ b/packages/node-experimental/src/index.ts @@ -1,18 +1,18 @@ -export { expressIntegration } from './integrations/express'; -export { fastifyIntegration } from './integrations/fastify'; -export { graphqlIntegration } from './integrations/graphql'; +export { expressIntegration } from './integrations/tracing/express'; +export { fastifyIntegration } from './integrations/tracing/fastify'; +export { graphqlIntegration } from './integrations/tracing/graphql'; export { httpIntegration } from './integrations/http'; -export { mongoIntegration } from './integrations/mongo'; -export { mongooseIntegration } from './integrations/mongoose'; -export { mysqlIntegration } from './integrations/mysql'; -export { mysql2Integration } from './integrations/mysql2'; -export { nestIntegration } from './integrations/nest'; +export { mongoIntegration } from './integrations/tracing/mongo'; +export { mongooseIntegration } from './integrations/tracing/mongoose'; +export { mysqlIntegration } from './integrations/tracing/mysql'; +export { mysql2Integration } from './integrations/tracing/mysql2'; +export { nestIntegration } from './integrations/tracing/nest'; export { nativeNodeFetchIntegration } from './integrations/node-fetch'; -export { postgresIntegration } from './integrations/postgres'; -export { prismaIntegration } from './integrations/prisma'; +export { postgresIntegration } from './integrations/tracing/postgres'; +export { prismaIntegration } from './integrations/tracing/prisma'; export { init, getDefaultIntegrations } from './sdk/init'; -export { getAutoPerformanceIntegrations } from './integrations/getAutoPerformanceIntegrations'; +export { getAutoPerformanceIntegrations } from './integrations/tracing'; export * as Handlers from './sdk/handlers'; export type { Span } from './types'; diff --git a/packages/node-experimental/src/integrations/NodePerformanceIntegration.ts b/packages/node-experimental/src/integrations/NodePerformanceIntegration.ts deleted file mode 100644 index 536b9ed55daa..000000000000 --- a/packages/node-experimental/src/integrations/NodePerformanceIntegration.ts +++ /dev/null @@ -1,57 +0,0 @@ -import type { Instrumentation } from '@opentelemetry/instrumentation'; -import { registerInstrumentations } from '@opentelemetry/instrumentation'; - -/** - * The base node performance integration. - */ -export abstract class NodePerformanceIntegration { - protected _options: IntegrationOptions; - protected _unload?: () => void; - protected _instrumentations?: Instrumentation[] | undefined; - - public abstract name: string; - - public constructor(options: IntegrationOptions) { - this._options = options; - } - - /** - * Load the instrumentation(s) for this integration. - * Returns `true` if the instrumentations were loaded, else false. - */ - public loadInstrumentations(): boolean { - try { - this._instrumentations = this.setupInstrumentation(this._options) || undefined; - } catch (error) { - return false; - } - - return true; - } - - /** - * @inheritDoc - */ - public setupOnce(): void { - const instrumentations = this._instrumentations || this.setupInstrumentation(this._options); - - if (!instrumentations) { - return; - } - - // Register instrumentations we care about - this._unload = registerInstrumentations({ - instrumentations, - }); - } - - /** - * Unregister this integration. - */ - public unregister(): void { - this._unload?.(); - } - - // Return the instrumentation(s) needed for this integration. - public abstract setupInstrumentation(options: IntegrationOptions): Instrumentation[] | void; -} diff --git a/packages/node-experimental/src/integrations/express.ts b/packages/node-experimental/src/integrations/express.ts deleted file mode 100644 index 1931038da714..000000000000 --- a/packages/node-experimental/src/integrations/express.ts +++ /dev/null @@ -1,62 +0,0 @@ -import type { Instrumentation } from '@opentelemetry/instrumentation'; -import { registerInstrumentations } from '@opentelemetry/instrumentation'; -import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express'; -import { defineIntegration } from '@sentry/core'; -import type { Integration, IntegrationFn } from '@sentry/types'; - -import { addOriginToSpan } from '../utils/addOriginToSpan'; -import { NodePerformanceIntegration } from './NodePerformanceIntegration'; - -const _expressIntegration = (() => { - return { - name: 'Express', - setupOnce() { - registerInstrumentations({ - instrumentations: [ - new ExpressInstrumentation({ - requestHook(span) { - addOriginToSpan(span, 'auto.http.otel.express'); - }, - }), - ], - }); - }, - }; -}) satisfies IntegrationFn; - -export const expressIntegration = defineIntegration(_expressIntegration); - -/** - * Express integration - * - * Capture tracing data for express. - * @deprecated Use `expressIntegration()` instead. - */ -export class Express extends NodePerformanceIntegration implements Integration { - /** - * @inheritDoc - */ - public static id: string = 'Express'; - - /** - * @inheritDoc - */ - public name: string; - - public constructor() { - super(); - // eslint-disable-next-line deprecation/deprecation - this.name = Express.id; - } - - /** @inheritDoc */ - public setupInstrumentation(): void | Instrumentation[] { - return [ - new ExpressInstrumentation({ - requestHook(span) { - addOriginToSpan(span, 'auto.http.otel.express'); - }, - }), - ]; - } -} diff --git a/packages/node-experimental/src/integrations/fastify.ts b/packages/node-experimental/src/integrations/fastify.ts deleted file mode 100644 index b34d267934aa..000000000000 --- a/packages/node-experimental/src/integrations/fastify.ts +++ /dev/null @@ -1,63 +0,0 @@ -import type { Instrumentation } from '@opentelemetry/instrumentation'; -import { registerInstrumentations } from '@opentelemetry/instrumentation'; -import { FastifyInstrumentation } from '@opentelemetry/instrumentation-fastify'; -import { defineIntegration } from '@sentry/core'; -import type { Integration, IntegrationFn } from '@sentry/types'; - -import { addOriginToSpan } from '../utils/addOriginToSpan'; -import { NodePerformanceIntegration } from './NodePerformanceIntegration'; - -const _fastifyIntegration = (() => { - return { - name: 'Fastify', - setupOnce() { - registerInstrumentations({ - instrumentations: [ - new FastifyInstrumentation({ - requestHook(span) { - addOriginToSpan(span, 'auto.http.otel.fastify'); - }, - }), - ], - }); - }, - }; -}) satisfies IntegrationFn; - -export const fastifyIntegration = defineIntegration(_fastifyIntegration); - -/** - * Express integration - * - * Capture tracing data for fastify. - * - * @deprecated Use `fastifyIntegration()` instead. - */ -export class Fastify extends NodePerformanceIntegration implements Integration { - /** - * @inheritDoc - */ - public static id: string = 'Fastify'; - - /** - * @inheritDoc - */ - public name: string; - - public constructor() { - super(); - // eslint-disable-next-line deprecation/deprecation - this.name = Fastify.id; - } - - /** @inheritDoc */ - public setupInstrumentation(): void | Instrumentation[] { - return [ - new FastifyInstrumentation({ - requestHook(span) { - addOriginToSpan(span, 'auto.http.otel.fastify'); - }, - }), - ]; - } -} diff --git a/packages/node-experimental/src/integrations/graphql.ts b/packages/node-experimental/src/integrations/graphql.ts deleted file mode 100644 index 576d049c44b9..000000000000 --- a/packages/node-experimental/src/integrations/graphql.ts +++ /dev/null @@ -1,65 +0,0 @@ -import type { Instrumentation } from '@opentelemetry/instrumentation'; -import { registerInstrumentations } from '@opentelemetry/instrumentation'; -import { GraphQLInstrumentation } from '@opentelemetry/instrumentation-graphql'; -import { defineIntegration } from '@sentry/core'; -import type { Integration, IntegrationFn } from '@sentry/types'; - -import { addOriginToSpan } from '../utils/addOriginToSpan'; -import { NodePerformanceIntegration } from './NodePerformanceIntegration'; - -const _graphqlIntegration = (() => { - return { - name: 'Graphql', - setupOnce() { - registerInstrumentations({ - instrumentations: [ - new GraphQLInstrumentation({ - ignoreTrivialResolveSpans: true, - responseHook(span) { - addOriginToSpan(span, 'auto.graphql.otel.graphql'); - }, - }), - ], - }); - }, - }; -}) satisfies IntegrationFn; - -export const graphqlIntegration = defineIntegration(_graphqlIntegration); - -/** - * GraphQL integration - * - * Capture tracing data for GraphQL. - * - * @deprecated Use `graphqlIntegration()` instead. - */ -export class GraphQL extends NodePerformanceIntegration implements Integration { - /** - * @inheritDoc - */ - public static id: string = 'GraphQL'; - - /** - * @inheritDoc - */ - public name: string; - - public constructor() { - super(); - // eslint-disable-next-line deprecation/deprecation - this.name = GraphQL.id; - } - - /** @inheritDoc */ - public setupInstrumentation(): void | Instrumentation[] { - return [ - new GraphQLInstrumentation({ - ignoreTrivialResolveSpans: true, - responseHook(span) { - addOriginToSpan(span, 'auto.graphql.otel.graphql'); - }, - }), - ]; - } -} diff --git a/packages/node-experimental/src/integrations/hapi.ts b/packages/node-experimental/src/integrations/hapi.ts deleted file mode 100644 index 1376bcb49ccf..000000000000 --- a/packages/node-experimental/src/integrations/hapi.ts +++ /dev/null @@ -1,51 +0,0 @@ -import type { Instrumentation } from '@opentelemetry/instrumentation'; -import { registerInstrumentations } from '@opentelemetry/instrumentation'; -import { HapiInstrumentation } from '@opentelemetry/instrumentation-hapi'; -import { defineIntegration } from '@sentry/core'; -import type { Integration, IntegrationFn } from '@sentry/types'; - -import { NodePerformanceIntegration } from './NodePerformanceIntegration'; - -const _hapiIntegration = (() => { - return { - name: 'Hapi', - setupOnce() { - registerInstrumentations({ - instrumentations: [new HapiInstrumentation()], - }); - }, - }; -}) satisfies IntegrationFn; - -export const hapiIntegration = defineIntegration(_hapiIntegration); - -/** - * Hapi integration - * - * Capture tracing data for Hapi. - * - * @deprecated Use `hapiIntegration()` instead. - */ -export class Hapi extends NodePerformanceIntegration implements Integration { - /** - * @inheritDoc - */ - public static id: string = 'Hapi'; - - /** - * @inheritDoc - */ - public name: string; - - public constructor() { - super(); - // eslint-disable-next-line deprecation/deprecation - this.name = Hapi.id; - } - - /** @inheritDoc */ - public setupInstrumentation(): void | Instrumentation[] { - // Has no hook to adjust spans and add origin - return [new HapiInstrumentation()]; - } -} diff --git a/packages/node-experimental/src/integrations/mongo.ts b/packages/node-experimental/src/integrations/mongo.ts deleted file mode 100644 index bcfaaaf1bc62..000000000000 --- a/packages/node-experimental/src/integrations/mongo.ts +++ /dev/null @@ -1,63 +0,0 @@ -import type { Instrumentation } from '@opentelemetry/instrumentation'; -import { registerInstrumentations } from '@opentelemetry/instrumentation'; -import { MongoDBInstrumentation } from '@opentelemetry/instrumentation-mongodb'; -import { defineIntegration } from '@sentry/core'; -import type { Integration, IntegrationFn } from '@sentry/types'; - -import { addOriginToSpan } from '../utils/addOriginToSpan'; -import { NodePerformanceIntegration } from './NodePerformanceIntegration'; - -const _mongoIntegration = (() => { - return { - name: 'Mongo', - setupOnce() { - registerInstrumentations({ - instrumentations: [ - new MongoDBInstrumentation({ - responseHook(span) { - addOriginToSpan(span, 'auto.db.otel.mongo'); - }, - }), - ], - }); - }, - }; -}) satisfies IntegrationFn; - -export const mongoIntegration = defineIntegration(_mongoIntegration); - -/** - * MongoDB integration - * - * Capture tracing data for MongoDB. - * - * @deprecated Use `mongoIntegration()` instead. - */ -export class Mongo extends NodePerformanceIntegration implements Integration { - /** - * @inheritDoc - */ - public static id: string = 'Mongo'; - - /** - * @inheritDoc - */ - public name: string; - - public constructor() { - super(); - // eslint-disable-next-line deprecation/deprecation - this.name = Mongo.id; - } - - /** @inheritDoc */ - public setupInstrumentation(): void | Instrumentation[] { - return [ - new MongoDBInstrumentation({ - responseHook(span) { - addOriginToSpan(span, 'auto.db.otel.mongo'); - }, - }), - ]; - } -} diff --git a/packages/node-experimental/src/integrations/mongoose.ts b/packages/node-experimental/src/integrations/mongoose.ts deleted file mode 100644 index a14c7d54a266..000000000000 --- a/packages/node-experimental/src/integrations/mongoose.ts +++ /dev/null @@ -1,63 +0,0 @@ -import type { Instrumentation } from '@opentelemetry/instrumentation'; -import { registerInstrumentations } from '@opentelemetry/instrumentation'; -import { MongooseInstrumentation } from '@opentelemetry/instrumentation-mongoose'; -import { defineIntegration } from '@sentry/core'; -import type { Integration, IntegrationFn } from '@sentry/types'; - -import { addOriginToSpan } from '../utils/addOriginToSpan'; -import { NodePerformanceIntegration } from './NodePerformanceIntegration'; - -const _mongooseIntegration = (() => { - return { - name: 'Mongoose', - setupOnce() { - registerInstrumentations({ - instrumentations: [ - new MongooseInstrumentation({ - responseHook(span) { - addOriginToSpan(span, 'auto.db.otel.mongoose'); - }, - }), - ], - }); - }, - }; -}) satisfies IntegrationFn; - -export const mongooseIntegration = defineIntegration(_mongooseIntegration); - -/** - * Mongoose integration - * - * Capture tracing data for Mongoose. - * - * @deprecated Use `mongooseIntegration()` instead. - */ -export class Mongoose extends NodePerformanceIntegration implements Integration { - /** - * @inheritDoc - */ - public static id: string = 'Mongoose'; - - /** - * @inheritDoc - */ - public name: string; - - public constructor() { - super(); - // eslint-disable-next-line deprecation/deprecation - this.name = Mongoose.id; - } - - /** @inheritDoc */ - public setupInstrumentation(): void | Instrumentation[] { - return [ - new MongooseInstrumentation({ - responseHook(span) { - addOriginToSpan(span, 'auto.db.otel.mongoose'); - }, - }), - ]; - } -} diff --git a/packages/node-experimental/src/integrations/mysql.ts b/packages/node-experimental/src/integrations/mysql.ts deleted file mode 100644 index 3cf0f4e42c87..000000000000 --- a/packages/node-experimental/src/integrations/mysql.ts +++ /dev/null @@ -1,51 +0,0 @@ -import type { Instrumentation } from '@opentelemetry/instrumentation'; -import { registerInstrumentations } from '@opentelemetry/instrumentation'; -import { MySQLInstrumentation } from '@opentelemetry/instrumentation-mysql'; -import { defineIntegration } from '@sentry/core'; -import type { Integration, IntegrationFn } from '@sentry/types'; - -import { NodePerformanceIntegration } from './NodePerformanceIntegration'; - -const _mysqlIntegration = (() => { - return { - name: 'Mysql', - setupOnce() { - registerInstrumentations({ - instrumentations: [new MySQLInstrumentation({})], - }); - }, - }; -}) satisfies IntegrationFn; - -export const mysqlIntegration = defineIntegration(_mysqlIntegration); - -/** - * MySQL integration - * - * Capture tracing data for mysql. - * - * @deprecated Use `mysqlIntegration()` instead. - */ -export class Mysql extends NodePerformanceIntegration implements Integration { - /** - * @inheritDoc - */ - public static id: string = 'Mysql'; - - /** - * @inheritDoc - */ - public name: string; - - public constructor() { - super(); - // eslint-disable-next-line deprecation/deprecation - this.name = Mysql.id; - } - - /** @inheritDoc */ - public setupInstrumentation(): void | Instrumentation[] { - // Has no hook to adjust spans and add origin - return [new MySQLInstrumentation({})]; - } -} diff --git a/packages/node-experimental/src/integrations/mysql2.ts b/packages/node-experimental/src/integrations/mysql2.ts deleted file mode 100644 index bb89d0aa01cb..000000000000 --- a/packages/node-experimental/src/integrations/mysql2.ts +++ /dev/null @@ -1,63 +0,0 @@ -import type { Instrumentation } from '@opentelemetry/instrumentation'; -import { registerInstrumentations } from '@opentelemetry/instrumentation'; -import { MySQL2Instrumentation } from '@opentelemetry/instrumentation-mysql2'; -import { defineIntegration } from '@sentry/core'; -import type { Integration, IntegrationFn } from '@sentry/types'; - -import { addOriginToSpan } from '../utils/addOriginToSpan'; -import { NodePerformanceIntegration } from './NodePerformanceIntegration'; - -const _mysql2Integration = (() => { - return { - name: 'Mysql2', - setupOnce() { - registerInstrumentations({ - instrumentations: [ - new MySQL2Instrumentation({ - responseHook(span) { - addOriginToSpan(span, 'auto.db.otel.mysql2'); - }, - }), - ], - }); - }, - }; -}) satisfies IntegrationFn; - -export const mysql2Integration = defineIntegration(_mysql2Integration); - -/** - * MySQL2 integration - * - * Capture tracing data for mysql2 - * - * @deprecated Use `mysql2Integration()` instead. - */ -export class Mysql2 extends NodePerformanceIntegration implements Integration { - /** - * @inheritDoc - */ - public static id: string = 'Mysql2'; - - /** - * @inheritDoc - */ - public name: string; - - public constructor() { - super(); - // eslint-disable-next-line deprecation/deprecation - this.name = Mysql2.id; - } - - /** @inheritDoc */ - public setupInstrumentation(): void | Instrumentation[] { - return [ - new MySQL2Instrumentation({ - responseHook(span) { - addOriginToSpan(span, 'auto.db.otel.mysql2'); - }, - }), - ]; - } -} diff --git a/packages/node-experimental/src/integrations/nest.ts b/packages/node-experimental/src/integrations/nest.ts deleted file mode 100644 index c03955f71193..000000000000 --- a/packages/node-experimental/src/integrations/nest.ts +++ /dev/null @@ -1,51 +0,0 @@ -import type { Instrumentation } from '@opentelemetry/instrumentation'; -import { registerInstrumentations } from '@opentelemetry/instrumentation'; -import { NestInstrumentation } from '@opentelemetry/instrumentation-nestjs-core'; -import { defineIntegration } from '@sentry/core'; -import type { Integration, IntegrationFn } from '@sentry/types'; - -import { NodePerformanceIntegration } from './NodePerformanceIntegration'; - -const _nestIntegration = (() => { - return { - name: 'Nest', - setupOnce() { - registerInstrumentations({ - instrumentations: [new NestInstrumentation({})], - }); - }, - }; -}) satisfies IntegrationFn; - -export const nestIntegration = defineIntegration(_nestIntegration); - -/** - * Nest framework integration - * - * Capture tracing data for nest. - * - * @deprecated Use `nestIntegration()` instead. - */ -export class Nest extends NodePerformanceIntegration implements Integration { - /** - * @inheritDoc - */ - public static id: string = 'Nest'; - - /** - * @inheritDoc - */ - public name: string; - - public constructor() { - super(); - // eslint-disable-next-line deprecation/deprecation - this.name = Nest.id; - } - - /** @inheritDoc */ - public setupInstrumentation(): void | Instrumentation[] { - // Does not have a hook to adjust spans and add origin - return [new NestInstrumentation({})]; - } -} diff --git a/packages/node-experimental/src/integrations/postgres.ts b/packages/node-experimental/src/integrations/postgres.ts deleted file mode 100644 index 91a6a710ffdd..000000000000 --- a/packages/node-experimental/src/integrations/postgres.ts +++ /dev/null @@ -1,65 +0,0 @@ -import type { Instrumentation } from '@opentelemetry/instrumentation'; -import { registerInstrumentations } from '@opentelemetry/instrumentation'; -import { PgInstrumentation } from '@opentelemetry/instrumentation-pg'; -import { defineIntegration } from '@sentry/core'; -import type { Integration, IntegrationFn } from '@sentry/types'; - -import { addOriginToSpan } from '../utils/addOriginToSpan'; -import { NodePerformanceIntegration } from './NodePerformanceIntegration'; - -const _postgresIntegration = (() => { - return { - name: 'Postgres', - setupOnce() { - registerInstrumentations({ - instrumentations: [ - new PgInstrumentation({ - requireParentSpan: true, - requestHook(span) { - addOriginToSpan(span, 'auto.db.otel.postgres'); - }, - }), - ], - }); - }, - }; -}) satisfies IntegrationFn; - -export const postgresIntegration = defineIntegration(_postgresIntegration); - -/** - * Postgres integration - * - * Capture tracing data for pg. - * - * @deprecated Use `postgresIntegration()` instead. - */ -export class Postgres extends NodePerformanceIntegration implements Integration { - /** - * @inheritDoc - */ - public static id: string = 'Postgres'; - - /** - * @inheritDoc - */ - public name: string; - - public constructor() { - super(); - // eslint-disable-next-line deprecation/deprecation - this.name = Postgres.id; - } - - /** @inheritDoc */ - public setupInstrumentation(): void | Instrumentation[] { - return [ - new PgInstrumentation({ - requireParentSpan: true, - requestHook(span) { - addOriginToSpan(span, 'auto.db.otel.postgres'); - }, - }), - ]; - } -} diff --git a/packages/node-experimental/src/integrations/tracing/express.ts b/packages/node-experimental/src/integrations/tracing/express.ts new file mode 100644 index 000000000000..0606702d8220 --- /dev/null +++ b/packages/node-experimental/src/integrations/tracing/express.ts @@ -0,0 +1,30 @@ +import { registerInstrumentations } from '@opentelemetry/instrumentation'; +import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express'; +import { defineIntegration } from '@sentry/core'; +import type { IntegrationFn } from '@sentry/types'; + +import { addOriginToSpan } from '../../utils/addOriginToSpan'; + +const _expressIntegration = (() => { + return { + name: 'Express', + setupOnce() { + registerInstrumentations({ + instrumentations: [ + new ExpressInstrumentation({ + requestHook(span) { + addOriginToSpan(span, 'auto.http.otel.express'); + }, + }), + ], + }); + }, + }; +}) satisfies IntegrationFn; + +/** + * Express integration + * + * Capture tracing data for express. + */ +export const expressIntegration = defineIntegration(_expressIntegration); diff --git a/packages/node-experimental/src/integrations/tracing/fastify.ts b/packages/node-experimental/src/integrations/tracing/fastify.ts new file mode 100644 index 000000000000..11742d960dff --- /dev/null +++ b/packages/node-experimental/src/integrations/tracing/fastify.ts @@ -0,0 +1,30 @@ +import { registerInstrumentations } from '@opentelemetry/instrumentation'; +import { FastifyInstrumentation } from '@opentelemetry/instrumentation-fastify'; +import { defineIntegration } from '@sentry/core'; +import type { IntegrationFn } from '@sentry/types'; + +import { addOriginToSpan } from '../../utils/addOriginToSpan'; + +const _fastifyIntegration = (() => { + return { + name: 'Fastify', + setupOnce() { + registerInstrumentations({ + instrumentations: [ + new FastifyInstrumentation({ + requestHook(span) { + addOriginToSpan(span, 'auto.http.otel.fastify'); + }, + }), + ], + }); + }, + }; +}) satisfies IntegrationFn; + +/** + * Express integration + * + * Capture tracing data for fastify. + */ +export const fastifyIntegration = defineIntegration(_fastifyIntegration); diff --git a/packages/node-experimental/src/integrations/tracing/graphql.ts b/packages/node-experimental/src/integrations/tracing/graphql.ts new file mode 100644 index 000000000000..a91524ece6bb --- /dev/null +++ b/packages/node-experimental/src/integrations/tracing/graphql.ts @@ -0,0 +1,31 @@ +import { registerInstrumentations } from '@opentelemetry/instrumentation'; +import { GraphQLInstrumentation } from '@opentelemetry/instrumentation-graphql'; +import { defineIntegration } from '@sentry/core'; +import type { IntegrationFn } from '@sentry/types'; + +import { addOriginToSpan } from '../../utils/addOriginToSpan'; + +const _graphqlIntegration = (() => { + return { + name: 'Graphql', + setupOnce() { + registerInstrumentations({ + instrumentations: [ + new GraphQLInstrumentation({ + ignoreTrivialResolveSpans: true, + responseHook(span) { + addOriginToSpan(span, 'auto.graphql.otel.graphql'); + }, + }), + ], + }); + }, + }; +}) satisfies IntegrationFn; + +/** + * GraphQL integration + * + * Capture tracing data for GraphQL. + */ +export const graphqlIntegration = defineIntegration(_graphqlIntegration); diff --git a/packages/node-experimental/src/integrations/tracing/hapi.ts b/packages/node-experimental/src/integrations/tracing/hapi.ts new file mode 100644 index 000000000000..949726af698b --- /dev/null +++ b/packages/node-experimental/src/integrations/tracing/hapi.ts @@ -0,0 +1,22 @@ +import { registerInstrumentations } from '@opentelemetry/instrumentation'; +import { HapiInstrumentation } from '@opentelemetry/instrumentation-hapi'; +import { defineIntegration } from '@sentry/core'; +import type { IntegrationFn } from '@sentry/types'; + +const _hapiIntegration = (() => { + return { + name: 'Hapi', + setupOnce() { + registerInstrumentations({ + instrumentations: [new HapiInstrumentation()], + }); + }, + }; +}) satisfies IntegrationFn; + +/** + * Hapi integration + * + * Capture tracing data for Hapi. + */ +export const hapiIntegration = defineIntegration(_hapiIntegration); diff --git a/packages/node-experimental/src/integrations/getAutoPerformanceIntegrations.ts b/packages/node-experimental/src/integrations/tracing/index.ts similarity index 100% rename from packages/node-experimental/src/integrations/getAutoPerformanceIntegrations.ts rename to packages/node-experimental/src/integrations/tracing/index.ts diff --git a/packages/node-experimental/src/integrations/koa.ts b/packages/node-experimental/src/integrations/tracing/koa.ts similarity index 100% rename from packages/node-experimental/src/integrations/koa.ts rename to packages/node-experimental/src/integrations/tracing/koa.ts diff --git a/packages/node-experimental/src/integrations/tracing/mongo.ts b/packages/node-experimental/src/integrations/tracing/mongo.ts new file mode 100644 index 000000000000..9bbfd16a9581 --- /dev/null +++ b/packages/node-experimental/src/integrations/tracing/mongo.ts @@ -0,0 +1,30 @@ +import { registerInstrumentations } from '@opentelemetry/instrumentation'; +import { MongoDBInstrumentation } from '@opentelemetry/instrumentation-mongodb'; +import { defineIntegration } from '@sentry/core'; +import type { IntegrationFn } from '@sentry/types'; + +import { addOriginToSpan } from '../../utils/addOriginToSpan'; + +const _mongoIntegration = (() => { + return { + name: 'Mongo', + setupOnce() { + registerInstrumentations({ + instrumentations: [ + new MongoDBInstrumentation({ + responseHook(span) { + addOriginToSpan(span, 'auto.db.otel.mongo'); + }, + }), + ], + }); + }, + }; +}) satisfies IntegrationFn; + +/** + * MongoDB integration + * + * Capture tracing data for MongoDB. + */ +export const mongoIntegration = defineIntegration(_mongoIntegration); diff --git a/packages/node-experimental/src/integrations/tracing/mongoose.ts b/packages/node-experimental/src/integrations/tracing/mongoose.ts new file mode 100644 index 000000000000..ba15fc647907 --- /dev/null +++ b/packages/node-experimental/src/integrations/tracing/mongoose.ts @@ -0,0 +1,30 @@ +import { registerInstrumentations } from '@opentelemetry/instrumentation'; +import { MongooseInstrumentation } from '@opentelemetry/instrumentation-mongoose'; +import { defineIntegration } from '@sentry/core'; +import type { IntegrationFn } from '@sentry/types'; + +import { addOriginToSpan } from '../../utils/addOriginToSpan'; + +const _mongooseIntegration = (() => { + return { + name: 'Mongoose', + setupOnce() { + registerInstrumentations({ + instrumentations: [ + new MongooseInstrumentation({ + responseHook(span) { + addOriginToSpan(span, 'auto.db.otel.mongoose'); + }, + }), + ], + }); + }, + }; +}) satisfies IntegrationFn; + +/** + * Mongoose integration + * + * Capture tracing data for Mongoose. + */ +export const mongooseIntegration = defineIntegration(_mongooseIntegration); diff --git a/packages/node-experimental/src/integrations/tracing/mysql.ts b/packages/node-experimental/src/integrations/tracing/mysql.ts new file mode 100644 index 000000000000..4f6123c7eed9 --- /dev/null +++ b/packages/node-experimental/src/integrations/tracing/mysql.ts @@ -0,0 +1,22 @@ +import { registerInstrumentations } from '@opentelemetry/instrumentation'; +import { MySQLInstrumentation } from '@opentelemetry/instrumentation-mysql'; +import { defineIntegration } from '@sentry/core'; +import type { IntegrationFn } from '@sentry/types'; + +const _mysqlIntegration = (() => { + return { + name: 'Mysql', + setupOnce() { + registerInstrumentations({ + instrumentations: [new MySQLInstrumentation({})], + }); + }, + }; +}) satisfies IntegrationFn; + +/** + * MySQL integration + * + * Capture tracing data for mysql. + */ +export const mysqlIntegration = defineIntegration(_mysqlIntegration); diff --git a/packages/node-experimental/src/integrations/tracing/mysql2.ts b/packages/node-experimental/src/integrations/tracing/mysql2.ts new file mode 100644 index 000000000000..14a9e826c332 --- /dev/null +++ b/packages/node-experimental/src/integrations/tracing/mysql2.ts @@ -0,0 +1,30 @@ +import { registerInstrumentations } from '@opentelemetry/instrumentation'; +import { MySQL2Instrumentation } from '@opentelemetry/instrumentation-mysql2'; +import { defineIntegration } from '@sentry/core'; +import type { IntegrationFn } from '@sentry/types'; + +import { addOriginToSpan } from '../../utils/addOriginToSpan'; + +const _mysql2Integration = (() => { + return { + name: 'Mysql2', + setupOnce() { + registerInstrumentations({ + instrumentations: [ + new MySQL2Instrumentation({ + responseHook(span) { + addOriginToSpan(span, 'auto.db.otel.mysql2'); + }, + }), + ], + }); + }, + }; +}) satisfies IntegrationFn; + +/** + * MySQL2 integration + * + * Capture tracing data for mysql2 + */ +export const mysql2Integration = defineIntegration(_mysql2Integration); diff --git a/packages/node-experimental/src/integrations/tracing/nest.ts b/packages/node-experimental/src/integrations/tracing/nest.ts new file mode 100644 index 000000000000..1f2c75e3807e --- /dev/null +++ b/packages/node-experimental/src/integrations/tracing/nest.ts @@ -0,0 +1,22 @@ +import { registerInstrumentations } from '@opentelemetry/instrumentation'; +import { NestInstrumentation } from '@opentelemetry/instrumentation-nestjs-core'; +import { defineIntegration } from '@sentry/core'; +import type { IntegrationFn } from '@sentry/types'; + +const _nestIntegration = (() => { + return { + name: 'Nest', + setupOnce() { + registerInstrumentations({ + instrumentations: [new NestInstrumentation({})], + }); + }, + }; +}) satisfies IntegrationFn; + +/** + * Nest framework integration + * + * Capture tracing data for nest. + */ +export const nestIntegration = defineIntegration(_nestIntegration); diff --git a/packages/node-experimental/src/integrations/tracing/postgres.ts b/packages/node-experimental/src/integrations/tracing/postgres.ts new file mode 100644 index 000000000000..e57df5b52d21 --- /dev/null +++ b/packages/node-experimental/src/integrations/tracing/postgres.ts @@ -0,0 +1,31 @@ +import { registerInstrumentations } from '@opentelemetry/instrumentation'; +import { PgInstrumentation } from '@opentelemetry/instrumentation-pg'; +import { defineIntegration } from '@sentry/core'; +import type { IntegrationFn } from '@sentry/types'; + +import { addOriginToSpan } from '../../utils/addOriginToSpan'; + +const _postgresIntegration = (() => { + return { + name: 'Postgres', + setupOnce() { + registerInstrumentations({ + instrumentations: [ + new PgInstrumentation({ + requireParentSpan: true, + requestHook(span) { + addOriginToSpan(span, 'auto.db.otel.postgres'); + }, + }), + ], + }); + }, + }; +}) satisfies IntegrationFn; + +/** + * Postgres integration + * + * Capture tracing data for pg. + */ +export const postgresIntegration = defineIntegration(_postgresIntegration); diff --git a/packages/node-experimental/src/integrations/prisma.ts b/packages/node-experimental/src/integrations/tracing/prisma.ts similarity index 51% rename from packages/node-experimental/src/integrations/prisma.ts rename to packages/node-experimental/src/integrations/tracing/prisma.ts index 9edd6ce9d02d..1f78262b9a3c 100644 --- a/packages/node-experimental/src/integrations/prisma.ts +++ b/packages/node-experimental/src/integrations/tracing/prisma.ts @@ -1,10 +1,7 @@ -import type { Instrumentation } from '@opentelemetry/instrumentation'; import { registerInstrumentations } from '@opentelemetry/instrumentation'; import { PrismaInstrumentation } from '@prisma/instrumentation'; import { defineIntegration } from '@sentry/core'; -import type { Integration, IntegrationFn } from '@sentry/types'; - -import { NodePerformanceIntegration } from './NodePerformanceIntegration'; +import type { IntegrationFn } from '@sentry/types'; const _prismaIntegration = (() => { return { @@ -20,8 +17,6 @@ const _prismaIntegration = (() => { }; }) satisfies IntegrationFn; -export const prismaIntegration = defineIntegration(_prismaIntegration); - /** * Prisma integration * @@ -30,29 +25,5 @@ export const prismaIntegration = defineIntegration(_prismaIntegration); * previewFeatures = ["tracing"] * For the prisma client. * See https://www.prisma.io/docs/concepts/components/prisma-client/opentelemetry-tracing for more details. - * - * @deprecated Use `prismaIntegration()` instead. */ -export class Prisma extends NodePerformanceIntegration implements Integration { - /** - * @inheritDoc - */ - public static id: string = 'Prisma'; - - /** - * @inheritDoc - */ - public name: string; - - public constructor() { - super(); - // eslint-disable-next-line deprecation/deprecation - this.name = Prisma.id; - } - - /** @inheritDoc */ - public setupInstrumentation(): void | Instrumentation[] { - // does not have a hook to adjust spans & add origin - return [new PrismaInstrumentation({})]; - } -} +export const prismaIntegration = defineIntegration(_prismaIntegration); diff --git a/packages/node-experimental/src/sdk/init.ts b/packages/node-experimental/src/sdk/init.ts index 78d9fa7ef572..093a61cb6966 100644 --- a/packages/node-experimental/src/sdk/init.ts +++ b/packages/node-experimental/src/sdk/init.ts @@ -23,9 +23,9 @@ import { } from '@sentry/utils'; import { DEBUG_BUILD } from '../debug-build'; -import { getAutoPerformanceIntegrations } from '../integrations/getAutoPerformanceIntegrations'; import { httpIntegration } from '../integrations/http'; import { nativeNodeFetchIntegration } from '../integrations/node-fetch'; +import { getAutoPerformanceIntegrations } from '../integrations/tracing'; import { makeNodeTransport } from '../transports'; import type { NodeClientOptions, NodeOptions } from '../types'; import { NodeClient } from './client'; diff --git a/packages/node-experimental/test/sdk/init.test.ts b/packages/node-experimental/test/sdk/init.test.ts index 5474f3c1ca07..7f0c3a8d71ec 100644 --- a/packages/node-experimental/test/sdk/init.test.ts +++ b/packages/node-experimental/test/sdk/init.test.ts @@ -1,6 +1,6 @@ import type { Integration } from '@sentry/types'; -import * as auto from '../../src/integrations/getAutoPerformanceIntegrations'; +import * as auto from '../../src/integrations/tracing'; import { getClient } from '../../src/sdk/api'; import { init } from '../../src/sdk/init'; import { cleanupOtel } from '../helpers/mockSdkInit';