@sentry/node 10.13.0 → 10.15.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 (55) hide show
  1. package/build/cjs/index.js +18 -15
  2. package/build/cjs/index.js.map +1 -1
  3. package/build/cjs/integrations/tracing/fastify/index.js +1 -1
  4. package/build/cjs/integrations/tracing/fastify/index.js.map +1 -1
  5. package/build/cjs/integrations/tracing/firebase/firebase.js +1 -1
  6. package/build/cjs/integrations/tracing/firebase/firebase.js.map +1 -1
  7. package/build/cjs/integrations/tracing/google-genai/instrumentation.js +1 -1
  8. package/build/cjs/integrations/tracing/google-genai/instrumentation.js.map +1 -1
  9. package/build/cjs/integrations/tracing/hono/constants.js +15 -0
  10. package/build/cjs/integrations/tracing/hono/constants.js.map +1 -0
  11. package/build/cjs/integrations/tracing/hono/index.js +137 -0
  12. package/build/cjs/integrations/tracing/hono/index.js.map +1 -0
  13. package/build/cjs/integrations/tracing/hono/instrumentation.js +236 -0
  14. package/build/cjs/integrations/tracing/hono/instrumentation.js.map +1 -0
  15. package/build/cjs/integrations/tracing/index.js +15 -12
  16. package/build/cjs/integrations/tracing/index.js.map +1 -1
  17. package/build/cjs/utils/redisCache.js +2 -2
  18. package/build/cjs/utils/redisCache.js.map +1 -1
  19. package/build/esm/index.js +1 -0
  20. package/build/esm/index.js.map +1 -1
  21. package/build/esm/integrations/tracing/fastify/index.js +1 -1
  22. package/build/esm/integrations/tracing/fastify/index.js.map +1 -1
  23. package/build/esm/integrations/tracing/firebase/firebase.js +1 -1
  24. package/build/esm/integrations/tracing/firebase/firebase.js.map +1 -1
  25. package/build/esm/integrations/tracing/google-genai/instrumentation.js +1 -1
  26. package/build/esm/integrations/tracing/google-genai/instrumentation.js.map +1 -1
  27. package/build/esm/integrations/tracing/hono/constants.js +12 -0
  28. package/build/esm/integrations/tracing/hono/constants.js.map +1 -0
  29. package/build/esm/integrations/tracing/hono/index.js +133 -0
  30. package/build/esm/integrations/tracing/hono/index.js.map +1 -0
  31. package/build/esm/integrations/tracing/hono/instrumentation.js +234 -0
  32. package/build/esm/integrations/tracing/hono/instrumentation.js.map +1 -0
  33. package/build/esm/integrations/tracing/index.js +3 -0
  34. package/build/esm/integrations/tracing/index.js.map +1 -1
  35. package/build/esm/package.json +1 -1
  36. package/build/esm/utils/redisCache.js +2 -2
  37. package/build/esm/utils/redisCache.js.map +1 -1
  38. package/build/types/index.d.ts +1 -0
  39. package/build/types/index.d.ts.map +1 -1
  40. package/build/types/integrations/tracing/firebase/firebase.d.ts.map +1 -1
  41. package/build/types/integrations/tracing/hono/constants.d.ts +11 -0
  42. package/build/types/integrations/tracing/hono/constants.d.ts.map +1 -0
  43. package/build/types/integrations/tracing/hono/index.d.ts +30 -0
  44. package/build/types/integrations/tracing/hono/index.d.ts.map +1 -1
  45. package/build/types/integrations/tracing/hono/instrumentation.d.ts +29 -2
  46. package/build/types/integrations/tracing/hono/instrumentation.d.ts.map +1 -1
  47. package/build/types/integrations/tracing/hono/types.d.ts +4 -1
  48. package/build/types/integrations/tracing/hono/types.d.ts.map +1 -1
  49. package/build/types/integrations/tracing/index.d.ts.map +1 -1
  50. package/build/types-ts3.8/index.d.ts +1 -0
  51. package/build/types-ts3.8/integrations/tracing/hono/constants.d.ts +11 -0
  52. package/build/types-ts3.8/integrations/tracing/hono/index.d.ts +30 -0
  53. package/build/types-ts3.8/integrations/tracing/hono/instrumentation.d.ts +29 -2
  54. package/build/types-ts3.8/integrations/tracing/hono/types.d.ts +4 -1
  55. package/package.json +4 -4
@@ -17,6 +17,7 @@ const postgres = require('./integrations/tracing/postgres.js');
17
17
  const postgresjs = require('./integrations/tracing/postgresjs.js');
18
18
  const prisma = require('./integrations/tracing/prisma.js');
19
19
  const index$1 = require('./integrations/tracing/hapi/index.js');
20
+ const index$2 = require('./integrations/tracing/hono/index.js');
20
21
  const koa = require('./integrations/tracing/koa.js');
21
22
  const connect = require('./integrations/tracing/connect.js');
22
23
  const knex = require('./integrations/tracing/knex.js');
@@ -24,18 +25,18 @@ const tedious = require('./integrations/tracing/tedious.js');
24
25
  const genericPool = require('./integrations/tracing/genericPool.js');
25
26
  const dataloader = require('./integrations/tracing/dataloader.js');
26
27
  const amqplib = require('./integrations/tracing/amqplib.js');
27
- const index$2 = require('./integrations/tracing/vercelai/index.js');
28
- const index$3 = require('./integrations/tracing/openai/index.js');
29
- const index$4 = require('./integrations/tracing/anthropic-ai/index.js');
30
- const index$5 = require('./integrations/tracing/google-genai/index.js');
28
+ const index$3 = require('./integrations/tracing/vercelai/index.js');
29
+ const index$4 = require('./integrations/tracing/openai/index.js');
30
+ const index$5 = require('./integrations/tracing/anthropic-ai/index.js');
31
+ const index$6 = require('./integrations/tracing/google-genai/index.js');
31
32
  const launchDarkly = require('./integrations/featureFlagShims/launchDarkly.js');
32
33
  const openFeature = require('./integrations/featureFlagShims/openFeature.js');
33
34
  const statsig = require('./integrations/featureFlagShims/statsig.js');
34
35
  const unleash = require('./integrations/featureFlagShims/unleash.js');
35
36
  const firebase = require('./integrations/tracing/firebase/firebase.js');
