@sentry/node 10.0.0-alpha.1 → 10.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/build/cjs/index.js +2 -0
  2. package/build/cjs/index.js.map +1 -1
  3. package/build/cjs/integrations/tracing/fastify/index.js +57 -11
  4. package/build/cjs/integrations/tracing/fastify/index.js.map +1 -1
  5. package/build/cjs/integrations/tracing/firebase/firebase.js +32 -0
  6. package/build/cjs/integrations/tracing/firebase/firebase.js.map +1 -0
  7. package/build/cjs/integrations/tracing/firebase/otel/firebaseInstrumentation.js +41 -0
  8. package/build/cjs/integrations/tracing/firebase/otel/firebaseInstrumentation.js.map +1 -0
  9. package/build/cjs/integrations/tracing/firebase/otel/patches/firestore.js +295 -0
  10. package/build/cjs/integrations/tracing/firebase/otel/patches/firestore.js.map +1 -0
  11. package/build/cjs/integrations/tracing/index.js +3 -0
  12. package/build/cjs/integrations/tracing/index.js.map +1 -1
  13. package/build/cjs/integrations/tracing/vercelai/instrumentation.js +15 -2
  14. package/build/cjs/integrations/tracing/vercelai/instrumentation.js.map +1 -1
  15. package/build/esm/index.js +1 -0
  16. package/build/esm/index.js.map +1 -1
  17. package/build/esm/integrations/tracing/fastify/index.js +57 -11
  18. package/build/esm/integrations/tracing/fastify/index.js.map +1 -1
  19. package/build/esm/integrations/tracing/firebase/firebase.js +29 -0
  20. package/build/esm/integrations/tracing/firebase/firebase.js.map +1 -0
  21. package/build/esm/integrations/tracing/firebase/otel/firebaseInstrumentation.js +39 -0
  22. package/build/esm/integrations/tracing/firebase/otel/firebaseInstrumentation.js.map +1 -0
  23. package/build/esm/integrations/tracing/firebase/otel/patches/firestore.js +292 -0
  24. package/build/esm/integrations/tracing/firebase/otel/patches/firestore.js.map +1 -0
  25. package/build/esm/integrations/tracing/index.js +3 -0
  26. package/build/esm/integrations/tracing/index.js.map +1 -1
  27. package/build/esm/integrations/tracing/vercelai/instrumentation.js +16 -3
  28. package/build/esm/integrations/tracing/vercelai/instrumentation.js.map +1 -1
  29. package/build/esm/package.json +1 -1
  30. package/build/types/index.d.ts +1 -0
  31. package/build/types/index.d.ts.map +1 -1
  32. package/build/types/integrations/tracing/fastify/index.d.ts +38 -2
  33. package/build/types/integrations/tracing/fastify/index.d.ts.map +1 -1
  34. package/build/types/integrations/tracing/firebase/firebase.d.ts +6 -0
  35. package/build/types/integrations/tracing/firebase/firebase.d.ts.map +1 -0
  36. package/build/types/integrations/tracing/firebase/index.d.ts +2 -0
  37. package/build/types/integrations/tracing/firebase/index.d.ts.map +1 -0
  38. package/build/types/integrations/tracing/firebase/otel/firebaseInstrumentation.d.ts +19 -0
  39. package/build/types/integrations/tracing/firebase/otel/firebaseInstrumentation.d.ts.map +1 -0
  40. package/build/types/integrations/tracing/firebase/otel/index.d.ts +3 -0
  41. package/build/types/integrations/tracing/firebase/otel/index.d.ts.map +1 -0
  42. package/build/types/integrations/tracing/firebase/otel/patches/firestore.d.ts +23 -0
  43. package/build/types/integrations/tracing/firebase/otel/patches/firestore.d.ts.map +1 -0
  44. package/build/types/integrations/tracing/firebase/otel/types.d.ts +86 -0
  45. package/build/types/integrations/tracing/firebase/otel/types.d.ts.map +1 -0
  46. package/build/types/integrations/tracing/index.d.ts.map +1 -1
  47. package/build/types/integrations/tracing/vercelai/instrumentation.d.ts.map +1 -1
  48. package/build/types-ts3.8/index.d.ts +1 -0
  49. package/build/types-ts3.8/integrations/tracing/fastify/index.d.ts +38 -2
  50. package/build/types-ts3.8/integrations/tracing/firebase/firebase.d.ts +6 -0
  51. package/build/types-ts3.8/integrations/tracing/firebase/index.d.ts +2 -0
  52. package/build/types-ts3.8/integrations/tracing/firebase/otel/firebaseInstrumentation.d.ts +19 -0
  53. package/build/types-ts3.8/integrations/tracing/firebase/otel/index.d.ts +3 -0
  54. package/build/types-ts3.8/integrations/tracing/firebase/otel/patches/firestore.d.ts +23 -0
  55. package/build/types-ts3.8/integrations/tracing/firebase/otel/types.d.ts +86 -0
  56. package/package.json +5 -5