36
- const index$6 = require('./sdk/index.js');
37
+ const index$7 = require('./sdk/index.js');
37
38
  const initOtel = require('./sdk/initOtel.js');
38
- const index$7 = require('./integrations/tracing/index.js');
39
+ const index$8 = require('./integrations/tracing/index.js');
39
40
  const opentelemetry = require('@sentry/opentelemetry');
40
41
  const core = require('@sentry/core');
41
42
  const nodeCore = require('@sentry/node-core');
@@ -63,6 +64,8 @@ exports.postgresJsIntegration = postgresjs.postgresJsIntegration;
63
64
  exports.prismaIntegration = prisma.prismaIntegration;
64
65
  exports.hapiIntegration = index$1.hapiIntegration;
65
66
  exports.setupHapiErrorHandler = index$1.setupHapiErrorHandler;
67
+ exports.honoIntegration = index$2.honoIntegration;
68
+ exports.setupHonoErrorHandler = index$2.setupHonoErrorHandler;
66
69
  exports.koaIntegration = koa.koaIntegration;
67
70
  exports.setupKoaErrorHandler = koa.setupKoaErrorHandler;
68
71
  exports.connectIntegration = connect.connectIntegration;
@@ -72,10 +75,10 @@ exports.tediousIntegration = tedious.tediousIntegration;
72
75
  exports.genericPoolIntegration = genericPool.genericPoolIntegration;
73
76
  exports.dataloaderIntegration = dataloader.dataloaderIntegration;
74
77
  exports.amqplibIntegration = amqplib.amqplibIntegration;
75
- exports.vercelAIIntegration = index$2.vercelAIIntegration;
76
- exports.openAIIntegration = index$3.openAIIntegration;
77
- exports.anthropicAIIntegration = index$4.anthropicAIIntegration;
78
- exports.googleGenAIIntegration = index$5.googleGenAIIntegration;
78
+ exports.vercelAIIntegration = index$3.vercelAIIntegration;
79
+ exports.openAIIntegration = index$4.openAIIntegration;
80
+ exports.anthropicAIIntegration = index$5.anthropicAIIntegration;
81
+ exports.googleGenAIIntegration = index$6.googleGenAIIntegration;
79
82
  exports.buildLaunchDarklyFlagUsedHandler = launchDarkly.buildLaunchDarklyFlagUsedHandlerShim;
80
83
  exports.launchDarklyIntegration = launchDarkly.launchDarklyIntegrationShim;
81
84
  exports.OpenFeatureIntegrationHook = openFeature.OpenFeatureIntegrationHookShim;
@@ -83,13 +86,13 @@ exports.openFeatureIntegration = openFeature.openFeatureIntegrationShim;
83
86
  exports.statsigIntegration = statsig.statsigIntegrationShim;
84
87
  exports.unleashIntegration = unleash.unleashIntegrationShim;
85
88
  exports.firebaseIntegration = firebase.firebaseIntegration;
86
- exports.getDefaultIntegrations = index$6.getDefaultIntegrations;
87
- exports.getDefaultIntegrationsWithoutPerformance = index$6.getDefaultIntegrationsWithoutPerformance;
88
- exports.init = index$6.init;
89
- exports.initWithoutDefaultIntegrations = index$6.initWithoutDefaultIntegrations;
89
+ exports.getDefaultIntegrations = index$7.getDefaultIntegrations;
90
+ exports.getDefaultIntegrationsWithoutPerformance = index$7.getDefaultIntegrationsWithoutPerformance;
91
+ exports.init = index$7.init;
92
+ exports.initWithoutDefaultIntegrations = index$7.initWithoutDefaultIntegrations;
90
93
  exports.initOpenTelemetry = initOtel.initOpenTelemetry;
91
94
  exports.preloadOpenTelemetry = initOtel.preloadOpenTelemetry;
92
- exports.getAutoPerformanceIntegrations = index$7.getAutoPerformanceIntegrations;
95
+ exports.getAutoPerformanceIntegrations = index$8.getAutoPerformanceIntegrations;
93
96
  exports.setNodeAsyncContextStrategy = opentelemetry.setOpenTelemetryContextAsyncContextStrategy;
94
97
  exports.SDK_VERSION = core.SDK_VERSION;
95
98
  exports.SEMANTIC_ATTRIBUTE_SENTRY_OP = core.SEMANTIC_ATTRIBUTE_SENTRY_OP;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -42,7 +42,7 @@ function getFastifyIntegration() {
42
42
  if (!client) {
43
43
  return undefined;
44
44
  } else {
45
- return client.getIntegrationByName(INTEGRATION_NAME) ;
45
+ return client.getIntegrationByName(INTEGRATION_NAME);
46
46
  }
47
47
  }
48
48
 
@@ -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\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';\n\nexport const instrumentFastifyV3 = generateInstrumentOnce(\n `${INTEGRATION_NAME}.v3`,\n () => new FastifyInstrumentationV3(),\n);\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: 'auto.function.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":["generateInstrumentOnce","FastifyInstrumentationV3","getClient","DEBUG_BUILD","debug","captureException","FastifyOtelInstrumentation","diagnosticsChannel","defineIntegration","spanToJSON","SEMANTIC_ATTRIBUTE_SENTRY_OP","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","getIsolationScope"],"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;;AAE3B,MAAM,mBAAA,GAAsBA,+BAAsB;AACzD,EAAE,CAAC,EAAA,gBAAA,CAAA,GAAA,CAAA;AACA,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ACA;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,IAAAU,sBAAA,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';\n\nexport const instrumentFastifyV3 = generateInstrumentOnce(\n `${INTEGRATION_NAME}.v3`,\n () => new FastifyInstrumentationV3(),\n);\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);\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: 'auto.function.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":["generateInstrumentOnce","FastifyInstrumentationV3","getClient","DEBUG_BUILD","debug","captureException","FastifyOtelInstrumentation","diagnosticsChannel","defineIntegration","spanToJSON","SEMANTIC_ATTRIBUTE_SENTRY_OP","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","getIsolationScope"],"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;;AAE3B,MAAM,mBAAA,GAAsBA,+BAAsB;AACzD,EAAE,CAAC,EAAA,gBAAA,CAAA,GAAA,CAAA;AACA,EAAA,MAAA,IAAAC,wCAAA,EAAA;AACA;;AAEA,SAAA,qBAAA,GAAA;AACA,EAAA,MAAA,MAAA,GAAAC,cAAA,EAAA;AACA,EAAA,IAAA,CAAA,MAAA,EAAA;AACA,IAAA,OAAA,SAAA;AACA,GAAA,MAAA;AACA,IAAA,OAAA,MAAA,CAAA,oBAAA,CAAA,gBAAA,CAAA;AACA;AACA;;AAEA,SAAA,kBAAA;;AAIA,EAAA,KAAA;AACA,EAAA,OAAA;AACA,EAAA,KAAA;AACA,EAAA,aAAA;AACA,EAAA;AACA,EAAA,MAAA,iBAAA,GAAA,qBAAA,EAAA,EAAA,oBAAA,EAAA,IAAA,wBAAA;AACA;AACA,EAAA,IAAA,aAAA,KAAA,qBAAA,EAAA;AACA,IAAA,IAAA,CAAA,wBAAA,GAAA,IAAA;AACA;;AAEA,EAAA,IAAA,IAAA,C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A,CAAA;AACA;;;;;;;"}
@@ -8,7 +8,7 @@ const INTEGRATION_NAME = 'Firebase';
8
8
 
9
9
  const config = {
10
10
  firestoreSpanCreationHook: span => {
11
- nodeCore.addOriginToSpan(span , 'auto.firebase.otel.firestore');
11
+ nodeCore.addOriginToSpan(span, 'auto.firebase.otel.firestore');
12
12
 
13
13
  span.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_OP, 'db.query');
14
14
  },
@@ -1 +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":["addOriginToSpan","SEMANTIC_ATTRIBUTE_SENTRY_OP","generateInstrumentOnce","FirebaseInstrumentation","defineIntegration"],"mappings":";;;;;;AAMA,MAAM,gBAAA,GAAmB,UAAU;;AAEnC,MAAM,MAAM,GAAkC;AAC9C,EAAE,yBAAyB,EAAE,IAAA,IAAQ;AACrC,IAAIA,wBAAe,CAAC,IAAA,GAAc,8BAA8B,CAAC;;AAEjE,IAAI,IAAI,CAAC,YAAY,CAACC,iCAA4B,EAAE,UAAU,CAAC;AAC/D,GAAG;AACH,CAAC;;AAEM,MAAM,kBAAA,GAAqBC,+BAAsB,CAAC,gBAAgB,EAAE,MAAM,IAAIC,+CAAuB,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,GAAsBC,sBAAiB,CAAC,oBAAoB;;;;;"}
1
+ {"version":3,"file":"firebase.js","sources":["../../../../../src/integrations/tracing/firebase/firebase.ts"],"sourcesContent":["import 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, '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":["addOriginToSpan","SEMANTIC_ATTRIBUTE_SENTRY_OP","generateInstrumentOnce","FirebaseInstrumentation","defineIntegration"],"mappings":";;;;;;AAKA,MAAM,gBAAA,GAAmB,UAAU;;AAEnC,MAAM,MAAM,GAAkC;AAC9C,EAAE,yBAAyB,EAAE,IAAA,IAAQ;AACrC,IAAIA,wBAAe,CAAC,IAAI,EAAE,8BAA8B,CAAC;;AAEzD,IAAI,IAAI,CAAC,YAAY,CAACC,iCAA4B,EAAE,UAAU,CAAC;AAC/D,GAAG;AACH,CAAC;;AAEM,MAAM,kBAAA,GAAqBC,+BAAsB,CAAC,gBAAgB,EAAE,MAAM,IAAIC,+CAAuB,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,GAAsBC,sBAAiB,CAAC,oBAAoB;;;;;"}
@@ -58,7 +58,7 @@ class SentryGoogleGenAiInstrumentation extends instrumentation.InstrumentationBa
58
58
  const client = core.getClient();
59
59
  const defaultPii = Boolean(client?.getOptions().sendDefaultPii);
60
60
 
61
- const typedConfig = config ;
61
+ const typedConfig = config;
62
62
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
63
63
  const recordInputs = typedConfig?.recordInputs ?? defaultPii;
64
64
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
@@ -1 +1 @@
1
- {"version":3,"file":"instrumentation.js","sources":["../../../../../src/integrations/tracing/google-genai/instrumentation.ts"],"sourcesContent":["import type { InstrumentationConfig } from '@opentelemetry/instrumentation';\nimport {\n type InstrumentationModuleDefinition,\n InstrumentationBase,\n InstrumentationNodeModuleDefinition,\n InstrumentationNodeModuleFile,\n} from '@opentelemetry/instrumentation';\nimport type { GoogleGenAIClient, GoogleGenAIOptions } from '@sentry/core';\nimport { getClient, instrumentGoogleGenAIClient, replaceExports, SDK_VERSION } from '@sentry/core';\n\nconst supportedVersions = ['>=0.10.0 <2'];\n\n/**\n * Represents the patched shape of the Google GenAI module export.\n */\ninterface PatchedModuleExports {\n [key: string]: unknown;\n GoogleGenAI?: unknown;\n}\n\ntype GoogleGenAIInstrumentationOptions = GoogleGenAIOptions & InstrumentationConfig;\n\n/**\n * Sentry Google GenAI instrumentation using OpenTelemetry.\n */\nexport class SentryGoogleGenAiInstrumentation extends InstrumentationBase<GoogleGenAIInstrumentationOptions> {\n public constructor(config: GoogleGenAIInstrumentationOptions = {}) {\n super('@sentry/instrumentation-google-genai', 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(\n '@google/genai',\n supportedVersions,\n exports => this._patch(exports),\n exports => exports,\n // In CJS, @google/genai re-exports from (dist/node/index.cjs) file.\n // Patching only the root module sometimes misses the real implementation or\n // gets overwritten when that file is loaded. We add a file-level patch so that\n // _patch runs again on the concrete implementation\n [\n new InstrumentationNodeModuleFile(\n '@google/genai/dist/node/index.cjs',\n supportedVersions,\n exports => this._patch(exports),\n exports => exports,\n ),\n ],\n );\n return module;\n }\n\n /**\n * Core patch logic applying instrumentation to the Google GenAI client constructor.\n */\n private _patch(exports: PatchedModuleExports): PatchedModuleExports | void {\n const Original = exports.GoogleGenAI;\n const config = this.getConfig();\n\n if (typeof Original !== 'function') {\n return exports;\n }\n\n const WrappedGoogleGenAI = function (this: unknown, ...args: unknown[]): GoogleGenAIClient {\n const instance = Reflect.construct(Original, args);\n const client = getClient();\n const defaultPii = Boolean(client?.getOptions().sendDefaultPii);\n\n const typedConfig = config as GoogleGenAIInstrumentationOptions;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const recordInputs = typedConfig?.recordInputs ?? defaultPii;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const recordOutputs = typedConfig?.recordOutputs ?? defaultPii;\n\n return instrumentGoogleGenAIClient(instance, {\n recordInputs,\n recordOutputs,\n });\n };\n\n // Preserve static and prototype chains\n Object.setPrototypeOf(WrappedGoogleGenAI, Original);\n Object.setPrototypeOf(WrappedGoogleGenAI.prototype, Original.prototype);\n\n for (const key of Object.getOwnPropertyNames(Original)) {\n if (!['length', 'name', 'prototype'].includes(key)) {\n const descriptor = Object.getOwnPropertyDescriptor(Original, key);\n if (descriptor) {\n Object.defineProperty(WrappedGoogleGenAI, key, descriptor);\n }\n }\n }\n\n // Replace google genai exports with the wrapped constructor\n replaceExports(exports, 'GoogleGenAI', WrappedGoogleGenAI);\n\n return exports;\n }\n}\n"],"names":["InstrumentationBase","SDK_VERSION","InstrumentationNodeModuleDefinition","InstrumentationNodeModuleFile","getClient","instrumentGoogleGenAIClient","replaceExports"],"mappings":";;;;;AAUA,MAAM,iBAAA,GAAoB,CAAC,aAAa,CAAC;;AAEzC;AACA;AACA;;AAQA;AACA;AACA;AACO,MAAM,gCAAA,SAAyCA,mCAAmB,CAAoC;AAC7G,GAAS,WAAW,CAAC,MAAM,GAAsC,EAAE,EAAE;AACrE,IAAI,KAAK,CAAC,sCAAsC,EAAEC,gBAAW,EAAE,MAAM,CAAC;AACtE;;AAEA;AACA;AACA;AACA,GAAS,IAAI,GAAoC;AACjD,IAAI,MAAM,MAAA,GAAS,IAAIC,mDAAmC;AAC1D,MAAM,eAAe;AACrB,MAAM,iBAAiB;AACvB,MAAM,WAAW,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;AACrC,MAAM,OAAA,IAAW,OAAO;AACxB;AACA;AACA;AACA;AACA,MAAM;AACN,QAAQ,IAAIC,6CAA6B;AACzC,UAAU,mCAAmC;AAC7C,UAAU,iBAAiB;AAC3B,UAAU,WAAW,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;AACzC,UAAU,OAAA,IAAW,OAAO;AAC5B,SAAS;AACT,OAAO;AACP,KAAK;AACL,IAAI,OAAO,MAAM;AACjB;;AAEA;AACA;AACA;AACA,GAAU,MAAM,CAAC,OAAO,EAAqD;AAC7E,IAAI,MAAM,QAAA,GAAW,OAAO,CAAC,WAAW;AACxC,IAAI,MAAM,MAAA,GAAS,IAAI,CAAC,SAAS,EAAE;;AAEnC,IAAI,IAAI,OAAO,QAAA,KA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I,OAAO,OAAO;AAClB;AACA;;;;"}
1
+ {"version":3,"file":"instrumentation.js","sources":["../../../../../src/integrations/tracing/google-genai/instrumentation.ts"],"sourcesContent":["import type { InstrumentationConfig } from '@opentelemetry/instrumentation';\nimport {\n type InstrumentationModuleDefinition,\n InstrumentationBase,\n InstrumentationNodeModuleDefinition,\n InstrumentationNodeModuleFile,\n} from '@opentelemetry/instrumentation';\nimport type { GoogleGenAIClient, GoogleGenAIOptions } from '@sentry/core';\nimport { getClient, instrumentGoogleGenAIClient, replaceExports, SDK_VERSION } from '@sentry/core';\n\nconst supportedVersions = ['>=0.10.0 <2'];\n\n/**\n * Represents the patched shape of the Google GenAI module export.\n */\ninterface PatchedModuleExports {\n [key: string]: unknown;\n GoogleGenAI?: unknown;\n}\n\ntype GoogleGenAIInstrumentationOptions = GoogleGenAIOptions & InstrumentationConfig;\n\n/**\n * Sentry Google GenAI instrumentation using OpenTelemetry.\n */\nexport class SentryGoogleGenAiInstrumentation extends InstrumentationBase<GoogleGenAIInstrumentationOptions> {\n public constructor(config: GoogleGenAIInstrumentationOptions = {}) {\n super('@sentry/instrumentation-google-genai', 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(\n '@google/genai',\n supportedVersions,\n exports => this._patch(exports),\n exports => exports,\n // In CJS, @google/genai re-exports from (dist/node/index.cjs) file.\n // Patching only the root module sometimes misses the real implementation or\n // gets overwritten when that file is loaded. We add a file-level patch so that\n // _patch runs again on the concrete implementation\n [\n new InstrumentationNodeModuleFile(\n '@google/genai/dist/node/index.cjs',\n supportedVersions,\n exports => this._patch(exports),\n exports => exports,\n ),\n ],\n );\n return module;\n }\n\n /**\n * Core patch logic applying instrumentation to the Google GenAI client constructor.\n */\n private _patch(exports: PatchedModuleExports): PatchedModuleExports | void {\n const Original = exports.GoogleGenAI;\n const config = this.getConfig();\n\n if (typeof Original !== 'function') {\n return exports;\n }\n\n const WrappedGoogleGenAI = function (this: unknown, ...args: unknown[]): GoogleGenAIClient {\n const instance = Reflect.construct(Original, args);\n const client = getClient();\n const defaultPii = Boolean(client?.getOptions().sendDefaultPii);\n\n const typedConfig = config;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const recordInputs = typedConfig?.recordInputs ?? defaultPii;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const recordOutputs = typedConfig?.recordOutputs ?? defaultPii;\n\n return instrumentGoogleGenAIClient(instance, {\n recordInputs,\n recordOutputs,\n });\n };\n\n // Preserve static and prototype chains\n Object.setPrototypeOf(WrappedGoogleGenAI, Original);\n Object.setPrototypeOf(WrappedGoogleGenAI.prototype, Original.prototype);\n\n for (const key of Object.getOwnPropertyNames(Original)) {\n if (!['length', 'name', 'prototype'].includes(key)) {\n const descriptor = Object.getOwnPropertyDescriptor(Original, key);\n if (descriptor) {\n Object.defineProperty(WrappedGoogleGenAI, key, descriptor);\n }\n }\n }\n\n // Replace google genai exports with the wrapped constructor\n replaceExports(exports, 'GoogleGenAI', WrappedGoogleGenAI);\n\n return exports;\n }\n}\n"],"names":["InstrumentationBase","SDK_VERSION","InstrumentationNodeModuleDefinition","InstrumentationNodeModuleFile","getClient","instrumentGoogleGenAIClient","replaceExports"],"mappings":";;;;;AAUA,MAAM,iBAAA,GAAoB,CAAC,aAAa,CAAC;;AAEzC;AACA;AACA;;AAQA;AACA;AACA;AACO,MAAM,gCAAA,SAAyCA,mCAAmB,CAAoC;AAC7G,GAAS,WAAW,CAAC,MAAM,GAAsC,EAAE,EAAE;AACrE,IAAI,KAAK,CAAC,sCAAsC,EAAEC,gBAAW,EAAE,MAAM,CAAC;AACtE;;AAEA;AACA;AACA;AACA,GAAS,IAAI,GAAoC;AACjD,IAAI,MAAM,MAAA,GAAS,IAAIC,mDAAmC;AAC1D,MAAM,eAAe;AACrB,MAAM,iBAAiB;AACvB,MAAM,WAAW,IAAI,CAAC,MAAM,CAAC,OA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;;AAE3E,IAAI,KAAK,MAAM,GAAA,IAAO,MAAM,CAAC,mBAAmB,CAAC,QAAQ,CAAC,EAAE;AAC5D,MAAM,IAAI,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;AAC1D,QAAQ,MAAM,UAAA,GAAa,MAAM,CAAC,wBAAwB,CAAC,QAAQ,EAAE,GAAG,CAAC;AACzE,QAAQ,IAAI,UAAU,EAAE;AACxB,UAAU,MAAM,CAAC,cAAc,CAAC,kBAAkB,EAAE,GAAG,EAAE,UAAU,CAAC;AACpE;AACA;AACA;;AAEA;AACA,IAAIC,mBAAc,CAAC,OAAO,EAAE,aAAa,EAAE,kBAAkB,CAAC;;AAE9D,IAAI,OAAO,OAAO;AAClB;AACA;;;;"}
@@ -0,0 +1,15 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ const AttributeNames = {
4
+ HONO_TYPE: 'hono.type',
5
+ HONO_NAME: 'hono.name',
6
+ } ;
7
+
8
+ const HonoTypes = {
9
+ MIDDLEWARE: 'middleware',
10
+ REQUEST_HANDLER: 'request_handler',
11
+ } ;
12
+
13
+ exports.AttributeNames = AttributeNames;
14
+ exports.HonoTypes = HonoTypes;
15
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sources":["../../../../../src/integrations/tracing/hono/constants.ts"],"sourcesContent":["export const AttributeNames = {\n HONO_TYPE: 'hono.type',\n HONO_NAME: 'hono.name',\n} as const;\n\nexport type AttributeNames = (typeof AttributeNames)[keyof typeof AttributeNames];\n\nexport const HonoTypes = {\n MIDDLEWARE: 'middleware',\n REQUEST_HANDLER: 'request_handler',\n} as const;\n\nexport type HonoTypes = (typeof HonoTypes)[keyof typeof HonoTypes];\n"],"names":[],"mappings":";;AAAO,MAAM,iBAAiB;AAC9B,EAAE,SAAS,EAAE,WAAW;AACxB,EAAE,SAAS,EAAE,WAAW;AACxB,CAAA;;AAIO,MAAM,YAAY;AACzB,EAAE,UAAU,EAAE,YAAY;AAC1B,EAAE,eAAe,EAAE,iBAAiB;AACpC,CAAA;;;;;"}
@@ -0,0 +1,137 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ const semanticConventions = require('@opentelemetry/semantic-conventions');
4
+ const core = require('@sentry/core');
5
+ const nodeCore = require('@sentry/node-core');
6
+ const debugBuild = require('../../../debug-build.js');
7
+ const constants = require('./constants.js');
8
+ const instrumentation = require('./instrumentation.js');
9
+
10
+ const INTEGRATION_NAME = 'Hono';
11
+
12
+ function addHonoSpanAttributes(span) {
13
+ const attributes = core.spanToJSON(span).data;
14
+ const type = attributes[constants.AttributeNames.HONO_TYPE];
15
+ if (attributes[core.SEMANTIC_ATTRIBUTE_SENTRY_OP] || !type) {
16
+ return;
17
+ }
18
+
19
+ span.setAttributes({
20
+ [core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.otel.hono',
21
+ [core.SEMANTIC_ATTRIBUTE_SENTRY_OP]: `${type}.hono`,
22
+ });
23
+
24
+ const name = attributes[constants.AttributeNames.HONO_NAME];
25
+ if (typeof name === 'string') {
26
+ span.updateName(name);
27
+ }
28
+
29
+ if (core.getIsolationScope() === core.getDefaultIsolationScope()) {
30
+ debugBuild.DEBUG_BUILD && core.debug.warn('Isolation scope is default isolation scope - skipping setting transactionName');
31
+ return;
32
+ }
33
+
34
+ const route = attributes[semanticConventions.ATTR_HTTP_ROUTE];
35
+ const method = attributes[semanticConventions.ATTR_HTTP_REQUEST_METHOD];
36
+ if (typeof route === 'string' && typeof method === 'string') {
37
+ core.getIsolationScope().setTransactionName(`${method} ${route}`);
38
+ }
39
+ }
40
+
41
+ const instrumentHono = nodeCore.generateInstrumentOnce(
42
+ INTEGRATION_NAME,
43
+ () =>
44
+ new instrumentation.HonoInstrumentation({
45
+ responseHook: span => {
46
+ addHonoSpanAttributes(span);
47
+ },
48
+ }),
49
+ );
50
+
51
+ const _honoIntegration = (() => {
52
+ return {
53
+ name: INTEGRATION_NAME,
54
+ setupOnce() {
55
+ instrumentHono();
56
+ },
57
+ };
58
+ }) ;
59
+
60
+ /**
61
+ * Adds Sentry tracing instrumentation for [Hono](https://hono.dev/).
62
+ *
63
+ * If you also want to capture errors, you need to call `setupHonoErrorHandler(app)` after you set up your Hono server.
64
+ *
65
+ * For more information, see the [hono documentation](https://docs.sentry.io/platforms/javascript/guides/hono/).
66
+ *
67
+ * @example
68
+ * ```javascript
69
+ * const Sentry = require('@sentry/node');
70
+ *
71
+ * Sentry.init({
72
+ * integrations: [Sentry.honoIntegration()],
73
+ * })
74
+ * ```
75
+ */
76
+ const honoIntegration = core.defineIntegration(_honoIntegration);
77
+
78
+ function honoRequestHandler() {
79
+ return async function sentryRequestMiddleware(context, next) {
80
+ const normalizedRequest = core.httpRequestToRequestData(context.req);
81
+ core.getIsolationScope().setSDKProcessingMetadata({ normalizedRequest });
82
+ await next();
83
+ };
84
+ }
85
+
86
+ function defaultShouldHandleError(context) {
87
+ const statusCode = context.res.status;
88
+ return statusCode >= 500;
89
+ }
90
+
91
+ function honoErrorHandler(options) {
92
+ return async function sentryErrorMiddleware(context, next) {
93
+ await next();
94
+
95
+ const shouldHandleError = options?.shouldHandleError || defaultShouldHandleError;
96
+ if (shouldHandleError(context)) {
97
+ (context.res ).sentry = core.captureException(context.error, {
98
+ mechanism: {
99
+ type: 'auto.middleware.hono',
100
+ handled: false,
101
+ },
102
+ });
103
+ }
104
+ };
105
+ }
106
+
107
+ /**
108
+ * Add a Hono error handler to capture errors to Sentry.
109
+ *
110
+ * @param app The Hono instances
111
+ * @param options Configuration options for the handler
112
+ *
113
+ * @example
114
+ * ```javascript
115
+ * const Sentry = require('@sentry/node');
116
+ * const { Hono } = require("hono");
117
+ *
118
+ * const app = new Hono();
119
+ *
120
+ * Sentry.setupHonoErrorHandler(app);
121
+ *
122
+ * // Add your routes, etc.
123
+ * ```
124
+ */
125
+ function setupHonoErrorHandler(
126
+ app,
127
+ options,
128
+ ) {
129
+ app.use(honoRequestHandler());
130
+ app.use(honoErrorHandler(options));
131
+ nodeCore.ensureIsWrapped(app.use, 'hono');
132
+ }
133
+
134
+ exports.honoIntegration = honoIntegration;
135
+ exports.instrumentHono = instrumentHono;
136
+ exports.setupHonoErrorHandler = setupHonoErrorHandler;
137
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../../../src/integrations/tracing/hono/index.ts"],"sourcesContent":["import { ATTR_HTTP_REQUEST_METHOD, ATTR_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';\nimport type { IntegrationFn, Span } from '@sentry/core';\nimport {\n captureException,\n debug,\n defineIntegration,\n getDefaultIsolationScope,\n getIsolationScope,\n httpRequestToRequestData,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n spanToJSON,\n} from '@sentry/core';\nimport { ensureIsWrapped, generateInstrumentOnce } from '@sentry/node-core';\nimport { DEBUG_BUILD } from '../../../debug-build';\nimport { AttributeNames } from './constants';\nimport { HonoInstrumentation } from './instrumentation';\nimport type { Context, MiddlewareHandler, MiddlewareHandlerInterface, Next } from './types';\n\nconst INTEGRATION_NAME = 'Hono';\n\nfunction addHonoSpanAttributes(span: Span): void {\n const attributes = spanToJSON(span).data;\n const type = attributes[AttributeNames.HONO_TYPE];\n if (attributes[SEMANTIC_ATTRIBUTE_SENTRY_OP] || !type) {\n return;\n }\n\n span.setAttributes({\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.otel.hono',\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: `${type}.hono`,\n });\n\n const name = attributes[AttributeNames.HONO_NAME];\n if (typeof name === 'string') {\n span.updateName(name);\n }\n\n if (getIsolationScope() === getDefaultIsolationScope()) {\n DEBUG_BUILD && debug.warn('Isolation scope is default isolation scope - skipping setting transactionName');\n return;\n }\n\n const route = attributes[ATTR_HTTP_ROUTE];\n const method = attributes[ATTR_HTTP_REQUEST_METHOD];\n if (typeof route === 'string' && typeof method === 'string') {\n getIsolationScope().setTransactionName(`${method} ${route}`);\n }\n}\n\nexport const instrumentHono = generateInstrumentOnce(\n INTEGRATION_NAME,\n () =>\n new HonoInstrumentation({\n responseHook: span => {\n addHonoSpanAttributes(span);\n },\n }),\n);\n\nconst _honoIntegration = (() => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n instrumentHono();\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Adds Sentry tracing instrumentation for [Hono](https://hono.dev/).\n *\n * If you also want to capture errors, you need to call `setupHonoErrorHandler(app)` after you set up your Hono server.\n *\n * For more information, see the [hono documentation](https://docs.sentry.io/platforms/javascript/guides/hono/).\n *\n * @example\n * ```javascript\n * const Sentry = require('@sentry/node');\n *\n * Sentry.init({\n * integrations: [Sentry.honoIntegration()],\n * })\n * ```\n */\nexport const honoIntegration = defineIntegration(_honoIntegration);\n\ninterface HonoHandlerOptions {\n /**\n * Callback method deciding whether error should be captured and sent to Sentry\n * @param error Captured Hono error\n */\n shouldHandleError: (context: Context) => boolean;\n}\n\nfunction honoRequestHandler(): MiddlewareHandler {\n return async function sentryRequestMiddleware(context: Context, next: Next): Promise<void> {\n const normalizedRequest = httpRequestToRequestData(context.req);\n getIsolationScope().setSDKProcessingMetadata({ normalizedRequest });\n await next();\n };\n}\n\nfunction defaultShouldHandleError(context: Context): boolean {\n const statusCode = context.res.status;\n return statusCode >= 500;\n}\n\nfunction honoErrorHandler(options?: Partial<HonoHandlerOptions>): MiddlewareHandler {\n return async function sentryErrorMiddleware(context: Context, next: Next): Promise<void> {\n await next();\n\n const shouldHandleError = options?.shouldHandleError || defaultShouldHandleError;\n if (shouldHandleError(context)) {\n (context.res as { sentry?: string }).sentry = captureException(context.error, {\n mechanism: {\n type: 'auto.middleware.hono',\n handled: false,\n },\n });\n }\n };\n}\n\n/**\n * Add a Hono error handler to capture errors to Sentry.\n *\n * @param app The Hono instances\n * @param options Configuration options for the handler\n *\n * @example\n * ```javascript\n * const Sentry = require('@sentry/node');\n * const { Hono } = require(\"hono\");\n *\n * const app = new Hono();\n *\n * Sentry.setupHonoErrorHandler(app);\n *\n * // Add your routes, etc.\n * ```\n */\nexport function setupHonoErrorHandler(\n app: { use: MiddlewareHandlerInterface },\n options?: Partial<HonoHandlerOptions>,\n): void {\n app.use(honoRequestHandler());\n app.use(honoErrorHandler(options));\n ensureIsWrapped(app.use, 'hono');\n}\n"],"names":["spanToJSON","AttributeNames","SEMANTIC_ATTRIBUTE_SENTRY_OP","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","getIsolationScope","getDefaultIsolationScope","DEBUG_BUILD","debug","ATTR_HTTP_ROUTE","ATTR_HTTP_REQUEST_METHOD","generateInstrumentOnce","HonoInstrumentation","defineIntegration","httpRequestToRequestData","captureException","ensureIsWrapped"],"mappings":";;;;;;;;;AAmBA,MAAM,gBAAA,GAAmB,MAAM;;AAE/B,SAAS,qBAAqB,CAAC,IAAI,EAAc;AACjD,EAAE,MAAM,aAAaA,eAAU,CAAC,IAAI,CAAC,CAAC,IAAI;AAC1C,EAAE,MAAM,OAAO,UAAU,CAACC,wBAAc,CAAC,SAAS,CAAC;AACnD,EAAE,IAAI,UAAU,CAACC,iCAA4B,CAAA,IAAK,CAAC,IAAI,EAAE;AACzD,IAAI;AACJ;;AAEA,EAAE,IAAI,CAAC,aAAa,CAAC;AACrB,IAAI,CAACC,qCAAgC,GAAG,qBAAqB;AAC7D,IAAI,CAACD,iCAA4B,GAAG,CAAC,EAAA,IAAA,CAAA,KAAA,CAAA;AACA,GAAA,CAAA;;AAEA,EAAA,MAAA,IAAA,GAAA,UAAA,CAAAD,wBAAA,CAAA,SAAA,CAAA;AACA,EAAA,IAAA,OAAA,IAAA,KAAA,QAAA,EAAA;AACA,IAAA,IAAA,CAAA,UAAA,CAAA,IAAA,CAAA;AACA;;AAEA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ACA,EAAA,MAAA,UAAA,GAAA,OAAA,CAAA,GAAA,CAAA,MAAA;AACA,EAAA,OAAA,UAAA,IAAA,GAAA;AACA;;AAEA,SAAA,gBAAA,CAAA,OAAA,EAAA;AACA,EAAA,OAAA,eAAA,qBAAA,CAAA,OAAA,EAAA,IAAA,EAAA;AACA,IAAA,MAAA,IAAA,EAAA;;AAEA,IAAA,MAAA,iBAAA,GAAA,OAAA,EAAA,iBAAA,IAAA,wBAAA;AACA,IAAA,IAAA,iBAAA,CAAA,OAAA,CAAA,EAAA;AACA,MAAA,CAAA,OAAA,CAAA,GAAA,GAAA,MAAA,GAAAU,qBAAA,CAAA,OAAA,CAAA,KAAA,EAAA;AACA,QAAA,SAAA,EAAA;AACA,UAAA,IAAA,EAAA,sBAAA;AACA,UAAA,OAAA,EAAA,KAAA;AACA,SAAA;AACA,OAAA,CAAA;AACA;AACA,GAAA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAA,qBAAA;AACA,EAAA,GAAA;AACA,EAAA,OAAA;AACA,EAAA;AACA,EAAA,GAAA,CAAA,GAAA,CAAA,kBAAA,EAAA,CAAA;AACA,EAAA,GAAA,CAAA,GAAA,CAAA,gBAAA,CAAA,OAAA,CAAA,CAAA;AACA,EAAAC,wBAAA,CAAA,GAAA,CAAA,GAAA,EAAA,MAAA,CAAA;AACA;;;;;;"}
@@ -0,0 +1,236 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ const api = require('@opentelemetry/api');
4
+ const instrumentation = require('@opentelemetry/instrumentation');
5
+ const core = require('@sentry/core');
6
+ const constants = require('./constants.js');
7
+
8
+ const PACKAGE_NAME = '@sentry/instrumentation-hono';
9
+ const PACKAGE_VERSION = '0.0.1';
10
+
11
+ /**
12
+ * Hono instrumentation for OpenTelemetry
13
+ */
14
+ class HonoInstrumentation extends instrumentation.InstrumentationBase {
15
+ constructor(config = {}) {
16
+ super(PACKAGE_NAME, PACKAGE_VERSION, config);
17
+ }
18
+
19
+ /**
20
+ * Initialize the instrumentation.
21
+ */
22
+ init() {
23
+ return [
24
+ new instrumentation.InstrumentationNodeModuleDefinition('hono', ['>=4.0.0 <5'], moduleExports => this._patch(moduleExports)),
25
+ ];
26
+ }
27
+
28
+ /**
29
+ * Patches the module exports to instrument Hono.
30
+ */
31
+ _patch(moduleExports) {
32
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
33
+ const instrumentation = this;
34
+
35
+ class WrappedHono extends moduleExports.Hono {
36
+ constructor(...args) {
37
+ super(...args);
38
+
39
+ instrumentation._wrap(this, 'get', instrumentation._patchHandler());
40
+ instrumentation._wrap(this, 'post', instrumentation._patchHandler());
41
+ instrumentation._wrap(this, 'put', instrumentation._patchHandler());
42
+ instrumentation._wrap(this, 'delete', instrumentation._patchHandler());
43
+ instrumentation._wrap(this, 'options', instrumentation._patchHandler());
44
+ instrumentation._wrap(this, 'patch', instrumentation._patchHandler());
45
+ instrumentation._wrap(this, 'all', instrumentation._patchHandler());
46
+ instrumentation._wrap(this, 'on', instrumentation._patchOnHandler());
47
+ instrumentation._wrap(this, 'use', instrumentation._patchMiddlewareHandler());
48
+ }
49
+ }
50
+
51
+ try {
52
+ moduleExports.Hono = WrappedHono;
53
+ } catch {
54
+ // This is a workaround for environments where direct assignment is not allowed.
55
+ return { ...moduleExports, Hono: WrappedHono };
56
+ }
57
+
58
+ return moduleExports;
59
+ }
60
+
61
+ /**
62
+ * Patches the route handler to instrument it.
63
+ */
64
+ _patchHandler() {
65
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
66
+ const instrumentation = this;
67
+
68
+ return function (original) {
69
+ return function wrappedHandler( ...args) {
70
+ if (typeof args[0] === 'string') {
71
+ const path = args[0];
72
+ if (args.length === 1) {
73
+ return original.apply(this, [path]);
74
+ }
75
+
76
+ const handlers = args.slice(1);
77
+ return original.apply(this, [
78
+ path,
79
+ ...handlers.map(handler => instrumentation._wrapHandler(handler )),
80
+ ]);
81
+ }
82
+
83
+ return original.apply(
84
+ this,
85
+ args.map(handler => instrumentation._wrapHandler(handler )),
86
+ );
87
+ };
88
+ };
89
+ }
90
+
91
+ /**
92
+ * Patches the 'on' handler to instrument it.
93
+ */
94
+ _patchOnHandler() {
95
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
96
+ const instrumentation = this;
97
+
98
+ return function (original) {
99
+ return function wrappedHandler( ...args) {
100
+ const handlers = args.slice(2);
101
+ return original.apply(this, [
102
+ ...args.slice(0, 2),
103
+ ...handlers.map(handler => instrumentation._wrapHandler(handler )),
104
+ ]);
105
+ };
106
+ };
107
+ }
108
+
109
+ /**
110
+ * Patches the middleware handler to instrument it.
111
+ */
112
+ _patchMiddlewareHandler() {
113
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
114
+ const instrumentation = this;
115
+
116
+ return function (original) {
117
+ return function wrappedHandler( ...args) {
118
+ if (typeof args[0] === 'string') {
119
+ const path = args[0];
120
+ if (args.length === 1) {
121
+ return original.apply(this, [path]);
122
+ }
123
+
124
+ const handlers = args.slice(1);
125
+ return original.apply(this, [
126
+ path,
127
+ ...handlers.map(handler => instrumentation._wrapHandler(handler )),
128
+ ]);
129
+ }
130
+
131
+ return original.apply(
132
+ this,
133
+ args.map(handler => instrumentation._wrapHandler(handler )),
134
+ );
135
+ };
136
+ };
137
+ }
138
+
139
+ /**
140
+ * Wraps a handler or middleware handler to apply instrumentation.
141
+ */
142
+ _wrapHandler(handler) {
143
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
144
+ const instrumentation = this;
145
+
146
+ return function ( c, next) {
147
+ if (!instrumentation.isEnabled()) {
148
+ return handler.apply(this, [c, next]);
149
+ }
150
+
151
+ const path = c.req.path;
152
+ const span = instrumentation.tracer.startSpan(path);
153
+
154
+ return api.context.with(api.trace.setSpan(api.context.active(), span), () => {
155
+ return instrumentation._safeExecute(
156
+ () => {
157
+ const result = handler.apply(this, [c, next]);
158
+ if (core.isThenable(result)) {
159
+ return result.then(result => {
160
+ const type = instrumentation._determineHandlerType(result);
161
+ span.setAttributes({
162
+ [constants.AttributeNames.HONO_TYPE]: type,
163
+ [constants.AttributeNames.HONO_NAME]: type === constants.HonoTypes.REQUEST_HANDLER ? path : handler.name || 'anonymous',
164
+ });
165
+ instrumentation.getConfig().responseHook?.(span);
166
+ return result;
167
+ });
168
+ } else {
169
+ const type = instrumentation._determineHandlerType(result);
170
+ span.setAttributes({
171
+ [constants.AttributeNames.HONO_TYPE]: type,
172
+ [constants.AttributeNames.HONO_NAME]: type === constants.HonoTypes.REQUEST_HANDLER ? path : handler.name || 'anonymous',
173
+ });
174
+ instrumentation.getConfig().responseHook?.(span);
175
+ return result;
176
+ }
177
+ },
178
+ () => span.end(),
179
+ error => {
180
+ instrumentation._handleError(span, error);
181
+ span.end();
182
+ },
183
+ );
184
+ });
185
+ };
186
+ }
187
+
188
+ /**
189
+ * Safely executes a function and handles errors.
190
+ */
191
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
192
+ _safeExecute(execute, onSuccess, onFailure) {
193
+ try {
194
+ const result = execute();
195
+
196
+ if (core.isThenable(result)) {
197
+ result.then(
198
+ () => onSuccess(),
199
+ (error) => onFailure(error),
200
+ );
201
+ } else {
202
+ onSuccess();
203
+ }
204
+
205
+ return result;
206
+ } catch (error) {
207
+ onFailure(error);
208
+ throw error;
209
+ }
210
+ }
211
+
212
+ /**
213
+ * Determines the handler type based on the result.
214
+ * @param result
215
+ * @private
216
+ */
217
+ _determineHandlerType(result) {
218
+ return result === undefined ? constants.HonoTypes.MIDDLEWARE : constants.HonoTypes.REQUEST_HANDLER;
219
+ }
220
+
221
+ /**
222
+ * Handles errors by setting the span status and recording the exception.
223
+ */
224
+ _handleError(span, error) {
225
+ if (error instanceof Error) {
226
+ span.setStatus({
227
+ code: api.SpanStatusCode.ERROR,
228
+ message: error.message,
229
+ });
230
+ span.recordException(error);
231
+ }
232
+ }
233
+ }
234
+
235
+ exports.HonoInstrumentation = HonoInstrumentation;
236
+ //# sourceMappingURL=instrumentation.js.map