@@ -0,0 +1 @@
1
+ {"version":3,"file":"firestore.js","sources":["../../../../../../../src/integrations/tracing/firebase/otel/patches/firestore.ts"],"sourcesContent":["import * as net from 'node:net';\nimport type { Span, Tracer } from '@opentelemetry/api';\nimport { context, diag, SpanKind, trace } from '@opentelemetry/api';\nimport {\n InstrumentationNodeModuleDefinition,\n InstrumentationNodeModuleFile,\n isWrapped,\n safeExecuteInTheMiddle,\n} from '@opentelemetry/instrumentation';\nimport {\n ATTR_DB_COLLECTION_NAME,\n ATTR_DB_NAMESPACE,\n ATTR_DB_OPERATION_NAME,\n ATTR_DB_SYSTEM_NAME,\n ATTR_SERVER_ADDRESS,\n ATTR_SERVER_PORT,\n} from '@opentelemetry/semantic-conventions';\nimport type { SpanAttributes } from '@sentry/core';\nimport type { unwrap as shimmerUnwrap, wrap as shimmerWrap } from 'shimmer';\nimport type { FirebaseInstrumentation } from '../firebaseInstrumentation';\nimport type {\n AddDocType,\n CollectionReference,\n DeleteDocType,\n DocumentData,\n DocumentReference,\n FirebaseApp,\n FirebaseInstrumentationConfig,\n FirebaseOptions,\n FirestoreSettings,\n FirestoreSpanCreationHook,\n GetDocsType,\n PartialWithFieldValue,\n QuerySnapshot,\n SetDocType,\n SetOptions,\n WithFieldValue,\n} from '../types';\n\n/**\n *\n * @param tracer - Opentelemetry Tracer\n * @param firestoreSupportedVersions - supported version of firebase/firestore\n * @param wrap - reference to native instrumentation wrap function\n * @param unwrap - reference to native instrumentation wrap function\n */\nexport function patchFirestore(\n tracer: Tracer,\n firestoreSupportedVersions: string[],\n wrap: typeof shimmerWrap,\n unwrap: typeof shimmerUnwrap,\n config: FirebaseInstrumentationConfig,\n): InstrumentationNodeModuleDefinition {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n const defaultFirestoreSpanCreationHook: FirestoreSpanCreationHook = () => {};\n\n let firestoreSpanCreationHook: FirestoreSpanCreationHook = defaultFirestoreSpanCreationHook;\n const configFirestoreSpanCreationHook = config.firestoreSpanCreationHook;\n\n if (typeof configFirestoreSpanCreationHook === 'function') {\n firestoreSpanCreationHook = (span: Span) => {\n safeExecuteInTheMiddle(\n () => configFirestoreSpanCreationHook(span),\n error => {\n if (!error) {\n return;\n }\n diag.error(error?.message);\n },\n true,\n );\n };\n }\n\n const moduleFirestoreCJS = new InstrumentationNodeModuleDefinition(\n '@firebase/firestore',\n firestoreSupportedVersions,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (moduleExports: any) => wrapMethods(moduleExports, wrap, unwrap, tracer, firestoreSpanCreationHook),\n );\n const files: string[] = [\n '@firebase/firestore/dist/lite/index.node.cjs.js',\n '@firebase/firestore/dist/lite/index.node.mjs.js',\n '@firebase/firestore/dist/lite/index.rn.esm2017.js',\n '@firebase/firestore/dist/lite/index.cjs.js',\n ];\n\n for (const file of files) {\n moduleFirestoreCJS.files.push(\n new InstrumentationNodeModuleFile(\n file,\n firestoreSupportedVersions,\n moduleExports => wrapMethods(moduleExports, wrap, unwrap, tracer, firestoreSpanCreationHook),\n moduleExports => unwrapMethods(moduleExports, unwrap),\n ),\n );\n }\n\n return moduleFirestoreCJS;\n}\n\nfunction wrapMethods(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n moduleExports: any,\n wrap: typeof shimmerWrap,\n unwrap: typeof shimmerUnwrap,\n tracer: Tracer,\n firestoreSpanCreationHook: FirestoreSpanCreationHook,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): any {\n unwrapMethods(moduleExports, unwrap);\n\n wrap(moduleExports, 'addDoc', patchAddDoc(tracer, firestoreSpanCreationHook));\n wrap(moduleExports, 'getDocs', patchGetDocs(tracer, firestoreSpanCreationHook));\n wrap(moduleExports, 'setDoc', patchSetDoc(tracer, firestoreSpanCreationHook));\n wrap(moduleExports, 'deleteDoc', patchDeleteDoc(tracer, firestoreSpanCreationHook));\n\n return moduleExports;\n}\n\nfunction unwrapMethods(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n moduleExports: any,\n unwrap: typeof shimmerUnwrap,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): any {\n for (const method of ['addDoc', 'getDocs', 'setDoc', 'deleteDoc']) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n if (isWrapped(moduleExports[method])) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n unwrap(moduleExports, method);\n }\n }\n return moduleExports;\n}\n\nfunction patchAddDoc<AppModelType, DbModelType extends DocumentData>(\n tracer: Tracer,\n firestoreSpanCreationHook: FirestoreSpanCreationHook,\n): (\n original: AddDocType<AppModelType, DbModelType>,\n) => (\n this: FirebaseInstrumentation,\n reference: CollectionReference<AppModelType, DbModelType>,\n data: WithFieldValue<AppModelType>,\n) => Promise<DocumentReference<AppModelType, DbModelType>> {\n return function addDoc(original: AddDocType<AppModelType, DbModelType>) {\n return function (\n reference: CollectionReference<AppModelType, DbModelType>,\n data: WithFieldValue<AppModelType>,\n ): Promise<DocumentReference<AppModelType, DbModelType>> {\n const span = startDBSpan(tracer, 'addDoc', reference);\n firestoreSpanCreationHook(span);\n return executeContextWithSpan<Promise<DocumentReference<AppModelType, DbModelType>>>(span, () => {\n return original(reference, data);\n });\n };\n };\n}\n\nfunction patchDeleteDoc<AppModelType, DbModelType extends DocumentData>(\n tracer: Tracer,\n firestoreSpanCreationHook: FirestoreSpanCreationHook,\n): (\n original: DeleteDocType<AppModelType, DbModelType>,\n) => (this: FirebaseInstrumentation, reference: DocumentReference<AppModelType, DbModelType>) => Promise<void> {\n return function deleteDoc(original: DeleteDocType<AppModelType, DbModelType>) {\n return function (reference: DocumentReference<AppModelType, DbModelType>): Promise<void> {\n const span = startDBSpan(tracer, 'deleteDoc', reference.parent || reference);\n firestoreSpanCreationHook(span);\n return executeContextWithSpan<Promise<void>>(span, () => {\n return original(reference);\n });\n };\n };\n}\n\nfunction patchGetDocs<AppModelType, DbModelType extends DocumentData>(\n tracer: Tracer,\n firestoreSpanCreationHook: FirestoreSpanCreationHook,\n): (\n original: GetDocsType<AppModelType, DbModelType>,\n) => (\n this: FirebaseInstrumentation,\n reference: CollectionReference<AppModelType, DbModelType>,\n) => Promise<QuerySnapshot<AppModelType, DbModelType>> {\n return function getDocs(original: GetDocsType<AppModelType, DbModelType>) {\n return function (\n reference: CollectionReference<AppModelType, DbModelType>,\n ): Promise<QuerySnapshot<AppModelType, DbModelType>> {\n const span = startDBSpan(tracer, 'getDocs', reference);\n firestoreSpanCreationHook(span);\n return executeContextWithSpan<Promise<QuerySnapshot<AppModelType, DbModelType>>>(span, () => {\n return original(reference);\n });\n };\n };\n}\n\nfunction patchSetDoc<AppModelType, DbModelType extends DocumentData>(\n tracer: Tracer,\n firestoreSpanCreationHook: FirestoreSpanCreationHook,\n): (\n original: SetDocType<AppModelType, DbModelType>,\n) => (\n this: FirebaseInstrumentation,\n reference: DocumentReference<AppModelType, DbModelType>,\n data: WithFieldValue<AppModelType> & PartialWithFieldValue<AppModelType>,\n options?: SetOptions,\n) => Promise<void> {\n return function setDoc(original: SetDocType<AppModelType, DbModelType>) {\n return function (\n reference: DocumentReference<AppModelType, DbModelType>,\n data: WithFieldValue<AppModelType> & PartialWithFieldValue<AppModelType>,\n options?: SetOptions,\n ): Promise<void> {\n const span = startDBSpan(tracer, 'setDoc', reference.parent || reference);\n firestoreSpanCreationHook(span);\n\n return executeContextWithSpan<Promise<void>>(span, () => {\n return typeof options !== 'undefined' ? original(reference, data, options) : original(reference, data);\n });\n };\n };\n}\n\nfunction executeContextWithSpan<T>(span: Span, callback: () => T): T {\n return context.with(trace.setSpan(context.active(), span), () => {\n return safeExecuteInTheMiddle(\n (): T => {\n return callback();\n },\n err => {\n if (err) {\n span.recordException(err);\n }\n span.end();\n },\n true,\n );\n });\n}\n\nfunction startDBSpan<AppModelType, DbModelType extends DocumentData>(\n tracer: Tracer,\n spanName: string,\n reference: CollectionReference<AppModelType, DbModelType> | DocumentReference<AppModelType, DbModelType>,\n): Span {\n const span = tracer.startSpan(`${spanName} ${reference.path}`, { kind: SpanKind.CLIENT });\n addAttributes(span, reference);\n span.setAttribute(ATTR_DB_OPERATION_NAME, spanName);\n return span;\n}\n\n/**\n * Gets the server address and port attributes from the Firestore settings.\n * It's best effort to extract the address and port from the settings, especially for IPv6.\n * @param span - The span to set attributes on.\n * @param settings - The Firestore settings containing host information.\n */\nexport function getPortAndAddress(settings: FirestoreSettings): {\n address?: string;\n port?: number;\n} {\n let address: string | undefined;\n let port: string | undefined;\n\n if (typeof settings.host === 'string') {\n if (settings.host.startsWith('[')) {\n // IPv6 addresses can be enclosed in square brackets, e.g., [2001:db8::1]:8080\n if (settings.host.endsWith(']')) {\n // IPv6 with square brackets without port\n address = settings.host.replace(/^\\[|\\]$/g, '');\n } else if (settings.host.includes(']:')) {\n // IPv6 with square brackets with port\n const lastColonIndex = settings.host.lastIndexOf(':');\n if (lastColonIndex !== -1) {\n address = settings.host.slice(1, lastColonIndex).replace(/^\\[|\\]$/g, '');\n port = settings.host.slice(lastColonIndex + 1);\n }\n }\n } else {\n // IPv4 or IPv6 without square brackets\n // If it's an IPv6 address without square brackets, we assume it does not have a port.\n if (net.isIPv6(settings.host)) {\n address = settings.host;\n }\n // If it's an IPv4 address, we can extract the port if it exists.\n else {\n const lastColonIndex = settings.host.lastIndexOf(':');\n if (lastColonIndex !== -1) {\n address = settings.host.slice(0, lastColonIndex);\n port = settings.host.slice(lastColonIndex + 1);\n } else {\n address = settings.host;\n }\n }\n }\n }\n return {\n address: address,\n port: port ? parseInt(port, 10) : undefined,\n };\n}\n\nfunction addAttributes<AppModelType, DbModelType extends DocumentData>(\n span: Span,\n reference: CollectionReference<AppModelType, DbModelType> | DocumentReference<AppModelType, DbModelType>,\n): void {\n const firestoreApp: FirebaseApp = reference.firestore.app;\n const firestoreOptions: FirebaseOptions = firestoreApp.options;\n const json: { settings?: FirestoreSettings } = reference.firestore.toJSON() || {};\n const settings: FirestoreSettings = json.settings || {};\n\n const attributes: SpanAttributes = {\n [ATTR_DB_COLLECTION_NAME]: reference.path,\n [ATTR_DB_NAMESPACE]: firestoreApp.name,\n [ATTR_DB_SYSTEM_NAME]: 'firebase.firestore',\n 'firebase.firestore.type': reference.type,\n 'firebase.firestore.options.projectId': firestoreOptions.projectId,\n 'firebase.firestore.options.appId': firestoreOptions.appId,\n 'firebase.firestore.options.messagingSenderId': firestoreOptions.messagingSenderId,\n 'firebase.firestore.options.storageBucket': firestoreOptions.storageBucket,\n };\n\n const { address, port } = getPortAndAddress(settings);\n\n if (address) {\n attributes[ATTR_SERVER_ADDRESS] = address;\n }\n if (port) {\n attributes[ATTR_SERVER_PORT] = port;\n }\n\n span.setAttributes(attributes);\n}\n"],"names":["safeExecuteInTheMiddle","diag","InstrumentationNodeModuleDefinition","InstrumentationNodeModuleFile","isWrapped","context","trace","SpanKind","ATTR_DB_OPERATION_NAME","ATTR_DB_COLLECTION_NAME","ATTR_DB_NAMESPACE","ATTR_DB_SYSTEM_NAME","ATTR_SERVER_ADDRESS","ATTR_SERVER_PORT"],"mappings":";;;;;;;AAuCA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,cAAc;AAC9B,EAAE,MAAM;AACR,EAAE,0BAA0B;AAC5B,EAAE,IAAI;AACN,EAAE,MAAM;AACR,EAAE,MAAM;AACR,EAAuC;AACvC;AACA,EAAE,MAAM,gCAAgC,GAA8B,MAAM,EAAE;;AAE9E,EAAE,IAAI,yBAAyB,GAA8B,gCAAgC;AAC7F,EAAE,MAAM,+BAAA,GAAkC,MAAM,CAAC,yBAAyB;;AAE1E,EAAE,IAAI,OAAO,+BAAA,KAAoC,UAAU,EAAE;AAC7D,IAAI,yBAAA,GAA4B,CAAC,IAAI,KAAW;AAChD,MAAMA,sCAAsB;AAC5B,QAAQ,MAAM,+BAA+B,CAAC,IAAI,CAAC;AACnD,QAAQ,SAAS;AACjB,UAAU,IAAI,CAAC,KAAK,EAAE;AACtB,YAAY;AACZ;AACA,UAAUC,QAAI,CAAC,KAAK,CAAC,KAAK,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,GAAA,YAAA,CAAA,OAAA;AACA,EAAA,MAAA,IAAA,GAAA,SAAA,CAAA,SAAA,CAAA,MAAA,EAAA,IAAA,EAAA;AACA,EAAA,MAAA,QAAA,GAAA,IAAA,CAAA,QAAA,IAAA,EAAA;;AAEA,EAAA,MAAA,UAAA,GAAA;AACA,IAAA,CAAAC,2CAAA,GAAA,SAAA,CAAA,IAAA;AACA,IAAA,CAAAC,qCAAA,GAAA,YAAA,CAAA,IAAA;AACA,IAAA,CAAAC,uCAAA,GAAA,oBAAA;AACA,IAAA,yBAAA,EAAA,SAAA,CAAA,IAAA;AACA,IAAA,sCAAA,EAAA,gBAAA,CAAA,SAAA;AACA,IAAA,kCAAA,EAAA,gBAAA,CAAA,KAAA;AACA,IAAA,8CAAA,EAAA,gBAAA,CAAA,iBAAA;AACA,IAAA,0CAAA,EAAA,gBAAA,CAAA,aAAA;AACA,GAAA;;AAEA,EAAA,MAAA,EAAA,OAAA,EAAA,IAAA,EAAA,GAAA,iBAAA,CAAA,QAAA,CAAA;;AAEA,EAAA,IAAA,OAAA,EAAA;AACA,IAAA,UAAA,CAAAC,uCAAA,CAAA,GAAA,OAAA;AACA;AACA,EAAA,IAAA,IAAA,EAAA;AACA,IAAA,UAAA,CAAAC,oCAAA,CAAA,GAAA,IAAA;AACA;;AAEA,EAAA,IAAA,CAAA,aAAA,CAAA,UAAA,CAAA;AACA;;;;;"}
@@ -5,6 +5,7 @@ const amqplib = require('./amqplib.js');
5
5
  const connect = require('./connect.js');
6
6
  const express = require('./express.js');
7
7
  const index$1 = require('./fastify/index.js');
8
+ const firebase = require('./firebase/firebase.js');
8
9
  const genericPool = require('./genericPool.js');
9
10
  const graphql = require('./graphql.js');
10
11
  const index$2 = require('./hapi/index.js');
@@ -49,6 +50,7 @@ function getAutoPerformanceIntegrations() {
49
50
  index$3.vercelAIIntegration(),
50
51
  index$4.openAIIntegration(),
51
52
  postgresjs.postgresJsIntegration(),
53
+ firebase.firebaseIntegration(),
52
54
  ];
53
55
  }
54
56
 
@@ -81,6 +83,7 @@ function getOpenTelemetryInstrumentationToPreload() {
81
83
  index$3.instrumentVercelAi,
82
84
  index$4.instrumentOpenAi,
83
85
  postgresjs.instrumentPostgresJs,
86
+ firebase.instrumentFirebase,
84
87
  ];
85
88
  }
86
89
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../../src/integrations/tracing/index.ts"],"sourcesContent":["import type { Integration } from '@sentry/core';\nimport { instrumentOtelHttp } from '../http';\nimport { amqplibIntegration, instrumentAmqplib } from './amqplib';\nimport { connectIntegration, instrumentConnect } from './connect';\nimport { expressIntegration, instrumentExpress } from './express';\nimport { fastifyIntegration, instrumentFastify, instrumentFastifyV3 } from './fastify';\nimport { genericPoolIntegration, instrumentGenericPool } from './genericPool';\nimport { graphqlIntegration, instrumentGraphql } from './graphql';\nimport { hapiIntegration, instrumentHapi } from './hapi';\nimport { instrumentKafka, kafkaIntegration } from './kafka';\nimport { instrumentKoa, koaIntegration } from './koa';\nimport { instrumentLruMemoizer, lruMemoizerIntegration } from './lrumemoizer';\nimport { instrumentMongo, mongoIntegration } from './mongo';\nimport { instrumentMongoose, mongooseIntegration } from './mongoose';\nimport { instrumentMysql, mysqlIntegration } from './mysql';\nimport { instrumentMysql2, mysql2Integration } from './mysql2';\nimport { instrumentOpenAi, openAIIntegration } from './openai';\nimport { instrumentPostgres, postgresIntegration } from './postgres';\nimport { instrumentPostgresJs, postgresJsIntegration } from './postgresjs';\nimport { prismaIntegration } from './prisma';\nimport { instrumentRedis, redisIntegration } from './redis';\nimport { instrumentTedious, tediousIntegration } from './tedious';\nimport { instrumentVercelAi, vercelAIIntegration } from './vercelai';\n\n/**\n * With OTEL, all performance integrations will be added, as OTEL only initializes them when the patched package is actually required.\n */\nexport function getAutoPerformanceIntegrations(): Integration[] {\n return [\n expressIntegration(),\n fastifyIntegration(),\n graphqlIntegration(),\n mongoIntegration(),\n mongooseIntegration(),\n mysqlIntegration(),\n mysql2Integration(),\n redisIntegration(),\n postgresIntegration(),\n prismaIntegration(),\n hapiIntegration(),\n koaIntegration(),\n connectIntegration(),\n tediousIntegration(),\n genericPoolIntegration(),\n kafkaIntegration(),\n amqplibIntegration(),\n lruMemoizerIntegration(),\n vercelAIIntegration(),\n openAIIntegration(),\n postgresJsIntegration(),\n ];\n}\n\n/**\n * Get a list of methods to instrument OTEL, when preload instrumentation.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function getOpenTelemetryInstrumentationToPreload(): (((options?: any) => void) & { id: string })[] {\n return [\n instrumentOtelHttp,\n instrumentExpress,\n instrumentConnect,\n instrumentFastify,\n instrumentFastifyV3,\n instrumentHapi,\n instrumentKafka,\n instrumentKoa,\n instrumentLruMemoizer,\n instrumentMongo,\n instrumentMongoose,\n instrumentMysql,\n instrumentMysql2,\n instrumentPostgres,\n instrumentHapi,\n instrumentGraphql,\n instrumentRedis,\n instrumentTedious,\n instrumentGenericPool,\n instrumentAmqplib,\n instrumentVercelAi,\n instrumentOpenAi,\n instrumentPostgresJs,\n ];\n}\n"],"names":["expressIntegration","fastifyIntegration","graphqlIntegration","mongoIntegration","mongooseIntegration","mysqlIntegration","mysql2Integration","redisIntegration","postgresIntegration","prismaIntegration","hapiIntegration","koaIntegration","connectIntegration","tediousIntegration","genericPoolIntegration","kafkaIntegration","amqplibIntegration","lruMemoizerIntegration","vercelAIIntegration","openAIIntegration","postgresJsIntegration","instrumentOtelHttp","instrumentExpress","instrumentConnect","instrumentFastify","instrumentFastifyV3","instrumentHapi","instrumentKafka","instrumentKoa","instrumentLruMemoizer","instrumentMongo","instrumentMongoose","instrumentMysql","instrumentMysql2","instrumentPostgres","instrumentGraphql","instrumentRedis","instrumentTedious","instrumentGenericPool","instrumentAmqplib","instrumentVercelAi","instrumentOpenAi","instrumentPostgresJs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAwBA;AACA;AACA;AACO,SAAS,8BAA8B,GAAkB;AAChE,EAAE,OAAO;AACT,IAAIA,0BAAkB,EAAE;AACxB,IAAIC,0BAAkB,EAAE;AACxB,IAAIC,0BAAkB,EAAE;AACxB,IAAIC,sBAAgB,EAAE;AACtB,IAAIC,4BAAmB,EAAE;AACzB,IAAIC,sBAAgB,EAAE;AACtB,IAAIC,wBAAiB,EAAE;AACvB,IAAIC,sBAAgB,EAAE;AACtB,IAAIC,4BAAmB,EAAE;AACzB,IAAIC,wBAAiB,EAAE;AACvB,IAAIC,uBAAe,EAAE;AACrB,IAAIC,kBAAc,EAAE;AACpB,IAAIC,0BAAkB,EAAE;AACxB,IAAIC,0BAAkB,EAAE;AACxB,IAAIC,kCAAsB,EAAE;AAC5B,IAAIC,sBAAgB,EAAE;AACtB,IAAIC,0BAAkB,EAAE;AACxB,IAAIC,kCAAsB,EAAE;AAC5B,IAAIC,2BAAmB,EAAE;AACzB,IAAIC,yBAAiB,EAAE;AACvB,IAAIC,gCAAqB,EAAE;AAC3B,GAAG;AACH;;AAEA;AACA;AACA;AACA;AACO,SAAS,wCAAwC,GAAmD;AAC3G,EAAE,OAAO;AACT,IAAIC,wBAAkB;AACtB,IAAIC,yBAAiB;AACrB,IAAIC,yBAAiB;AACrB,IAAIC,yBAAiB;AACrB,IAAIC,2BAAmB;AACvB,IAAIC,sBAAc;AAClB,IAAIC,qBAAe;AACnB,IAAIC,iBAAa;AACjB,IAAIC,iCAAqB;AACzB,IAAIC,qBAAe;AACnB,IAAIC,2BAAkB;AACtB,IAAIC,qBAAe;AACnB,IAAIC,uBAAgB;AACpB,IAAIC,2BAAkB;AACtB,IAAIR,sBAAc;AAClB,IAAIS,yBAAiB;AACrB,IAAIC,qBAAe;AACnB,IAAIC,yBAAiB;AACrB,IAAIC,iCAAqB;AACzB,IAAIC,yBAAiB;AACrB,IAAIC,0BAAkB;AACtB,IAAIC,wBAAgB;AACpB,IAAIC,+BAAoB;AACxB,GAAG;AACH;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../../src/integrations/tracing/index.ts"],"sourcesContent":["import type { Integration } from '@sentry/core';\nimport { instrumentOtelHttp } from '../http';\nimport { amqplibIntegration, instrumentAmqplib } from './amqplib';\nimport { connectIntegration, instrumentConnect } from './connect';\nimport { expressIntegration, instrumentExpress } from './express';\nimport { fastifyIntegration, instrumentFastify, instrumentFastifyV3 } from './fastify';\nimport { firebaseIntegration, instrumentFirebase } from './firebase';\nimport { genericPoolIntegration, instrumentGenericPool } from './genericPool';\nimport { graphqlIntegration, instrumentGraphql } from './graphql';\nimport { hapiIntegration, instrumentHapi } from './hapi';\nimport { instrumentKafka, kafkaIntegration } from './kafka';\nimport { instrumentKoa, koaIntegration } from './koa';\nimport { instrumentLruMemoizer, lruMemoizerIntegration } from './lrumemoizer';\nimport { instrumentMongo, mongoIntegration } from './mongo';\nimport { instrumentMongoose, mongooseIntegration } from './mongoose';\nimport { instrumentMysql, mysqlIntegration } from './mysql';\nimport { instrumentMysql2, mysql2Integration } from './mysql2';\nimport { instrumentOpenAi, openAIIntegration } from './openai';\nimport { instrumentPostgres, postgresIntegration } from './postgres';\nimport { instrumentPostgresJs, postgresJsIntegration } from './postgresjs';\nimport { prismaIntegration } from './prisma';\nimport { instrumentRedis, redisIntegration } from './redis';\nimport { instrumentTedious, tediousIntegration } from './tedious';\nimport { instrumentVercelAi, vercelAIIntegration } from './vercelai';\n\n/**\n * With OTEL, all performance integrations will be added, as OTEL only initializes them when the patched package is actually required.\n */\nexport function getAutoPerformanceIntegrations(): Integration[] {\n return [\n expressIntegration(),\n fastifyIntegration(),\n graphqlIntegration(),\n mongoIntegration(),\n mongooseIntegration(),\n mysqlIntegration(),\n mysql2Integration(),\n redisIntegration(),\n postgresIntegration(),\n prismaIntegration(),\n hapiIntegration(),\n koaIntegration(),\n connectIntegration(),\n tediousIntegration(),\n genericPoolIntegration(),\n kafkaIntegration(),\n amqplibIntegration(),\n lruMemoizerIntegration(),\n vercelAIIntegration(),\n openAIIntegration(),\n postgresJsIntegration(),\n firebaseIntegration(),\n ];\n}\n\n/**\n * Get a list of methods to instrument OTEL, when preload instrumentation.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function getOpenTelemetryInstrumentationToPreload(): (((options?: any) => void) & { id: string })[] {\n return [\n instrumentOtelHttp,\n instrumentExpress,\n instrumentConnect,\n instrumentFastify,\n instrumentFastifyV3,\n instrumentHapi,\n instrumentKafka,\n instrumentKoa,\n instrumentLruMemoizer,\n instrumentMongo,\n instrumentMongoose,\n instrumentMysql,\n instrumentMysql2,\n instrumentPostgres,\n instrumentHapi,\n instrumentGraphql,\n instrumentRedis,\n instrumentTedious,\n instrumentGenericPool,\n instrumentAmqplib,\n instrumentVercelAi,\n instrumentOpenAi,\n instrumentPostgresJs,\n instrumentFirebase,\n ];\n}\n"],"names":["expressIntegration","fastifyIntegration","graphqlIntegration","mongoIntegration","mongooseIntegration","mysqlIntegration","mysql2Integration","redisIntegration","postgresIntegration","prismaIntegration","hapiIntegration","koaIntegration","connectIntegration","tediousIntegration","genericPoolIntegration","kafkaIntegration","amqplibIntegration","lruMemoizerIntegration","vercelAIIntegration","openAIIntegration","postgresJsIntegration","firebaseIntegration","instrumentOtelHttp","instrumentExpress","instrumentConnect","instrumentFastify","instrumentFastifyV3","instrumentHapi","instrumentKafka","instrumentKoa","instrumentLruMemoizer","instrumentMongo","instrumentMongoose","instrumentMysql","instrumentMysql2","instrumentPostgres","instrumentGraphql","instrumentRedis","instrumentTedious","instrumentGenericPool","instrumentAmqplib","instrumentVercelAi","instrumentOpenAi","instrumentPostgresJs","instrumentFirebase"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA;AACA;AACA;AACO,SAAS,8BAA8B,GAAkB;AAChE,EAAE,OAAO;AACT,IAAIA,0BAAkB,EAAE;AACxB,IAAIC,0BAAkB,EAAE;AACxB,IAAIC,0BAAkB,EAAE;AACxB,IAAIC,sBAAgB,EAAE;AACtB,IAAIC,4BAAmB,EAAE;AACzB,IAAIC,sBAAgB,EAAE;AACtB,IAAIC,wBAAiB,EAAE;AACvB,IAAIC,sBAAgB,EAAE;AACtB,IAAIC,4BAAmB,EAAE;AACzB,IAAIC,wBAAiB,EAAE;AACvB,IAAIC,uBAAe,EAAE;AACrB,IAAIC,kBAAc,EAAE;AACpB,IAAIC,0BAAkB,EAAE;AACxB,IAAIC,0BAAkB,EAAE;AACxB,IAAIC,kCAAsB,EAAE;AAC5B,IAAIC,sBAAgB,EAAE;AACtB,IAAIC,0BAAkB,EAAE;AACxB,IAAIC,kCAAsB,EAAE;AAC5B,IAAIC,2BAAmB,EAAE;AACzB,IAAIC,yBAAiB,EAAE;AACvB,IAAIC,gCAAqB,EAAE;AAC3B,IAAIC,4BAAmB,EAAE;AACzB,GAAG;AACH;;AAEA;AACA;AACA;AACA;AACO,SAAS,wCAAwC,GAAmD;AAC3G,EAAE,OAAO;AACT,IAAIC,wBAAkB;AACtB,IAAIC,yBAAiB;AACrB,IAAIC,yBAAiB;AACrB,IAAIC,yBAAiB;AACrB,IAAIC,2BAAmB;AACvB,IAAIC,sBAAc;AAClB,IAAIC,qBAAe;AACnB,IAAIC,iBAAa;AACjB,IAAIC,iCAAqB;AACzB,IAAIC,qBAAe;AACnB,IAAIC,2BAAkB;AACtB,IAAIC,qBAAe;AACnB,IAAIC,uBAAgB;AACpB,IAAIC,2BAAkB;AACtB,IAAIR,sBAAc;AAClB,IAAIS,yBAAiB;AACrB,IAAIC,qBAAe;AACnB,IAAIC,yBAAiB;AACrB,IAAIC,iCAAqB;AACzB,IAAIC,yBAAiB;AACrB,IAAIC,0BAAkB;AACtB,IAAIC,wBAAgB;AACpB,IAAIC,+BAAoB;AACxB,IAAIC,2BAAkB;AACtB,GAAG;AACH;;;;;"}
@@ -117,8 +117,21 @@ class SentryVercelAiInstrumentation extends instrumentation.InstrumentationBase
117
117
  recordOutputs,
118
118
  };
119
119
 
120
- // @ts-expect-error we know that the method exists
121
- return originalMethod.apply(this, args);
120
+ return core.handleCallbackErrors(
121
+ () => {
122
+ // @ts-expect-error we know that the method exists
123
+ return originalMethod.apply(this, args);
124
+ },
125
+ error => {
126
+ // This error bubbles up to unhandledrejection handler (if not handled before),
127
+ // where we do not know the active span anymore
128
+ // So to circumvent this, we set the active span on the error object
129
+ // which is picked up by the unhandledrejection handler
130
+ if (error && typeof error === 'object') {
131
+ core.addNonEnumerableProperty(error, '_sentry_active_span', core.getActiveSpan());
132
+ }
133
+ },
134
+ );
122
135
  };
123
136
  }
124
137
 
@@ -1 +1 @@
1
- {"version":3,"file":"instrumentation.js","sources":["../../../../../src/integrations/tracing/vercelai/instrumentation.ts"],"sourcesContent":["import type { InstrumentationConfig, InstrumentationModuleDefinition } from '@opentelemetry/instrumentation';\nimport { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';\nimport { getCurrentScope, SDK_VERSION } from '@sentry/core';\nimport { INTEGRATION_NAME } from './constants';\nimport type { TelemetrySettings, VercelAiIntegration } from './types';\n\n// List of patched methods\n// From: https://sdk.vercel.ai/docs/ai-sdk-core/telemetry#collected-data\nconst INSTRUMENTED_METHODS = [\n 'generateText',\n 'streamText',\n 'generateObject',\n 'streamObject',\n 'embed',\n 'embedMany',\n] as const;\n\ninterface MethodFirstArg extends Record<string, unknown> {\n experimental_telemetry?: TelemetrySettings;\n}\n\ntype MethodArgs = [MethodFirstArg, ...unknown[]];\n\ntype PatchedModuleExports = Record<(typeof INSTRUMENTED_METHODS)[number], (...args: MethodArgs) => unknown> &\n Record<string, unknown>;\n\ninterface RecordingOptions {\n recordInputs?: boolean;\n recordOutputs?: boolean;\n}\n\n/**\n * Determines whether to record inputs and outputs for Vercel AI telemetry based on the configuration hierarchy.\n *\n * The order of precedence is:\n * 1. The vercel ai integration options\n * 2. The experimental_telemetry options in the vercel ai method calls\n * 3. When telemetry is explicitly enabled (isEnabled: true), default to recording\n * 4. Otherwise, use the sendDefaultPii option from client options\n */\nexport function determineRecordingSettings(\n integrationRecordingOptions: RecordingOptions | undefined,\n methodTelemetryOptions: RecordingOptions,\n telemetryExplicitlyEnabled: boolean | undefined,\n defaultRecordingEnabled: boolean,\n): { recordInputs: boolean; recordOutputs: boolean } {\n const recordInputs =\n integrationRecordingOptions?.recordInputs !== undefined\n ? integrationRecordingOptions.recordInputs\n : methodTelemetryOptions.recordInputs !== undefined\n ? methodTelemetryOptions.recordInputs\n : telemetryExplicitlyEnabled === true\n ? true // When telemetry is explicitly enabled, default to recording inputs\n : defaultRecordingEnabled;\n\n const recordOutputs =\n integrationRecordingOptions?.recordOutputs !== undefined\n ? integrationRecordingOptions.recordOutputs\n : methodTelemetryOptions.recordOutputs !== undefined\n ? methodTelemetryOptions.recordOutputs\n : telemetryExplicitlyEnabled === true\n ? true // When telemetry is explicitly enabled, default to recording inputs\n : defaultRecordingEnabled;\n\n return { recordInputs, recordOutputs };\n}\n\n/**\n * This detects is added by the Sentry Vercel AI Integration to detect if the integration should\n * be enabled.\n *\n * It also patches the `ai` module to enable Vercel AI telemetry automatically for all methods.\n */\nexport class SentryVercelAiInstrumentation extends InstrumentationBase {\n private _isPatched = false;\n private _callbacks: (() => void)[] = [];\n\n public constructor(config: InstrumentationConfig = {}) {\n super('@sentry/instrumentation-vercel-ai', SDK_VERSION, config);\n }\n\n /**\n * Initializes the instrumentation by defining the modules to be patched.\n */\n public init(): InstrumentationModuleDefinition {\n const module = new InstrumentationNodeModuleDefinition('ai', ['>=3.0.0 <5'], this._patch.bind(this));\n return module;\n }\n\n /**\n * Call the provided callback when the module is patched.\n * If it has already been patched, the callback will be called immediately.\n */\n public callWhenPatched(callback: () => void): void {\n if (this._isPatched) {\n callback();\n } else {\n this._callbacks.push(callback);\n }\n }\n\n /**\n * Patches module exports to enable Vercel AI telemetry.\n */\n private _patch(moduleExports: PatchedModuleExports): unknown {\n this._isPatched = true;\n\n this._callbacks.forEach(callback => callback());\n this._callbacks = [];\n\n function generatePatch(originalMethod: (...args: MethodArgs) => unknown) {\n return (...args: MethodArgs) => {\n const existingExperimentalTelemetry = args[0].experimental_telemetry || {};\n const isEnabled = existingExperimentalTelemetry.isEnabled;\n\n const client = getCurrentScope().getClient();\n const integration = client?.getIntegrationByName<VercelAiIntegration>(INTEGRATION_NAME);\n const integrationOptions = integration?.options;\n const shouldRecordInputsAndOutputs = integration ? Boolean(client?.getOptions().sendDefaultPii) : false;\n\n const { recordInputs, recordOutputs } = determineRecordingSettings(\n integrationOptions,\n existingExperimentalTelemetry,\n isEnabled,\n shouldRecordInputsAndOutputs,\n );\n\n args[0].experimental_telemetry = {\n ...existingExperimentalTelemetry,\n isEnabled: isEnabled !== undefined ? isEnabled : true,\n recordInputs,\n recordOutputs,\n };\n\n // @ts-expect-error we know that the method exists\n return originalMethod.apply(this, args);\n };\n }\n\n // Is this an ESM module?\n // https://tc39.es/ecma262/#sec-module-namespace-objects\n if (Object.prototype.toString.call(moduleExports) === '[object Module]') {\n // In ESM we take the usual route and just replace the exports we want to instrument\n for (const method of INSTRUMENTED_METHODS) {\n moduleExports[method] = generatePatch(moduleExports[method]);\n }\n\n return moduleExports;\n } else {\n // In CJS we can't replace the exports in the original module because they\n // don't have setters, so we create a new object with the same properties\n const patchedModuleExports = INSTRUMENTED_METHODS.reduce((acc, curr) => {\n acc[curr] = generatePatch(moduleExports[curr]);\n return acc;\n }, {} as PatchedModuleExports);\n\n return { ...moduleExports, ...patchedModuleExports };\n }\n }\n}\n"],"names":["InstrumentationBase","SDK_VERSION","InstrumentationNodeModuleDefinition","getCurrentScope","INTEGRATION_NAME"],"mappings":";;;;;;AAMA;AACA;AACA,MAAM,uBAAuB;AAC7B,EAAE,cAAc;AAChB,EAAE,YAAY;AACd,EAAE,gBAAgB;AAClB,EAAE,cAAc;AAChB,EAAE,OAAO;AACT,EAAE,WAAW;AACb,CAAA;;AAgBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,0BAA0B;AAC1C,EAAE,2BAA2B;AAC7B,EAAE,sBAAsB;AACxB,EAAE,0BAA0B;AAC5B,EAAE,uBAAuB;AACzB,EAAqD;AACrD,EAAE,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,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC;AAC/C,OAAO;AACP;;AAEA;AACA;AACA,IAAI,IAAI,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAA,KAAM,iBAAiB,EAAE;AAC7E;AACA,MAAM,KAAK,MAAM,MAAA,IAAU,oBAAoB,EAAE;AACjD,QAAQ,aAAa,CAAC,MAAM,CAAA,GAAI,aAAa,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;AACpE;;AAEA,MAAM,OAAO,aAAa;AAC1B,WAAW;AACX;AACA;AACA,MAAM,MAAM,oBAAA,GAAuB,oBAAoB,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,KAAK;AAC9E,QAAQ,GAAG,CAAC,IAAI,CAAA,GAAI,aAAa,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;AACtD,QAAQ,OAAO,GAAG;AAClB,OAAO,EAAE,EAAC,EAA0B;;AAEpC,MAAM,OAAO,EAAE,GAAG,aAAa,EAAE,GAAG,sBAAsB;AAC1D;AACA;AACA;;;;;"}
1
+ {"version":3,"file":"instrumentation.js","sources":["../../../../../src/integrations/tracing/vercelai/instrumentation.ts"],"sourcesContent":["import type { InstrumentationConfig, InstrumentationModuleDefinition } from '@opentelemetry/instrumentation';\nimport { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';\nimport {\n addNonEnumerableProperty,\n getActiveSpan,\n getCurrentScope,\n handleCallbackErrors,\n SDK_VERSION,\n} from '@sentry/core';\nimport { INTEGRATION_NAME } from './constants';\nimport type { TelemetrySettings, VercelAiIntegration } from './types';\n\n// List of patched methods\n// From: https://sdk.vercel.ai/docs/ai-sdk-core/telemetry#collected-data\nconst INSTRUMENTED_METHODS = [\n 'generateText',\n 'streamText',\n 'generateObject',\n 'streamObject',\n 'embed',\n 'embedMany',\n] as const;\n\ninterface MethodFirstArg extends Record<string, unknown> {\n experimental_telemetry?: TelemetrySettings;\n}\n\ntype MethodArgs = [MethodFirstArg, ...unknown[]];\n\ntype PatchedModuleExports = Record<(typeof INSTRUMENTED_METHODS)[number], (...args: MethodArgs) => unknown> &\n Record<string, unknown>;\n\ninterface RecordingOptions {\n recordInputs?: boolean;\n recordOutputs?: boolean;\n}\n\n/**\n * Determines whether to record inputs and outputs for Vercel AI telemetry based on the configuration hierarchy.\n *\n * The order of precedence is:\n * 1. The vercel ai integration options\n * 2. The experimental_telemetry options in the vercel ai method calls\n * 3. When telemetry is explicitly enabled (isEnabled: true), default to recording\n * 4. Otherwise, use the sendDefaultPii option from client options\n */\nexport function determineRecordingSettings(\n integrationRecordingOptions: RecordingOptions | undefined,\n methodTelemetryOptions: RecordingOptions,\n telemetryExplicitlyEnabled: boolean | undefined,\n defaultRecordingEnabled: boolean,\n): { recordInputs: boolean; recordOutputs: boolean } {\n const recordInputs =\n integrationRecordingOptions?.recordInputs !== undefined\n ? integrationRecordingOptions.recordInputs\n : methodTelemetryOptions.recordInputs !== undefined\n ? methodTelemetryOptions.recordInputs\n : telemetryExplicitlyEnabled === true\n ? true // When telemetry is explicitly enabled, default to recording inputs\n : defaultRecordingEnabled;\n\n const recordOutputs =\n integrationRecordingOptions?.recordOutputs !== undefined\n ? integrationRecordingOptions.recordOutputs\n : methodTelemetryOptions.recordOutputs !== undefined\n ? methodTelemetryOptions.recordOutputs\n : telemetryExplicitlyEnabled === true\n ? true // When telemetry is explicitly enabled, default to recording inputs\n : defaultRecordingEnabled;\n\n return { recordInputs, recordOutputs };\n}\n\n/**\n * This detects is added by the Sentry Vercel AI Integration to detect if the integration should\n * be enabled.\n *\n * It also patches the `ai` module to enable Vercel AI telemetry automatically for all methods.\n */\nexport class SentryVercelAiInstrumentation extends InstrumentationBase {\n private _isPatched = false;\n private _callbacks: (() => void)[] = [];\n\n public constructor(config: InstrumentationConfig = {}) {\n super('@sentry/instrumentation-vercel-ai', SDK_VERSION, config);\n }\n\n /**\n * Initializes the instrumentation by defining the modules to be patched.\n */\n public init(): InstrumentationModuleDefinition {\n const module = new InstrumentationNodeModuleDefinition('ai', ['>=3.0.0 <5'], this._patch.bind(this));\n return module;\n }\n\n /**\n * Call the provided callback when the module is patched.\n * If it has already been patched, the callback will be called immediately.\n */\n public callWhenPatched(callback: () => void): void {\n if (this._isPatched) {\n callback();\n } else {\n this._callbacks.push(callback);\n }\n }\n\n /**\n * Patches module exports to enable Vercel AI telemetry.\n */\n private _patch(moduleExports: PatchedModuleExports): unknown {\n this._isPatched = true;\n\n this._callbacks.forEach(callback => callback());\n this._callbacks = [];\n\n function generatePatch(originalMethod: (...args: MethodArgs) => unknown) {\n return (...args: MethodArgs) => {\n const existingExperimentalTelemetry = args[0].experimental_telemetry || {};\n const isEnabled = existingExperimentalTelemetry.isEnabled;\n\n const client = getCurrentScope().getClient();\n const integration = client?.getIntegrationByName<VercelAiIntegration>(INTEGRATION_NAME);\n const integrationOptions = integration?.options;\n const shouldRecordInputsAndOutputs = integration ? Boolean(client?.getOptions().sendDefaultPii) : false;\n\n const { recordInputs, recordOutputs } = determineRecordingSettings(\n integrationOptions,\n existingExperimentalTelemetry,\n isEnabled,\n shouldRecordInputsAndOutputs,\n );\n\n args[0].experimental_telemetry = {\n ...existingExperimentalTelemetry,\n isEnabled: isEnabled !== undefined ? isEnabled : true,\n recordInputs,\n recordOutputs,\n };\n\n return handleCallbackErrors(\n () => {\n // @ts-expect-error we know that the method exists\n return originalMethod.apply(this, args);\n },\n error => {\n // This error bubbles up to unhandledrejection handler (if not handled before),\n // where we do not know the active span anymore\n // So to circumvent this, we set the active span on the error object\n // which is picked up by the unhandledrejection handler\n if (error && typeof error === 'object') {\n addNonEnumerableProperty(error, '_sentry_active_span', getActiveSpan());\n }\n },\n );\n };\n }\n\n // Is this an ESM module?\n // https://tc39.es/ecma262/#sec-module-namespace-objects\n if (Object.prototype.toString.call(moduleExports) === '[object Module]') {\n // In ESM we take the usual route and just replace the exports we want to instrument\n for (const method of INSTRUMENTED_METHODS) {\n moduleExports[method] = generatePatch(moduleExports[method]);\n }\n\n return moduleExports;\n } else {\n // In CJS we can't replace the exports in the original module because they\n // don't have setters, so we create a new object with the same properties\n const patchedModuleExports = INSTRUMENTED_METHODS.reduce((acc, curr) => {\n acc[curr] = generatePatch(moduleExports[curr]);\n return acc;\n }, {} as PatchedModuleExports);\n\n return { ...moduleExports, ...patchedModuleExports };\n }\n }\n}\n"],"names":["InstrumentationBase","SDK_VERSION","InstrumentationNodeModuleDefinition","getCurrentScope","INTEGRATION_NAME","handleCallbackErrors","addNonEnumerableProperty","getActiveSpan"],"mappings":";;;;;;AAYA;AACA;AACA,MAAM,uBAAuB;AAC7B,EAAE,cAAc;AAChB,EAAE,YAAY;AACd,EAAE,gBAAgB;AAClB,EAAE,cAAc;AAChB,EAAE,OAAO;AACT,EAAE,WAAW;AACb,CAAA;;AAgBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,0BAA0B;AAC1C,EAAE,2BAA2B;AAC7B,EAAE,sBAAsB;AACxB,EAAE,0BAA0B;AAC5B,EAAE,uBAAuB;AACzB,EAAqD;AACrD,EAAE,MAAM,YAAA;AACR,IAAI,2BAA2B,EAAE,YAAA,KAAiB;AAClD,QAAQ,2BAA2B,CAAC;AACpC,QAAQ,sBAAsB,CAAC,YAAA,KAAiB;AAChD,UAAU,sBAAsB,CAAC;AACjC,UAAU,+BAA+B;AACzC,YAAY,IAAA;AACZ,YAAY,uBAAuB;;AAEnC,EAAE,MAAM,aAAA;AACR,IAAI,2BAA2B,EAAE,aAAA,KAAkB;AACnD,QAAQ,2BAA2B,CAAC;AACpC,QAAQ,sBAAsB,CAAC,aAAA,KAAkB;AACjD,UAAU,sBAAsB,CAAC;AACjC,UAAU,+BAA+B;AACzC,YAAY,IAAA;AACZ,YAAY,uBAAuB;;AAEnC,EAAE,OAAO,EAAE,YAAY,EAAE,eAAe;AACxC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,6BAAA,SAAsCA,mCAAA,CAAoB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MAAM,CAAC,CAAC;AACpE;;AAEA,MAAM,OAAO,aAAa;AAC1B,WAAW;AACX;AACA;AACA,MAAM,MAAM,oBAAA,GAAuB,oBAAoB,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,KAAK;AAC9E,QAAQ,GAAG,CAAC,IAAI,CAAA,GAAI,aAAa,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;AACtD,QAAQ,OAAO,GAAG;AAClB,OAAO,EAAE,EAAC,EAA0B;;AAEpC,MAAM,OAAO,EAAE,GAAG,aAAa,EAAE,GAAG,sBAAsB;AAC1D;AACA;AACA;;;;;"}
@@ -28,6 +28,7 @@ export { buildLaunchDarklyFlagUsedHandlerShim as buildLaunchDarklyFlagUsedHandle
28
28
  export { OpenFeatureIntegrationHookShim as OpenFeatureIntegrationHook, openFeatureIntegrationShim as openFeatureIntegration } from './integrations/featureFlagShims/openFeature.js';
29
29
  export { statsigIntegrationShim as statsigIntegration } from './integrations/featureFlagShims/statsig.js';
30
30
  export { unleashIntegrationShim as unleashIntegration } from './integrations/featureFlagShims/unleash.js';
31
+ export { firebaseIntegration } from './integrations/tracing/firebase/firebase.js';
31
32
  export { getDefaultIntegrations, getDefaultIntegrationsWithoutPerformance, init, initWithoutDefaultIntegrations } from './sdk/index.js';
32
33
  export { initOpenTelemetry, preloadOpenTelemetry } from './sdk/initOtel.js';
33
34
  export { getAutoPerformanceIntegrations } from './integrations/tracing/index.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -5,19 +5,52 @@ import { DEBUG_BUILD } from '../../../debug-build.js';
5
5
  import { FastifyOtelInstrumentation } from './fastify-otel/index.js';
6
6
  import { FastifyInstrumentationV3 } from './v3/instrumentation.js';
7
7
 
8
+ /**
9
+ * Options for the Fastify integration.
10
+ *
11
+ * `shouldHandleError` - Callback method deciding whether error should be captured and sent to Sentry
12
+ * This is used on Fastify v5 where Sentry handles errors in the diagnostics channel.
13
+ * Fastify v3 and v4 use `setupFastifyErrorHandler` instead.
14
+ *
15
+ * @example
16
+ *
17
+ * ```javascript
18
+ * Sentry.init({
19
+ * integrations: [
20
+ * Sentry.fastifyIntegration({
21
+ * shouldHandleError(_error, _request, reply) {
22
+ * return reply.statusCode >= 500;
23
+ * },
24
+ * });
25
+ * },
26
+ * });
27
+ * ```
28
+ *
29
+ */
30
+
8
31
  const INTEGRATION_NAME = 'Fastify';
32
+ const INTEGRATION_NAME_V5 = 'Fastify-V5';
9
33
  const INTEGRATION_NAME_V3 = 'Fastify-V3';
10
34
 
11
35
  const instrumentFastifyV3 = generateInstrumentOnce(INTEGRATION_NAME_V3, () => new FastifyInstrumentationV3());
12
36
 
37
+ function getFastifyIntegration() {
38
+ const client = getClient();
39
+ if (!client) {
40
+ return undefined;
41
+ } else {
42
+ return client.getIntegrationByName(INTEGRATION_NAME) ;
43
+ }
44
+ }
45
+
13
46
  function handleFastifyError(
14
47
 
15
48
  error,
16
49
  request,
17
50
  reply,
18
- shouldHandleError,
19
51
  handlerOrigin,
20
52
  ) {
53
+ const shouldHandleError = getFastifyIntegration()?.getShouldHandleError() || defaultShouldHandleError;
21
54
  // Diagnostics channel runs before the onError hook, so we can use it to check if the handler was already registered
22
55
  if (handlerOrigin === 'diagnostics-channel') {
23
56
  this.diagnosticsChannelExists = true;
@@ -27,7 +60,7 @@ function handleFastifyError(
27
60
  DEBUG_BUILD &&
28
61
  debug.warn(
29
62
  'Fastify error handler was already registered via diagnostics channel.',
30
- 'You can safely remove `setupFastifyErrorHandler` call.',
63
+ 'You can safely remove `setupFastifyErrorHandler` call and set `shouldHandleError` on the integration options.',
31
64
  );
32
65
 
33
66
  // If the diagnostics channel already exists, we don't need to handle the error again
@@ -35,15 +68,13 @@ function handleFastifyError(
35
68
  }
36
69
 
37
70
  if (shouldHandleError(error, request, reply)) {
38
- captureException(error);
71
+ captureException(error, { mechanism: { handled: false, type: 'fastify' } });
39
72
  }
40
73
  }
41
74
 
42
- const instrumentFastify = generateInstrumentOnce(INTEGRATION_NAME, () => {
75
+ const instrumentFastify = generateInstrumentOnce(INTEGRATION_NAME_V5, () => {
43
76
  const fastifyOtelInstrumentationInstance = new FastifyOtelInstrumentation();
44
77
  const plugin = fastifyOtelInstrumentationInstance.plugin();
45
- const options = fastifyOtelInstrumentationInstance.getConfig();
46
- const shouldHandleError = (options )?.shouldHandleError || defaultShouldHandleError;
47
78
 
48
79
  // This message handler works for Fastify versions 3, 4 and 5
49
80
  dc.subscribe('fastify.initialization', message => {
@@ -69,20 +100,30 @@ const instrumentFastify = generateInstrumentOnce(INTEGRATION_NAME, () => {
69
100
 
70
101
  ;
71
102
 
72
- handleFastifyError.call(handleFastifyError, error, request, reply, shouldHandleError, 'diagnostics-channel');
103
+ handleFastifyError.call(handleFastifyError, error, request, reply, 'diagnostics-channel');
73
104
  });
74
105
 
75
106
  // Returning this as unknown not to deal with the internal types of the FastifyOtelInstrumentation
76
107
  return fastifyOtelInstrumentationInstance ;
77
108
  });
78
109
 
79
- const _fastifyIntegration = (() => {
110
+ const _fastifyIntegration = (({ shouldHandleError }) => {
111
+ let _shouldHandleError;
112
+
80
113
  return {
81
114
  name: INTEGRATION_NAME,
82
115
  setupOnce() {
116
+ _shouldHandleError = shouldHandleError || defaultShouldHandleError;
117
+
83
118
  instrumentFastifyV3();
84
119
  instrumentFastify();
85
120
  },
121
+ getShouldHandleError() {
122
+ return _shouldHandleError;
123
+ },
124
+ setShouldHandleError(fn) {
125
+ _shouldHandleError = fn;
126
+ },
86
127
  };
87
128
  }) ;
88
129
 
@@ -102,7 +143,9 @@ const _fastifyIntegration = (() => {
102
143
  * })
103
144
  * ```
104
145
  */
105
- const fastifyIntegration = defineIntegration(_fastifyIntegration);
146
+ const fastifyIntegration = defineIntegration((options = {}) =>
147
+ _fastifyIntegration(options),
148
+ );
106
149
 
107
150
  /**
108
151
  * Default function to determine if an error should be sent to Sentry
@@ -136,11 +179,14 @@ function defaultShouldHandleError(_error, _request, reply) {
136
179
  * ```
137
180
  */
138
181
  function setupFastifyErrorHandler(fastify, options) {
139
- const shouldHandleError = options?.shouldHandleError || defaultShouldHandleError;
182
+ if (options?.shouldHandleError) {
183
+ getFastifyIntegration()?.setShouldHandleError(options.shouldHandleError);
184
+ }
185
+
140
186
  const plugin = Object.assign(
141
187
  function (fastify, _options, done) {
142
188
  fastify.addHook('onError', async (request, reply, error) => {
143
- handleFastifyError.call(handleFastifyError, error, request, reply, shouldHandleError, 'onError-hook');
189
+ handleFastifyError.call(handleFastifyError, error, request, reply, 'onError-hook');
144
190
  });
145
191
  done();
146
192
  },
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../../../src/integrations/tracing/fastify/index.ts"],"sourcesContent":["import * as diagnosticsChannel from 'node:diagnostics_channel';\nimport type { Instrumentation, InstrumentationConfig } from '@opentelemetry/instrumentation';\nimport type { IntegrationFn, Span } from '@sentry/core';\nimport {\n captureException,\n debug,\n defineIntegration,\n getClient,\n getIsolationScope,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n spanToJSON,\n} from '@sentry/core';\nimport { generateInstrumentOnce } from '@sentry/node-core';\nimport { DEBUG_BUILD } from '../../../debug-build';\nimport { FastifyOtelInstrumentation } from './fastify-otel/index';\nimport type { FastifyInstance, FastifyReply, FastifyRequest } from './types';\nimport { FastifyInstrumentationV3 } from './v3/instrumentation';\n\ninterface FastifyHandlerOptions {\n /**\n * Callback method deciding whether error should be captured and sent to Sentry\n *\n * @param error Captured Fastify error\n * @param request Fastify request (or any object containing at least method, routeOptions.url, and routerPath)\n * @param reply Fastify reply (or any object containing at least statusCode)\n *\n * @example\n *\n * ```javascript\n * setupFastifyErrorHandler(app, {\n * shouldHandleError(_error, _request, reply) {\n * return reply.statusCode >= 400;\n * },\n * });\n * ```\n *\n * If using TypeScript, you can cast the request and reply to get full type safety.\n *\n * ```typescript\n * import type { FastifyRequest, FastifyReply } from 'fastify';\n *\n * setupFastifyErrorHandler(app, {\n * shouldHandleError(error, minimalRequest, minimalReply) {\n * const request = minimalRequest as FastifyRequest;\n * const reply = minimalReply as FastifyReply;\n * return reply.statusCode >= 500;\n * },\n * });\n * ```\n */\n shouldHandleError: (error: Error, request: FastifyRequest, reply: FastifyReply) => boolean;\n}\n\nconst INTEGRATION_NAME = 'Fastify';\nconst INTEGRATION_NAME_V3 = 'Fastify-V3';\n\nexport const instrumentFastifyV3 = generateInstrumentOnce(INTEGRATION_NAME_V3, () => new FastifyInstrumentationV3());\n\nfunction handleFastifyError(\n this: {\n diagnosticsChannelExists?: boolean;\n },\n error: Error,\n request: FastifyRequest & { opentelemetry?: () => { span?: Span } },\n reply: FastifyReply,\n shouldHandleError: (error: Error, request: FastifyRequest, reply: FastifyReply) => boolean,\n handlerOrigin: 'diagnostics-channel' | 'onError-hook',\n): void {\n // Diagnostics channel runs before the onError hook, so we can use it to check if the handler was already registered\n if (handlerOrigin === 'diagnostics-channel') {\n this.diagnosticsChannelExists = true;\n }\n\n if (this.diagnosticsChannelExists && handlerOrigin === 'onError-hook') {\n DEBUG_BUILD &&\n debug.warn(\n 'Fastify error handler was already registered via diagnostics channel.',\n 'You can safely remove `setupFastifyErrorHandler` call.',\n );\n\n // If the diagnostics channel already exists, we don't need to handle the error again\n return;\n }\n\n if (shouldHandleError(error, request, reply)) {\n captureException(error);\n }\n}\n\nexport const instrumentFastify = generateInstrumentOnce(INTEGRATION_NAME, () => {\n const fastifyOtelInstrumentationInstance = new FastifyOtelInstrumentation();\n const plugin = fastifyOtelInstrumentationInstance.plugin();\n const options = fastifyOtelInstrumentationInstance.getConfig();\n const shouldHandleError = (options as FastifyHandlerOptions)?.shouldHandleError || defaultShouldHandleError;\n\n // This message handler works for Fastify versions 3, 4 and 5\n diagnosticsChannel.subscribe('fastify.initialization', message => {\n const fastifyInstance = (message as { fastify?: FastifyInstance }).fastify;\n\n fastifyInstance?.register(plugin).after(err => {\n if (err) {\n DEBUG_BUILD && debug.error('Failed to setup Fastify instrumentation', err);\n } else {\n instrumentClient();\n\n if (fastifyInstance) {\n instrumentOnRequest(fastifyInstance);\n }\n }\n });\n });\n\n // This diagnostics channel only works on Fastify version 5\n // For versions 3 and 4, we use `setupFastifyErrorHandler` instead\n diagnosticsChannel.subscribe('tracing:fastify.request.handler:error', message => {\n const { error, request, reply } = message as {\n error: Error;\n request: FastifyRequest & { opentelemetry?: () => { span?: Span } };\n reply: FastifyReply;\n };\n\n handleFastifyError.call(handleFastifyError, error, request, reply, shouldHandleError, 'diagnostics-channel');\n });\n\n // Returning this as unknown not to deal with the internal types of the FastifyOtelInstrumentation\n return fastifyOtelInstrumentationInstance as Instrumentation<InstrumentationConfig & FastifyHandlerOptions>;\n});\n\nconst _fastifyIntegration = (() => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n instrumentFastifyV3();\n instrumentFastify();\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Adds Sentry tracing instrumentation for [Fastify](https://fastify.dev/).\n *\n * If you also want to capture errors, you need to call `setupFastifyErrorHandler(app)` after you set up your Fastify server.\n *\n * For more information, see the [fastify documentation](https://docs.sentry.io/platforms/javascript/guides/fastify/).\n *\n * @example\n * ```javascript\n * const Sentry = require('@sentry/node');\n *\n * Sentry.init({\n * integrations: [Sentry.fastifyIntegration()],\n * })\n * ```\n */\nexport const fastifyIntegration = defineIntegration(_fastifyIntegration);\n\n/**\n * Default function to determine if an error should be sent to Sentry\n *\n * 3xx and 4xx errors are not sent by default.\n */\nfunction defaultShouldHandleError(_error: Error, _request: FastifyRequest, reply: FastifyReply): boolean {\n const statusCode = reply.statusCode;\n // 3xx and 4xx errors are not sent by default.\n return statusCode >= 500 || statusCode <= 299;\n}\n\n/**\n * Add an Fastify error handler to capture errors to Sentry.\n *\n * @param fastify The Fastify instance to which to add the error handler\n * @param options Configuration options for the handler\n *\n * @example\n * ```javascript\n * const Sentry = require('@sentry/node');\n * const Fastify = require(\"fastify\");\n *\n * const app = Fastify();\n *\n * Sentry.setupFastifyErrorHandler(app);\n *\n * // Add your routes, etc.\n *\n * app.listen({ port: 3000 });\n * ```\n */\nexport function setupFastifyErrorHandler(fastify: FastifyInstance, options?: Partial<FastifyHandlerOptions>): void {\n const shouldHandleError = options?.shouldHandleError || defaultShouldHandleError;\n const plugin = Object.assign(\n function (fastify: FastifyInstance, _options: unknown, done: () => void): void {\n fastify.addHook('onError', async (request, reply, error) => {\n handleFastifyError.call(handleFastifyError, error, request, reply, shouldHandleError, 'onError-hook');\n });\n done();\n },\n {\n [Symbol.for('skip-override')]: true,\n [Symbol.for('fastify.display-name')]: 'sentry-fastify-error-handler',\n },\n );\n\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n fastify.register(plugin);\n}\n\nfunction addFastifySpanAttributes(span: Span): void {\n const spanJSON = spanToJSON(span);\n const spanName = spanJSON.description;\n const attributes = spanJSON.data;\n\n const type = attributes['fastify.type'];\n\n const isHook = type === 'hook';\n const isHandler = type === spanName?.startsWith('handler -');\n // In @fastify/otel `request-handler` is separated by dash, not underscore\n const isRequestHandler = spanName === 'request' || type === 'request-handler';\n\n // If this is already set, or we have no fastify span, no need to process again...\n if (attributes[SEMANTIC_ATTRIBUTE_SENTRY_OP] || (!isHandler && !isRequestHandler && !isHook)) {\n return;\n }\n\n const opPrefix = isHook ? 'hook' : isHandler ? 'middleware' : isRequestHandler ? 'request-handler' : '<unknown>';\n\n span.setAttributes({\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.otel.fastify',\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: `${opPrefix}.fastify`,\n });\n\n const attrName = attributes['fastify.name'] || attributes['plugin.name'] || attributes['hook.name'];\n if (typeof attrName === 'string') {\n // Try removing `fastify -> ` and `@fastify/otel -> ` prefixes\n // This is a bit of a hack, and not always working for all spans\n // But it's the best we can do without a proper API\n const updatedName = attrName.replace(/^fastify -> /, '').replace(/^@fastify\\/otel -> /, '');\n\n span.updateName(updatedName);\n }\n}\n\nfunction instrumentClient(): void {\n const client = getClient();\n if (client) {\n client.on('spanStart', (span: Span) => {\n addFastifySpanAttributes(span);\n });\n }\n}\n\nfunction instrumentOnRequest(fastify: FastifyInstance): void {\n fastify.addHook('onRequest', async (request: FastifyRequest & { opentelemetry?: () => { span?: Span } }, _reply) => {\n if (request.opentelemetry) {\n const { span } = request.opentelemetry();\n\n if (span) {\n addFastifySpanAttributes(span);\n }\n }\n\n const routeName = request.routeOptions?.url;\n const method = request.method || 'GET';\n\n getIsolationScope().setTransactionName(`${method} ${routeName}`);\n });\n}\n"],"names":["diagnosticsChannel"],"mappings":";;;;;;;AAsDA,MAAM,gBAAA,GAAmB,SAAS;AAClC,MAAM,mBAAA,GAAsB,YAAY;;AAEjC,MAAM,mBAAA,GAAsB,sBAAsB,CAAC,mBAAmB,EAAE,MAAM,IAAI,wBAAwB,EAAE;;AAEnH,SAAS,kBAAkB;;AAI3B,EAAE,KAAK;AACP,EAAE,OAAO;AACT,EAAE,KAAK;AACP,EAAE,iBAAiB;AACnB,EAAE,aAAa;AACf,EAAQ;AACR;AACA,EAAE,IAAI,aAAA,KAAkB,qBAAqB,EAAE;AAC/C,IAAI,IAAI,CAAC,wBAAA,GAA2B,IAAI;AACxC;;AAEA,EAAE,IAAI,IAAI,CAAC,4BAA4B,aAAA,KAAkB,cAAc,EAAE;AACzE,IAAI,WAAA;AACJ,MAAM,KAAK,CAAC,IAAI;AAChB,QAAQ,uEAAuE;AAC/E,QAAQ,wDAAwD;AAChE,OAAO;;AAEP;AACA,IAAI;AACJ;;AAEA,EAAE,IAAI,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE;AAChD,IAAI,gBAAgB,CAAC,KAAK,CAAC;AAC3B;AACA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GAAA,SAAA,EAAA;AACA,EAAA,IAAA,MAAA,EAAA;AACA,IAAA,MAAA,CAAA,EAAA,CAAA,WAAA,EAAA,CAAA,IAAA,KAAA;AACA,MAAA,wBAAA,CAAA,IAAA,CAAA;AACA,KAAA,CAAA;AACA;AACA;;AAEA,SAAA,mBAAA,CAAA,OAAA,EAAA;AACA,EAAA,OAAA,CAAA,OAAA,CAAA,WAAA,EAAA,OAAA,OAAA,EAAA,MAAA,KAAA;AACA,IAAA,IAAA,OAAA,CAAA,aAAA,EAAA;AACA,MAAA,MAAA,EAAA,IAAA,EAAA,GAAA,OAAA,CAAA,aAAA,EAAA;;AAEA,MAAA,IAAA,IAAA,EAAA;AACA,QAAA,wBAAA,CAAA,IAAA,CAAA;AACA;AACA;;AAEA,IAAA,MAAA,SAAA,GAAA,OAAA,CAAA,YAAA,EAAA,GAAA;AACA,IAAA,MAAA,MAAA,GAAA,OAAA,CAAA,MAAA,IAAA,KAAA;;AAEA,IAAA,iBAAA,EAAA,CAAA,kBAAA,CAAA,CAAA,EAAA,MAAA,CAAA,CAAA,EAAA,SAAA,CAAA,CAAA,CAAA;AACA,GAAA,CAAA;AACA;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../../../src/integrations/tracing/fastify/index.ts"],"sourcesContent":["import * as diagnosticsChannel from 'node:diagnostics_channel';\nimport type { Instrumentation, InstrumentationConfig } from '@opentelemetry/instrumentation';\nimport type { IntegrationFn, Span } from '@sentry/core';\nimport {\n captureException,\n debug,\n defineIntegration,\n getClient,\n getIsolationScope,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n spanToJSON,\n} from '@sentry/core';\nimport { generateInstrumentOnce } from '@sentry/node-core';\nimport { DEBUG_BUILD } from '../../../debug-build';\nimport { FastifyOtelInstrumentation } from './fastify-otel/index';\nimport type { FastifyInstance, FastifyReply, FastifyRequest } from './types';\nimport { FastifyInstrumentationV3 } from './v3/instrumentation';\n\n/**\n * Options for the Fastify integration.\n *\n * `shouldHandleError` - Callback method deciding whether error should be captured and sent to Sentry\n * This is used on Fastify v5 where Sentry handles errors in the diagnostics channel.\n * Fastify v3 and v4 use `setupFastifyErrorHandler` instead.\n *\n * @example\n *\n * ```javascript\n * Sentry.init({\n * integrations: [\n * Sentry.fastifyIntegration({\n * shouldHandleError(_error, _request, reply) {\n * return reply.statusCode >= 500;\n * },\n * });\n * },\n * });\n * ```\n *\n */\ninterface FastifyIntegrationOptions {\n /**\n * Callback method deciding whether error should be captured and sent to Sentry\n * This is used on Fastify v5 where Sentry handles errors in the diagnostics channel.\n * Fastify v3 and v4 use `setupFastifyErrorHandler` instead.\n *\n * @param error Captured Fastify error\n * @param request Fastify request (or any object containing at least method, routeOptions.url, and routerPath)\n * @param reply Fastify reply (or any object containing at least statusCode)\n */\n shouldHandleError: (error: Error, request: FastifyRequest, reply: FastifyReply) => boolean;\n}\n\ninterface FastifyHandlerOptions {\n /**\n * Callback method deciding whether error should be captured and sent to Sentry\n *\n * @param error Captured Fastify error\n * @param request Fastify request (or any object containing at least method, routeOptions.url, and routerPath)\n * @param reply Fastify reply (or any object containing at least statusCode)\n *\n * @example\n *\n *\n * ```javascript\n * setupFastifyErrorHandler(app, {\n * shouldHandleError(_error, _request, reply) {\n * return reply.statusCode >= 400;\n * },\n * });\n * ```\n *\n *\n * If using TypeScript, you can cast the request and reply to get full type safety.\n *\n * ```typescript\n * import type { FastifyRequest, FastifyReply } from 'fastify';\n *\n * setupFastifyErrorHandler(app, {\n * shouldHandleError(error, minimalRequest, minimalReply) {\n * const request = minimalRequest as FastifyRequest;\n * const reply = minimalReply as FastifyReply;\n * return reply.statusCode >= 500;\n * },\n * });\n * ```\n */\n shouldHandleError: (error: Error, request: FastifyRequest, reply: FastifyReply) => boolean;\n}\n\nconst INTEGRATION_NAME = 'Fastify';\nconst INTEGRATION_NAME_V5 = 'Fastify-V5';\nconst INTEGRATION_NAME_V3 = 'Fastify-V3';\n\nexport const instrumentFastifyV3 = generateInstrumentOnce(INTEGRATION_NAME_V3, () => new FastifyInstrumentationV3());\n\nfunction getFastifyIntegration(): ReturnType<typeof _fastifyIntegration> | undefined {\n const client = getClient();\n if (!client) {\n return undefined;\n } else {\n return client.getIntegrationByName(INTEGRATION_NAME) as ReturnType<typeof _fastifyIntegration> | undefined;\n }\n}\n\nfunction handleFastifyError(\n this: {\n diagnosticsChannelExists?: boolean;\n },\n error: Error,\n request: FastifyRequest & { opentelemetry?: () => { span?: Span } },\n reply: FastifyReply,\n handlerOrigin: 'diagnostics-channel' | 'onError-hook',\n): void {\n const shouldHandleError = getFastifyIntegration()?.getShouldHandleError() || defaultShouldHandleError;\n // Diagnostics channel runs before the onError hook, so we can use it to check if the handler was already registered\n if (handlerOrigin === 'diagnostics-channel') {\n this.diagnosticsChannelExists = true;\n }\n\n if (this.diagnosticsChannelExists && handlerOrigin === 'onError-hook') {\n DEBUG_BUILD &&\n debug.warn(\n 'Fastify error handler was already registered via diagnostics channel.',\n 'You can safely remove `setupFastifyErrorHandler` call and set `shouldHandleError` on the integration options.',\n );\n\n // If the diagnostics channel already exists, we don't need to handle the error again\n return;\n }\n\n if (shouldHandleError(error, request, reply)) {\n captureException(error, { mechanism: { handled: false, type: 'fastify' } });\n }\n}\n\nexport const instrumentFastify = generateInstrumentOnce(INTEGRATION_NAME_V5, () => {\n const fastifyOtelInstrumentationInstance = new FastifyOtelInstrumentation();\n const plugin = fastifyOtelInstrumentationInstance.plugin();\n\n // This message handler works for Fastify versions 3, 4 and 5\n diagnosticsChannel.subscribe('fastify.initialization', message => {\n const fastifyInstance = (message as { fastify?: FastifyInstance }).fastify;\n\n fastifyInstance?.register(plugin).after(err => {\n if (err) {\n DEBUG_BUILD && debug.error('Failed to setup Fastify instrumentation', err);\n } else {\n instrumentClient();\n\n if (fastifyInstance) {\n instrumentOnRequest(fastifyInstance);\n }\n }\n });\n });\n\n // This diagnostics channel only works on Fastify version 5\n // For versions 3 and 4, we use `setupFastifyErrorHandler` instead\n diagnosticsChannel.subscribe('tracing:fastify.request.handler:error', message => {\n const { error, request, reply } = message as {\n error: Error;\n request: FastifyRequest & { opentelemetry?: () => { span?: Span } };\n reply: FastifyReply;\n };\n\n handleFastifyError.call(handleFastifyError, error, request, reply, 'diagnostics-channel');\n });\n\n // Returning this as unknown not to deal with the internal types of the FastifyOtelInstrumentation\n return fastifyOtelInstrumentationInstance as Instrumentation<InstrumentationConfig & FastifyIntegrationOptions>;\n});\n\nconst _fastifyIntegration = (({ shouldHandleError }: Partial<FastifyIntegrationOptions>) => {\n let _shouldHandleError: (error: Error, request: FastifyRequest, reply: FastifyReply) => boolean;\n\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n _shouldHandleError = shouldHandleError || defaultShouldHandleError;\n\n instrumentFastifyV3();\n instrumentFastify();\n },\n getShouldHandleError() {\n return _shouldHandleError;\n },\n setShouldHandleError(fn: (error: Error, request: FastifyRequest, reply: FastifyReply) => boolean): void {\n _shouldHandleError = fn;\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Adds Sentry tracing instrumentation for [Fastify](https://fastify.dev/).\n *\n * If you also want to capture errors, you need to call `setupFastifyErrorHandler(app)` after you set up your Fastify server.\n *\n * For more information, see the [fastify documentation](https://docs.sentry.io/platforms/javascript/guides/fastify/).\n *\n * @example\n * ```javascript\n * const Sentry = require('@sentry/node');\n *\n * Sentry.init({\n * integrations: [Sentry.fastifyIntegration()],\n * })\n * ```\n */\nexport const fastifyIntegration = defineIntegration((options: Partial<FastifyIntegrationOptions> = {}) =>\n _fastifyIntegration(options),\n);\n\n/**\n * Default function to determine if an error should be sent to Sentry\n *\n * 3xx and 4xx errors are not sent by default.\n */\nfunction defaultShouldHandleError(_error: Error, _request: FastifyRequest, reply: FastifyReply): boolean {\n const statusCode = reply.statusCode;\n // 3xx and 4xx errors are not sent by default.\n return statusCode >= 500 || statusCode <= 299;\n}\n\n/**\n * Add an Fastify error handler to capture errors to Sentry.\n *\n * @param fastify The Fastify instance to which to add the error handler\n * @param options Configuration options for the handler\n *\n * @example\n * ```javascript\n * const Sentry = require('@sentry/node');\n * const Fastify = require(\"fastify\");\n *\n * const app = Fastify();\n *\n * Sentry.setupFastifyErrorHandler(app);\n *\n * // Add your routes, etc.\n *\n * app.listen({ port: 3000 });\n * ```\n */\nexport function setupFastifyErrorHandler(fastify: FastifyInstance, options?: Partial<FastifyHandlerOptions>): void {\n if (options?.shouldHandleError) {\n getFastifyIntegration()?.setShouldHandleError(options.shouldHandleError);\n }\n\n const plugin = Object.assign(\n function (fastify: FastifyInstance, _options: unknown, done: () => void): void {\n fastify.addHook('onError', async (request, reply, error) => {\n handleFastifyError.call(handleFastifyError, error, request, reply, 'onError-hook');\n });\n done();\n },\n {\n [Symbol.for('skip-override')]: true,\n [Symbol.for('fastify.display-name')]: 'sentry-fastify-error-handler',\n },\n );\n\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n fastify.register(plugin);\n}\n\nfunction addFastifySpanAttributes(span: Span): void {\n const spanJSON = spanToJSON(span);\n const spanName = spanJSON.description;\n const attributes = spanJSON.data;\n\n const type = attributes['fastify.type'];\n\n const isHook = type === 'hook';\n const isHandler = type === spanName?.startsWith('handler -');\n // In @fastify/otel `request-handler` is separated by dash, not underscore\n const isRequestHandler = spanName === 'request' || type === 'request-handler';\n\n // If this is already set, or we have no fastify span, no need to process again...\n if (attributes[SEMANTIC_ATTRIBUTE_SENTRY_OP] || (!isHandler && !isRequestHandler && !isHook)) {\n return;\n }\n\n const opPrefix = isHook ? 'hook' : isHandler ? 'middleware' : isRequestHandler ? 'request-handler' : '<unknown>';\n\n span.setAttributes({\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.otel.fastify',\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: `${opPrefix}.fastify`,\n });\n\n const attrName = attributes['fastify.name'] || attributes['plugin.name'] || attributes['hook.name'];\n if (typeof attrName === 'string') {\n // Try removing `fastify -> ` and `@fastify/otel -> ` prefixes\n // This is a bit of a hack, and not always working for all spans\n // But it's the best we can do without a proper API\n const updatedName = attrName.replace(/^fastify -> /, '').replace(/^@fastify\\/otel -> /, '');\n\n span.updateName(updatedName);\n }\n}\n\nfunction instrumentClient(): void {\n const client = getClient();\n if (client) {\n client.on('spanStart', (span: Span) => {\n addFastifySpanAttributes(span);\n });\n }\n}\n\nfunction instrumentOnRequest(fastify: FastifyInstance): void {\n fastify.addHook('onRequest', async (request: FastifyRequest & { opentelemetry?: () => { span?: Span } }, _reply) => {\n if (request.opentelemetry) {\n const { span } = request.opentelemetry();\n\n if (span) {\n addFastifySpanAttributes(span);\n }\n }\n\n const routeName = request.routeOptions?.url;\n const method = request.method || 'GET';\n\n getIsolationScope().setTransactionName(`${method} ${routeName}`);\n });\n}\n"],"names":["diagnosticsChannel"],"mappings":";;;;;;;AAmBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAmDA,MAAM,gBAAA,GAAmB,SAAS;AAClC,MAAM,mBAAA,GAAsB,YAAY;AACxC,MAAM,mBAAA,GAAsB,YAAY;;AAEjC,MAAM,mBAAA,GAAsB,sBAAsB,CAAC,mBAAmB,EAAE,MAAM,IAAI,wBAAwB,EAAE;;AAEnH,SAAS,qBAAqB,GAAuD;AACrF,EAAE,MAAM,MAAA,GAAS,SAAS,EAAE;AAC5B,EAAE,IAAI,CAAC,MAAM,EAAE;AACf,IAAI,OAAO,SAAS;AACpB,SAAS;AACT,IAAI,OAAO,MAAM,CAAC,oBAAoB,CAAC,gBAAgB,CAAA;AACvD;AACA;;AAEA,SAAS,kBAAkB;;AAI3B,EAAE,KAAK;AACP,EAAE,OAAO;AACT,EAAE,KAAK;AACP,EAAE,aAAa;AACf,EAAQ;AACR,EAAE,MAAM,iBAAA,GAAoB,qBAAqB,EAAE,EAAE,oBAAoB,EAAC,IAAK,wBAAwB;AACvG;AACA,EAAE,IAA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CAAA,YAAA,EAAA,GAAA;AACA,IAAA,MAAA,MAAA,GAAA,OAAA,CAAA,MAAA,IAAA,KAAA;;AAEA,IAAA,iBAAA,EAAA,CAAA,kBAAA,CAAA,CAAA,EAAA,MAAA,CAAA,CAAA,EAAA,SAAA,CAAA,CAAA,CAAA;AACA,GAAA,CAAA;AACA;;;;"}
@@ -0,0 +1,29 @@
1
+ import { defineIntegration, SEMANTIC_ATTRIBUTE_SENTRY_OP } from '@sentry/core';
2
+ import { generateInstrumentOnce, addOriginToSpan } from '@sentry/node-core';
3
+ import { FirebaseInstrumentation } from './otel/firebaseInstrumentation.js';
4
+
5
+ const INTEGRATION_NAME = 'Firebase';
6
+
7
+ const config = {
8
+ firestoreSpanCreationHook: span => {
9
+ addOriginToSpan(span , 'auto.firebase.otel.firestore');
10
+
11
+ span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'db.query');
12
+ },
13
+ };
14
+
15
+ const instrumentFirebase = generateInstrumentOnce(INTEGRATION_NAME, () => new FirebaseInstrumentation(config));
16
+
17
+ const _firebaseIntegration = (() => {
18
+ return {
19
+ name: INTEGRATION_NAME,
20
+ setupOnce() {
21
+ instrumentFirebase();
22
+ },
23
+ };
24
+ }) ;
25
+
26
+ const firebaseIntegration = defineIntegration(_firebaseIntegration);
27
+
28
+ export { firebaseIntegration, instrumentFirebase };
29
+ //# sourceMappingURL=firebase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"firebase.js","sources":["../../../../../src/integrations/tracing/firebase/firebase.ts"],"sourcesContent":["import type { Span } from '@opentelemetry/api';\nimport type { IntegrationFn } from '@sentry/core';\nimport { defineIntegration, SEMANTIC_ATTRIBUTE_SENTRY_OP } from '@sentry/core';\nimport { addOriginToSpan, generateInstrumentOnce } from '@sentry/node-core';\nimport { type FirebaseInstrumentationConfig, FirebaseInstrumentation } from './otel';\n\nconst INTEGRATION_NAME = 'Firebase';\n\nconst config: FirebaseInstrumentationConfig = {\n firestoreSpanCreationHook: span => {\n addOriginToSpan(span as Span, 'auto.firebase.otel.firestore');\n\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'db.query');\n },\n};\n\nexport const instrumentFirebase = generateInstrumentOnce(INTEGRATION_NAME, () => new FirebaseInstrumentation(config));\n\nconst _firebaseIntegration = (() => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n instrumentFirebase();\n },\n };\n}) satisfies IntegrationFn;\n\nexport const firebaseIntegration = defineIntegration(_firebaseIntegration);\n"],"names":[],"mappings":";;;;AAMA,MAAM,gBAAA,GAAmB,UAAU;;AAEnC,MAAM,MAAM,GAAkC;AAC9C,EAAE,yBAAyB,EAAE,IAAA,IAAQ;AACrC,IAAI,eAAe,CAAC,IAAA,GAAc,8BAA8B,CAAC;;AAEjE,IAAI,IAAI,CAAC,YAAY,CAAC,4BAA4B,EAAE,UAAU,CAAC;AAC/D,GAAG;AACH,CAAC;;AAEM,MAAM,kBAAA,GAAqB,sBAAsB,CAAC,gBAAgB,EAAE,MAAM,IAAI,uBAAuB,CAAC,MAAM,CAAC;;AAEpH,MAAM,oBAAA,IAAwB,MAAM;AACpC,EAAE,OAAO;AACT,IAAI,IAAI,EAAE,gBAAgB;AAC1B,IAAI,SAAS,GAAG;AAChB,MAAM,kBAAkB,EAAE;AAC1B,KAAK;AACL,GAAG;AACH,CAAC,CAAA;;MAEY,mBAAA,GAAsB,iBAAiB,CAAC,oBAAoB;;;;"}
@@ -0,0 +1,39 @@
1
+ import { InstrumentationBase } from '@opentelemetry/instrumentation';
2
+ import { SDK_VERSION } from '@sentry/core';
3
+ import { patchFirestore } from './patches/firestore.js';
4
+
5
+ const DefaultFirebaseInstrumentationConfig = {};
6
+ const firestoreSupportedVersions = ['>=3.0.0 <5']; // firebase 9+
7
+
8
+ /**
9
+ * Instrumentation for Firebase services, specifically Firestore.
10
+ */
11
+ class FirebaseInstrumentation extends InstrumentationBase {
12
+ constructor(config = DefaultFirebaseInstrumentationConfig) {
13
+ super('@sentry/instrumentation-firebase', SDK_VERSION, config);
14
+ }
15
+
16
+ /**
17
+ * sets config
18
+ * @param config
19
+ */
20
+ setConfig(config = {}) {
21
+ super.setConfig({ ...DefaultFirebaseInstrumentationConfig, ...config });
22
+ }
23
+
24
+ /**
25
+ *
26
+ * @protected
27
+ */
28
+ // eslint-disable-next-line @typescript-eslint/naming-convention
29
+ init() {
30
+ const modules = [];
31
+
32
+ modules.push(patchFirestore(this.tracer, firestoreSupportedVersions, this._wrap, this._unwrap, this.getConfig()));
33
+
34
+ return modules;
35
+ }
36
+ }
37
+
38
+ export { FirebaseInstrumentation };
39
+ //# sourceMappingURL=firebaseInstrumentation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"firebaseInstrumentation.js","sources":["../../../../../../src/integrations/tracing/firebase/otel/firebaseInstrumentation.ts"],"sourcesContent":["import { type InstrumentationNodeModuleDefinition, InstrumentationBase } from '@opentelemetry/instrumentation';\nimport { SDK_VERSION } from '@sentry/core';\nimport { patchFirestore } from './patches/firestore';\nimport type { FirebaseInstrumentationConfig } from './types';\n\nconst DefaultFirebaseInstrumentationConfig: FirebaseInstrumentationConfig = {};\nconst firestoreSupportedVersions = ['>=3.0.0 <5']; // firebase 9+\n\n/**\n * Instrumentation for Firebase services, specifically Firestore.\n */\nexport class FirebaseInstrumentation extends InstrumentationBase<FirebaseInstrumentationConfig> {\n public constructor(config: FirebaseInstrumentationConfig = DefaultFirebaseInstrumentationConfig) {\n super('@sentry/instrumentation-firebase', SDK_VERSION, config);\n }\n\n /**\n * sets config\n * @param config\n */\n public override setConfig(config: FirebaseInstrumentationConfig = {}): void {\n super.setConfig({ ...DefaultFirebaseInstrumentationConfig, ...config });\n }\n\n /**\n *\n * @protected\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n protected init(): InstrumentationNodeModuleDefinition | InstrumentationNodeModuleDefinition[] | void {\n const modules: InstrumentationNodeModuleDefinition[] = [];\n\n modules.push(patchFirestore(this.tracer, firestoreSupportedVersions, this._wrap, this._unwrap, this.getConfig()));\n\n return modules;\n }\n}\n"],"names":[],"mappings":";;;;AAKA,MAAM,oCAAoC,GAAkC,EAAE;AAC9E,MAAM,0BAAA,GAA6B,CAAC,YAAY,CAAC,CAAA;;AAEjD;AACA;AACA;AACO,MAAM,uBAAA,SAAgC,mBAAmB,CAAgC;AAChG,GAAS,WAAW,CAAC,MAAM,GAAkC,oCAAoC,EAAE;AACnG,IAAI,KAAK,CAAC,kCAAkC,EAAE,WAAW,EAAE,MAAM,CAAC;AAClE;;AAEA;AACA;AACA;AACA;AACA,IAAkB,SAAS,CAAC,MAAM,GAAkC,EAAE,EAAQ;AAC9E,IAAI,KAAK,CAAC,SAAS,CAAC,EAAE,GAAG,oCAAoC,EAAE,GAAG,MAAA,EAAQ,CAAC;AAC3E;;AAEA;AACA;AACA;AACA;AACA;AACA,GAAY,IAAI,GAAuF;AACvG,IAAI,MAAM,OAAO,GAA0C,EAAE;;AAE7D,IAAI,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,0BAA0B,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;;AAErH,IAAI,OAAO,OAAO;AAClB;AACA;;;;"}