@sentry/node 10.55.0 → 10.57.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.
- package/build/cjs/integrations/node-fetch/vendored/undici.js +2 -3
- package/build/cjs/integrations/node-fetch/vendored/undici.js.map +1 -1
- package/build/cjs/integrations/tracing/InstrumentationNodeModuleFile.js +15 -0
- package/build/cjs/integrations/tracing/InstrumentationNodeModuleFile.js.map +1 -0
- package/build/cjs/integrations/tracing/amqplib/vendored/amqplib.js +9 -9
- package/build/cjs/integrations/tracing/amqplib/vendored/amqplib.js.map +1 -1
- package/build/cjs/integrations/tracing/amqplib/vendored/utils.js.map +1 -1
- package/build/cjs/integrations/tracing/anthropic-ai/index.js.map +1 -1
- package/build/cjs/integrations/tracing/connect/vendored/instrumentation.js +3 -5
- package/build/cjs/integrations/tracing/connect/vendored/instrumentation.js.map +1 -1
- package/build/cjs/integrations/tracing/express.js +3 -5
- package/build/cjs/integrations/tracing/express.js.map +1 -1
- package/build/cjs/integrations/tracing/fastify/v3/instrumentation.js +10 -11
- package/build/cjs/integrations/tracing/fastify/v3/instrumentation.js.map +1 -1
- package/build/cjs/integrations/tracing/fastify/vendored/instrumentation.js +3 -4
- package/build/cjs/integrations/tracing/fastify/vendored/instrumentation.js.map +1 -1
- package/build/cjs/integrations/tracing/firebase/otel/patches/firestore.js +2 -1
- package/build/cjs/integrations/tracing/firebase/otel/patches/firestore.js.map +1 -1
- package/build/cjs/integrations/tracing/firebase/otel/patches/functions.js +2 -1
- package/build/cjs/integrations/tracing/firebase/otel/patches/functions.js.map +1 -1
- package/build/cjs/integrations/tracing/google-genai/index.js.map +1 -1
- package/build/cjs/integrations/tracing/google-genai/instrumentation.js +2 -1
- package/build/cjs/integrations/tracing/google-genai/instrumentation.js.map +1 -1
- package/build/cjs/integrations/tracing/graphql/vendored/instrumentation.js +4 -3
- package/build/cjs/integrations/tracing/graphql/vendored/instrumentation.js.map +1 -1
- package/build/cjs/integrations/tracing/hapi/vendored/instrumentation.js +2 -5
- package/build/cjs/integrations/tracing/hapi/vendored/instrumentation.js.map +1 -1
- package/build/cjs/integrations/tracing/knex/vendored/instrumentation.js +3 -2
- package/build/cjs/integrations/tracing/knex/vendored/instrumentation.js.map +1 -1
- package/build/cjs/integrations/tracing/koa/vendored/instrumentation.js +3 -4
- package/build/cjs/integrations/tracing/koa/vendored/instrumentation.js.map +1 -1
- package/build/cjs/integrations/tracing/langchain/index.js.map +1 -1
- package/build/cjs/integrations/tracing/langchain/instrumentation.js +3 -2
- package/build/cjs/integrations/tracing/langchain/instrumentation.js.map +1 -1
- package/build/cjs/integrations/tracing/langgraph/index.js.map +1 -1
- package/build/cjs/integrations/tracing/langgraph/instrumentation.js +7 -5
- package/build/cjs/integrations/tracing/langgraph/instrumentation.js.map +1 -1
- package/build/cjs/integrations/tracing/lrumemoizer/vendored/instrumentation.js +8 -11
- package/build/cjs/integrations/tracing/lrumemoizer/vendored/instrumentation.js.map +1 -1
- package/build/cjs/integrations/tracing/mongo/vendored/instrumentation.js +7 -6
- package/build/cjs/integrations/tracing/mongo/vendored/instrumentation.js.map +1 -1
- package/build/cjs/integrations/tracing/mysql2/vendored/instrumentation.js +3 -2
- package/build/cjs/integrations/tracing/mysql2/vendored/instrumentation.js.map +1 -1
- package/build/cjs/integrations/tracing/openai/index.js.map +1 -1
- package/build/cjs/integrations/tracing/postgres/vendored/instrumentation.js +5 -5
- package/build/cjs/integrations/tracing/postgres/vendored/instrumentation.js.map +1 -1
- package/build/cjs/integrations/tracing/postgresjs.js +3 -2
- package/build/cjs/integrations/tracing/postgresjs.js.map +1 -1
- package/build/cjs/integrations/tracing/redis/index.js +3 -2
- package/build/cjs/integrations/tracing/redis/index.js.map +1 -1
- package/build/cjs/integrations/tracing/redis/vendored/ioredis-instrumentation.js +1 -1
- package/build/cjs/integrations/tracing/redis/vendored/ioredis-instrumentation.js.map +1 -1
- package/build/cjs/integrations/tracing/redis/vendored/redis-instrumentation.js +4 -3
- package/build/cjs/integrations/tracing/redis/vendored/redis-instrumentation.js.map +1 -1
- package/build/cjs/integrations/tracing/utils/sql-common.js.map +1 -1
- package/build/cjs/integrations/tracing/vercelai/instrumentation.js +6 -5
- package/build/cjs/integrations/tracing/vercelai/instrumentation.js.map +1 -1
- package/build/cjs/utils/setHttpServerSpanRouteAttribute.js +21 -0
- package/build/cjs/utils/setHttpServerSpanRouteAttribute.js.map +1 -0
- package/build/esm/integrations/node-fetch/vendored/undici.js +3 -4
- package/build/esm/integrations/node-fetch/vendored/undici.js.map +1 -1
- package/build/esm/integrations/tracing/InstrumentationNodeModuleFile.js +13 -0
- package/build/esm/integrations/tracing/InstrumentationNodeModuleFile.js.map +1 -0
- package/build/esm/integrations/tracing/amqplib/vendored/amqplib.js +7 -7
- package/build/esm/integrations/tracing/amqplib/vendored/amqplib.js.map +1 -1
- package/build/esm/integrations/tracing/amqplib/vendored/utils.js.map +1 -1
- package/build/esm/integrations/tracing/anthropic-ai/index.js.map +1 -1
- package/build/esm/integrations/tracing/connect/vendored/instrumentation.js +3 -5
- package/build/esm/integrations/tracing/connect/vendored/instrumentation.js.map +1 -1
- package/build/esm/integrations/tracing/express.js +3 -5
- package/build/esm/integrations/tracing/express.js.map +1 -1
- package/build/esm/integrations/tracing/fastify/v3/instrumentation.js +3 -4
- package/build/esm/integrations/tracing/fastify/v3/instrumentation.js.map +1 -1
- package/build/esm/integrations/tracing/fastify/vendored/instrumentation.js +3 -4
- package/build/esm/integrations/tracing/fastify/vendored/instrumentation.js.map +1 -1
- package/build/esm/integrations/tracing/firebase/otel/patches/firestore.js +2 -1
- package/build/esm/integrations/tracing/firebase/otel/patches/firestore.js.map +1 -1
- package/build/esm/integrations/tracing/firebase/otel/patches/functions.js +2 -1
- package/build/esm/integrations/tracing/firebase/otel/patches/functions.js.map +1 -1
- package/build/esm/integrations/tracing/google-genai/index.js.map +1 -1
- package/build/esm/integrations/tracing/google-genai/instrumentation.js +2 -1
- package/build/esm/integrations/tracing/google-genai/instrumentation.js.map +1 -1
- package/build/esm/integrations/tracing/graphql/vendored/instrumentation.js +2 -1
- package/build/esm/integrations/tracing/graphql/vendored/instrumentation.js.map +1 -1
- package/build/esm/integrations/tracing/hapi/vendored/instrumentation.js +2 -5
- package/build/esm/integrations/tracing/hapi/vendored/instrumentation.js.map +1 -1
- package/build/esm/integrations/tracing/knex/vendored/instrumentation.js +2 -1
- package/build/esm/integrations/tracing/knex/vendored/instrumentation.js.map +1 -1
- package/build/esm/integrations/tracing/koa/vendored/instrumentation.js +3 -4
- package/build/esm/integrations/tracing/koa/vendored/instrumentation.js.map +1 -1
- package/build/esm/integrations/tracing/langchain/index.js.map +1 -1
- package/build/esm/integrations/tracing/langchain/instrumentation.js +2 -1
- package/build/esm/integrations/tracing/langchain/instrumentation.js.map +1 -1
- package/build/esm/integrations/tracing/langgraph/index.js.map +1 -1
- package/build/esm/integrations/tracing/langgraph/instrumentation.js +5 -3
- package/build/esm/integrations/tracing/langgraph/instrumentation.js.map +1 -1
- package/build/esm/integrations/tracing/lrumemoizer/vendored/instrumentation.js +8 -11
- package/build/esm/integrations/tracing/lrumemoizer/vendored/instrumentation.js.map +1 -1
- package/build/esm/integrations/tracing/mongo/vendored/instrumentation.js +2 -1
- package/build/esm/integrations/tracing/mongo/vendored/instrumentation.js.map +1 -1
- package/build/esm/integrations/tracing/mysql2/vendored/instrumentation.js +2 -1
- package/build/esm/integrations/tracing/mysql2/vendored/instrumentation.js.map +1 -1
- package/build/esm/integrations/tracing/openai/index.js.map +1 -1
- package/build/esm/integrations/tracing/postgres/vendored/instrumentation.js +5 -5
- package/build/esm/integrations/tracing/postgres/vendored/instrumentation.js.map +1 -1
- package/build/esm/integrations/tracing/postgresjs.js +3 -2
- package/build/esm/integrations/tracing/postgresjs.js.map +1 -1
- package/build/esm/integrations/tracing/redis/index.js +3 -2
- package/build/esm/integrations/tracing/redis/index.js.map +1 -1
- package/build/esm/integrations/tracing/redis/vendored/ioredis-instrumentation.js +1 -1
- package/build/esm/integrations/tracing/redis/vendored/ioredis-instrumentation.js.map +1 -1
- package/build/esm/integrations/tracing/redis/vendored/redis-instrumentation.js +2 -1
- package/build/esm/integrations/tracing/redis/vendored/redis-instrumentation.js.map +1 -1
- package/build/esm/integrations/tracing/utils/sql-common.js.map +1 -1
- package/build/esm/integrations/tracing/vercelai/instrumentation.js +6 -5
- package/build/esm/integrations/tracing/vercelai/instrumentation.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/esm/utils/setHttpServerSpanRouteAttribute.js +19 -0
- package/build/esm/utils/setHttpServerSpanRouteAttribute.js.map +1 -0
- package/build/types/integrations/node-fetch/vendored/undici.d.ts.map +1 -1
- package/build/types/integrations/tracing/InstrumentationNodeModuleFile.d.ts +9 -0
- package/build/types/integrations/tracing/InstrumentationNodeModuleFile.d.ts.map +1 -0
- package/build/types/integrations/tracing/amqplib/vendored/amqplib.d.ts.map +1 -1
- package/build/types/integrations/tracing/amqplib/vendored/utils.d.ts +2 -2
- package/build/types/integrations/tracing/amqplib/vendored/utils.d.ts.map +1 -1
- package/build/types/integrations/tracing/anthropic-ai/index.d.ts +8 -7
- package/build/types/integrations/tracing/anthropic-ai/index.d.ts.map +1 -1
- package/build/types/integrations/tracing/connect/vendored/instrumentation.d.ts.map +1 -1
- package/build/types/integrations/tracing/express.d.ts.map +1 -1
- package/build/types/integrations/tracing/fastify/v3/instrumentation.d.ts.map +1 -1
- package/build/types/integrations/tracing/fastify/vendored/instrumentation.d.ts.map +1 -1
- package/build/types/integrations/tracing/firebase/otel/patches/firestore.d.ts.map +1 -1
- package/build/types/integrations/tracing/firebase/otel/patches/functions.d.ts.map +1 -1
- package/build/types/integrations/tracing/google-genai/index.d.ts +8 -7
- package/build/types/integrations/tracing/google-genai/index.d.ts.map +1 -1
- package/build/types/integrations/tracing/google-genai/instrumentation.d.ts.map +1 -1
- package/build/types/integrations/tracing/graphql/vendored/instrumentation.d.ts.map +1 -1
- package/build/types/integrations/tracing/hapi/vendored/instrumentation.d.ts.map +1 -1
- package/build/types/integrations/tracing/knex/vendored/instrumentation.d.ts.map +1 -1
- package/build/types/integrations/tracing/koa/vendored/instrumentation.d.ts.map +1 -1
- package/build/types/integrations/tracing/langchain/index.d.ts +9 -8
- package/build/types/integrations/tracing/langchain/index.d.ts.map +1 -1
- package/build/types/integrations/tracing/langchain/instrumentation.d.ts.map +1 -1
- package/build/types/integrations/tracing/langgraph/index.d.ts +8 -7
- package/build/types/integrations/tracing/langgraph/index.d.ts.map +1 -1
- package/build/types/integrations/tracing/langgraph/instrumentation.d.ts.map +1 -1
- package/build/types/integrations/tracing/lrumemoizer/vendored/instrumentation.d.ts +2 -2
- package/build/types/integrations/tracing/lrumemoizer/vendored/instrumentation.d.ts.map +1 -1
- package/build/types/integrations/tracing/mongo/vendored/instrumentation.d.ts.map +1 -1
- package/build/types/integrations/tracing/mysql2/vendored/instrumentation.d.ts.map +1 -1
- package/build/types/integrations/tracing/openai/index.d.ts +8 -7
- package/build/types/integrations/tracing/openai/index.d.ts.map +1 -1
- package/build/types/integrations/tracing/postgres/vendored/instrumentation.d.ts.map +1 -1
- package/build/types/integrations/tracing/postgresjs.d.ts.map +1 -1
- package/build/types/integrations/tracing/redis/index.d.ts +4 -1
- package/build/types/integrations/tracing/redis/index.d.ts.map +1 -1
- package/build/types/integrations/tracing/redis/vendored/redis-instrumentation.d.ts.map +1 -1
- package/build/types/integrations/tracing/utils/sql-common.d.ts +1 -1
- package/build/types/integrations/tracing/utils/sql-common.d.ts.map +1 -1
- package/build/types/integrations/tracing/vercelai/instrumentation.d.ts +2 -2
- package/build/types/integrations/tracing/vercelai/instrumentation.d.ts.map +1 -1
- package/build/types/integrations/tracing/vercelai/types.d.ts +6 -4
- package/build/types/integrations/tracing/vercelai/types.d.ts.map +1 -1
- package/build/types/utils/setHttpServerSpanRouteAttribute.d.ts +9 -0
- package/build/types/utils/setHttpServerSpanRouteAttribute.d.ts.map +1 -0
- package/build/types-ts3.8/integrations/tracing/InstrumentationNodeModuleFile.d.ts +9 -0
- package/build/types-ts3.8/integrations/tracing/amqplib/vendored/utils.d.ts +2 -2
- package/build/types-ts3.8/integrations/tracing/anthropic-ai/index.d.ts +8 -7
- package/build/types-ts3.8/integrations/tracing/google-genai/index.d.ts +8 -7
- package/build/types-ts3.8/integrations/tracing/langchain/index.d.ts +9 -8
- package/build/types-ts3.8/integrations/tracing/langgraph/index.d.ts +8 -7
- package/build/types-ts3.8/integrations/tracing/lrumemoizer/vendored/instrumentation.d.ts +2 -2
- package/build/types-ts3.8/integrations/tracing/openai/index.d.ts +8 -7
- package/build/types-ts3.8/integrations/tracing/redis/index.d.ts +4 -1
- package/build/types-ts3.8/integrations/tracing/vercelai/instrumentation.d.ts +2 -2
- package/build/types-ts3.8/integrations/tracing/vercelai/types.d.ts +6 -4
- package/build/types-ts3.8/utils/setHttpServerSpanRouteAttribute.d.ts +9 -0
- package/package.json +5 -4
- package/build/cjs/integrations/tracing/redis/redis-dc-subscriber.js +0 -151
- package/build/cjs/integrations/tracing/redis/redis-dc-subscriber.js.map +0 -1
- package/build/esm/integrations/tracing/redis/redis-dc-subscriber.js +0 -149
- package/build/esm/integrations/tracing/redis/redis-dc-subscriber.js.map +0 -1
- package/build/types/integrations/tracing/redis/redis-dc-subscriber.d.ts +0 -17
- package/build/types/integrations/tracing/redis/redis-dc-subscriber.d.ts.map +0 -1
- package/build/types-ts3.8/integrations/tracing/redis/redis-dc-subscriber.d.ts +0 -17
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions.js","sources":["../../../../../../../src/integrations/tracing/firebase/otel/patches/functions.ts"],"sourcesContent":["import type { Span, Tracer } from '@opentelemetry/api';\nimport { context, diag, SpanKind, trace } from '@opentelemetry/api';\nimport type { InstrumentationBase } from '@opentelemetry/instrumentation';\nimport {\n InstrumentationNodeModuleDefinition,\n InstrumentationNodeModuleFile,\n isWrapped,\n safeExecuteInTheMiddle,\n} from '@opentelemetry/instrumentation';\nimport type { SpanAttributes } from '@sentry/core';\nimport type { FirebaseInstrumentation } from '../firebaseInstrumentation';\nimport type {\n AvailableFirebaseFunctions,\n FirebaseFunctions,\n FirebaseInstrumentationConfig,\n OverloadedParameters,\n RequestHook,\n ResponseHook,\n} from '../types';\n\n/**\n * Patches Firebase Functions v2 to add OpenTelemetry instrumentation\n * @param tracer - Opentelemetry Tracer\n * @param functionsSupportedVersions - supported versions of firebase-functions\n * @param wrap - reference to native instrumentation wrap function\n * @param unwrap - reference to native instrumentation unwrap function\n * @param config - Firebase instrumentation config\n */\nexport function patchFunctions(\n tracer: Tracer,\n functionsSupportedVersions: string[],\n wrap: InstrumentationBase['_wrap'],\n unwrap: InstrumentationBase['_unwrap'],\n config: FirebaseInstrumentationConfig,\n): InstrumentationNodeModuleDefinition {\n let requestHook: RequestHook = () => {};\n let responseHook: ResponseHook = () => {};\n const errorHook = config.functions?.errorHook;\n const configRequestHook = config.functions?.requestHook;\n const configResponseHook = config.functions?.responseHook;\n\n if (typeof configResponseHook === 'function') {\n responseHook = (span: Span, err: unknown) => {\n safeExecuteInTheMiddle(\n () => configResponseHook(span, err),\n error => {\n if (!error) {\n return;\n }\n diag.error(error?.message);\n },\n true,\n );\n };\n }\n if (typeof configRequestHook === 'function') {\n requestHook = (span: Span) => {\n safeExecuteInTheMiddle(\n () => configRequestHook(span),\n error => {\n if (!error) {\n return;\n }\n diag.error(error?.message);\n },\n true,\n );\n };\n }\n\n const moduleFunctionsCJS = new InstrumentationNodeModuleDefinition('firebase-functions', functionsSupportedVersions);\n const modulesToInstrument = [\n { name: 'firebase-functions/lib/v2/providers/https.js', triggerType: 'function' },\n { name: 'firebase-functions/lib/v2/providers/firestore.js', triggerType: 'firestore' },\n { name: 'firebase-functions/lib/v2/providers/scheduler.js', triggerType: 'scheduler' },\n { name: 'firebase-functions/lib/v2/storage.js', triggerType: 'storage' },\n ] as const;\n\n modulesToInstrument.forEach(({ name, triggerType }) => {\n moduleFunctionsCJS.files.push(\n new InstrumentationNodeModuleFile(\n name,\n functionsSupportedVersions,\n moduleExports =>\n wrapCommonFunctions(\n moduleExports,\n wrap,\n unwrap,\n tracer,\n { requestHook, responseHook, errorHook },\n triggerType,\n ),\n moduleExports => unwrapCommonFunctions(moduleExports, unwrap),\n ),\n );\n });\n\n return moduleFunctionsCJS;\n}\n\n/**\n * Patches Cloud Functions for Firebase (v2) to add OpenTelemetry instrumentation\n *\n * @param tracer - Opentelemetry Tracer\n * @param functionsConfig - Firebase instrumentation config\n * @param triggerType - Type of trigger\n * @returns A function that patches the function\n */\nexport function patchV2Functions<T extends FirebaseFunctions = FirebaseFunctions>(\n tracer: Tracer,\n functionsConfig: FirebaseInstrumentationConfig['functions'],\n triggerType: string,\n): (original: T) => (...args: OverloadedParameters<T>) => ReturnType<T> {\n return function v2FunctionsWrapper(original: T): (...args: OverloadedParameters<T>) => ReturnType<T> {\n return function (this: FirebaseInstrumentation, ...args: OverloadedParameters<T>): ReturnType<T> {\n const handler = typeof args[0] === 'function' ? args[0] : args[1];\n const documentOrOptions = typeof args[0] === 'function' ? undefined : args[0];\n\n if (!handler) {\n return original.call(this, ...args);\n }\n\n const wrappedHandler = async function (this: unknown, ...handlerArgs: unknown[]): Promise<unknown> {\n const functionName = process.env.FUNCTION_TARGET || process.env.K_SERVICE || 'unknown';\n const span = tracer.startSpan(`firebase.function.${triggerType}`, {\n kind: SpanKind.SERVER,\n });\n\n const attributes: SpanAttributes = {\n 'faas.name': functionName,\n 'faas.trigger': triggerType,\n 'faas.provider': 'firebase',\n };\n\n if (process.env.GCLOUD_PROJECT) {\n attributes['cloud.project_id'] = process.env.GCLOUD_PROJECT;\n }\n\n if (process.env.EVENTARC_CLOUD_EVENT_SOURCE) {\n attributes['cloud.event_source'] = process.env.EVENTARC_CLOUD_EVENT_SOURCE;\n }\n\n span.setAttributes(attributes);\n functionsConfig?.requestHook?.(span);\n\n // Can be changed to safeExecuteInTheMiddleAsync once following is merged and released\n // https://github.com/open-telemetry/opentelemetry-js/pull/6032\n return context.with(trace.setSpan(context.active(), span), async () => {\n let error: Error | undefined;\n let result: T | undefined;\n\n try {\n result = await handler.apply(this, handlerArgs);\n } catch (e) {\n error = e as Error;\n }\n\n functionsConfig?.responseHook?.(span, error);\n\n if (error) {\n span.recordException(error);\n }\n\n span.end();\n\n if (error) {\n await functionsConfig?.errorHook?.(span, error);\n throw error;\n }\n\n return result;\n });\n };\n\n if (documentOrOptions) {\n return original.call(this, documentOrOptions, wrappedHandler);\n } else {\n return original.call(this, wrappedHandler);\n }\n };\n };\n}\n\nfunction wrapCommonFunctions(\n moduleExports: AvailableFirebaseFunctions,\n wrap: InstrumentationBase<FirebaseInstrumentationConfig>['_wrap'],\n unwrap: InstrumentationBase<FirebaseInstrumentationConfig>['_unwrap'],\n tracer: Tracer,\n functionsConfig: FirebaseInstrumentationConfig['functions'],\n triggerType: 'function' | 'firestore' | 'scheduler' | 'storage',\n): AvailableFirebaseFunctions {\n unwrapCommonFunctions(moduleExports, unwrap);\n\n switch (triggerType) {\n case 'function':\n wrap(moduleExports, 'onRequest', patchV2Functions(tracer, functionsConfig, 'http.request'));\n wrap(moduleExports, 'onCall', patchV2Functions(tracer, functionsConfig, 'http.call'));\n break;\n\n case 'firestore':\n wrap(moduleExports, 'onDocumentCreated', patchV2Functions(tracer, functionsConfig, 'firestore.document.created'));\n wrap(moduleExports, 'onDocumentUpdated', patchV2Functions(tracer, functionsConfig, 'firestore.document.updated'));\n wrap(moduleExports, 'onDocumentDeleted', patchV2Functions(tracer, functionsConfig, 'firestore.document.deleted'));\n wrap(moduleExports, 'onDocumentWritten', patchV2Functions(tracer, functionsConfig, 'firestore.document.written'));\n wrap(\n moduleExports,\n 'onDocumentCreatedWithAuthContext',\n patchV2Functions(tracer, functionsConfig, 'firestore.document.created'),\n );\n wrap(\n moduleExports,\n 'onDocumentUpdatedWithAuthContext',\n patchV2Functions(tracer, functionsConfig, 'firestore.document.updated'),\n );\n\n wrap(\n moduleExports,\n 'onDocumentDeletedWithAuthContext',\n patchV2Functions(tracer, functionsConfig, 'firestore.document.deleted'),\n );\n\n wrap(\n moduleExports,\n 'onDocumentWrittenWithAuthContext',\n patchV2Functions(tracer, functionsConfig, 'firestore.document.written'),\n );\n break;\n\n case 'scheduler':\n wrap(moduleExports, 'onSchedule', patchV2Functions(tracer, functionsConfig, 'scheduler.scheduled'));\n break;\n\n case 'storage':\n wrap(moduleExports, 'onObjectFinalized', patchV2Functions(tracer, functionsConfig, 'storage.object.finalized'));\n wrap(moduleExports, 'onObjectArchived', patchV2Functions(tracer, functionsConfig, 'storage.object.archived'));\n wrap(moduleExports, 'onObjectDeleted', patchV2Functions(tracer, functionsConfig, 'storage.object.deleted'));\n wrap(\n moduleExports,\n 'onObjectMetadataUpdated',\n patchV2Functions(tracer, functionsConfig, 'storage.object.metadataUpdated'),\n );\n break;\n }\n\n return moduleExports;\n}\n\nfunction unwrapCommonFunctions(\n moduleExports: AvailableFirebaseFunctions,\n unwrap: InstrumentationBase<FirebaseInstrumentationConfig>['_unwrap'],\n): AvailableFirebaseFunctions {\n const methods: (keyof AvailableFirebaseFunctions)[] = [\n 'onSchedule',\n 'onRequest',\n 'onCall',\n 'onObjectFinalized',\n 'onObjectArchived',\n 'onObjectDeleted',\n 'onObjectMetadataUpdated',\n 'onDocumentCreated',\n 'onDocumentUpdated',\n 'onDocumentDeleted',\n 'onDocumentWritten',\n 'onDocumentCreatedWithAuthContext',\n 'onDocumentUpdatedWithAuthContext',\n 'onDocumentDeletedWithAuthContext',\n 'onDocumentWrittenWithAuthContext',\n ];\n\n for (const method of methods) {\n if (isWrapped(moduleExports[method])) {\n unwrap(moduleExports, method);\n }\n }\n return moduleExports;\n}\n"],"names":["safeExecuteInTheMiddle","diag","InstrumentationNodeModuleDefinition","InstrumentationNodeModuleFile","SpanKind","context","trace","isWrapped"],"mappings":";;;;;AA4BO,SAAS,cAAA,CACd,MAAA,EACA,0BAAA,EACA,IAAA,EACA,QACA,MAAA,EACqC;AACrC,EAAA,IAAI,cAA2B,MAAM;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4B;AAC5B,EAAA,MAAM,OAAA,GAAgD;AAAA,IACpD,YAAA;AAAA,IACA,WAAA;AAAA,IACA,QAAA;AAAA,IACA,mBAAA;AAAA,IACA,kBAAA;AAAA,IACA,iBAAA;AAAA,IACA,yBAAA;AAAA,IACA,mBAAA;AAAA,IACA,mBAAA;AAAA,IACA,mBAAA;AAAA,IACA,mBAAA;AAAA,IACA,kCAAA;AAAA,IACA,kCAAA;AAAA,IACA,kCAAA;AAAA,IACA;AAAA,GACF;AAEA,EAAA,KAAA,MAAW,UAAU,OAAA,EAAS;AAC5B,IAAA,IAAIE,yBAAA,CAAU,aAAA,CAAc,MAAM,CAAC,CAAA,EAAG;AACpC,MAAA,MAAA,CAAO,eAAe,MAAM,CAAA;AAAA,IAC9B;AAAA,EACF;AACA,EAAA,OAAO,aAAA;AACT;;;;;"}
|
|
1
|
+
{"version":3,"file":"functions.js","sources":["../../../../../../../src/integrations/tracing/firebase/otel/patches/functions.ts"],"sourcesContent":["import type { Span, Tracer } from '@opentelemetry/api';\nimport { context, diag, SpanKind, trace } from '@opentelemetry/api';\nimport type { InstrumentationBase } from '@opentelemetry/instrumentation';\nimport { InstrumentationNodeModuleDefinition, isWrapped, safeExecuteInTheMiddle } from '@opentelemetry/instrumentation';\nimport { InstrumentationNodeModuleFile } from '../../../InstrumentationNodeModuleFile';\nimport type { SpanAttributes } from '@sentry/core';\nimport type { FirebaseInstrumentation } from '../firebaseInstrumentation';\nimport type {\n AvailableFirebaseFunctions,\n FirebaseFunctions,\n FirebaseInstrumentationConfig,\n OverloadedParameters,\n RequestHook,\n ResponseHook,\n} from '../types';\n\n/**\n * Patches Firebase Functions v2 to add OpenTelemetry instrumentation\n * @param tracer - Opentelemetry Tracer\n * @param functionsSupportedVersions - supported versions of firebase-functions\n * @param wrap - reference to native instrumentation wrap function\n * @param unwrap - reference to native instrumentation unwrap function\n * @param config - Firebase instrumentation config\n */\nexport function patchFunctions(\n tracer: Tracer,\n functionsSupportedVersions: string[],\n wrap: InstrumentationBase['_wrap'],\n unwrap: InstrumentationBase['_unwrap'],\n config: FirebaseInstrumentationConfig,\n): InstrumentationNodeModuleDefinition {\n let requestHook: RequestHook = () => {};\n let responseHook: ResponseHook = () => {};\n const errorHook = config.functions?.errorHook;\n const configRequestHook = config.functions?.requestHook;\n const configResponseHook = config.functions?.responseHook;\n\n if (typeof configResponseHook === 'function') {\n responseHook = (span: Span, err: unknown) => {\n safeExecuteInTheMiddle(\n () => configResponseHook(span, err),\n error => {\n if (!error) {\n return;\n }\n diag.error(error?.message);\n },\n true,\n );\n };\n }\n if (typeof configRequestHook === 'function') {\n requestHook = (span: Span) => {\n safeExecuteInTheMiddle(\n () => configRequestHook(span),\n error => {\n if (!error) {\n return;\n }\n diag.error(error?.message);\n },\n true,\n );\n };\n }\n\n const moduleFunctionsCJS = new InstrumentationNodeModuleDefinition('firebase-functions', functionsSupportedVersions);\n const modulesToInstrument = [\n { name: 'firebase-functions/lib/v2/providers/https.js', triggerType: 'function' },\n { name: 'firebase-functions/lib/v2/providers/firestore.js', triggerType: 'firestore' },\n { name: 'firebase-functions/lib/v2/providers/scheduler.js', triggerType: 'scheduler' },\n { name: 'firebase-functions/lib/v2/storage.js', triggerType: 'storage' },\n ] as const;\n\n modulesToInstrument.forEach(({ name, triggerType }) => {\n moduleFunctionsCJS.files.push(\n new InstrumentationNodeModuleFile(\n name,\n functionsSupportedVersions,\n moduleExports =>\n wrapCommonFunctions(\n moduleExports,\n wrap,\n unwrap,\n tracer,\n { requestHook, responseHook, errorHook },\n triggerType,\n ),\n moduleExports => unwrapCommonFunctions(moduleExports, unwrap),\n ),\n );\n });\n\n return moduleFunctionsCJS;\n}\n\n/**\n * Patches Cloud Functions for Firebase (v2) to add OpenTelemetry instrumentation\n *\n * @param tracer - Opentelemetry Tracer\n * @param functionsConfig - Firebase instrumentation config\n * @param triggerType - Type of trigger\n * @returns A function that patches the function\n */\nexport function patchV2Functions<T extends FirebaseFunctions = FirebaseFunctions>(\n tracer: Tracer,\n functionsConfig: FirebaseInstrumentationConfig['functions'],\n triggerType: string,\n): (original: T) => (...args: OverloadedParameters<T>) => ReturnType<T> {\n return function v2FunctionsWrapper(original: T): (...args: OverloadedParameters<T>) => ReturnType<T> {\n return function (this: FirebaseInstrumentation, ...args: OverloadedParameters<T>): ReturnType<T> {\n const handler = typeof args[0] === 'function' ? args[0] : args[1];\n const documentOrOptions = typeof args[0] === 'function' ? undefined : args[0];\n\n if (!handler) {\n return original.call(this, ...args);\n }\n\n const wrappedHandler = async function (this: unknown, ...handlerArgs: unknown[]): Promise<unknown> {\n const functionName = process.env.FUNCTION_TARGET || process.env.K_SERVICE || 'unknown';\n const span = tracer.startSpan(`firebase.function.${triggerType}`, {\n kind: SpanKind.SERVER,\n });\n\n const attributes: SpanAttributes = {\n 'faas.name': functionName,\n 'faas.trigger': triggerType,\n 'faas.provider': 'firebase',\n };\n\n if (process.env.GCLOUD_PROJECT) {\n attributes['cloud.project_id'] = process.env.GCLOUD_PROJECT;\n }\n\n if (process.env.EVENTARC_CLOUD_EVENT_SOURCE) {\n attributes['cloud.event_source'] = process.env.EVENTARC_CLOUD_EVENT_SOURCE;\n }\n\n span.setAttributes(attributes);\n functionsConfig?.requestHook?.(span);\n\n // Can be changed to safeExecuteInTheMiddleAsync once following is merged and released\n // https://github.com/open-telemetry/opentelemetry-js/pull/6032\n return context.with(trace.setSpan(context.active(), span), async () => {\n let error: Error | undefined;\n let result: T | undefined;\n\n try {\n result = await handler.apply(this, handlerArgs);\n } catch (e) {\n error = e as Error;\n }\n\n functionsConfig?.responseHook?.(span, error);\n\n if (error) {\n span.recordException(error);\n }\n\n span.end();\n\n if (error) {\n await functionsConfig?.errorHook?.(span, error);\n throw error;\n }\n\n return result;\n });\n };\n\n if (documentOrOptions) {\n return original.call(this, documentOrOptions, wrappedHandler);\n } else {\n return original.call(this, wrappedHandler);\n }\n };\n };\n}\n\nfunction wrapCommonFunctions(\n moduleExports: AvailableFirebaseFunctions,\n wrap: InstrumentationBase<FirebaseInstrumentationConfig>['_wrap'],\n unwrap: InstrumentationBase<FirebaseInstrumentationConfig>['_unwrap'],\n tracer: Tracer,\n functionsConfig: FirebaseInstrumentationConfig['functions'],\n triggerType: 'function' | 'firestore' | 'scheduler' | 'storage',\n): AvailableFirebaseFunctions {\n unwrapCommonFunctions(moduleExports, unwrap);\n\n switch (triggerType) {\n case 'function':\n wrap(moduleExports, 'onRequest', patchV2Functions(tracer, functionsConfig, 'http.request'));\n wrap(moduleExports, 'onCall', patchV2Functions(tracer, functionsConfig, 'http.call'));\n break;\n\n case 'firestore':\n wrap(moduleExports, 'onDocumentCreated', patchV2Functions(tracer, functionsConfig, 'firestore.document.created'));\n wrap(moduleExports, 'onDocumentUpdated', patchV2Functions(tracer, functionsConfig, 'firestore.document.updated'));\n wrap(moduleExports, 'onDocumentDeleted', patchV2Functions(tracer, functionsConfig, 'firestore.document.deleted'));\n wrap(moduleExports, 'onDocumentWritten', patchV2Functions(tracer, functionsConfig, 'firestore.document.written'));\n wrap(\n moduleExports,\n 'onDocumentCreatedWithAuthContext',\n patchV2Functions(tracer, functionsConfig, 'firestore.document.created'),\n );\n wrap(\n moduleExports,\n 'onDocumentUpdatedWithAuthContext',\n patchV2Functions(tracer, functionsConfig, 'firestore.document.updated'),\n );\n\n wrap(\n moduleExports,\n 'onDocumentDeletedWithAuthContext',\n patchV2Functions(tracer, functionsConfig, 'firestore.document.deleted'),\n );\n\n wrap(\n moduleExports,\n 'onDocumentWrittenWithAuthContext',\n patchV2Functions(tracer, functionsConfig, 'firestore.document.written'),\n );\n break;\n\n case 'scheduler':\n wrap(moduleExports, 'onSchedule', patchV2Functions(tracer, functionsConfig, 'scheduler.scheduled'));\n break;\n\n case 'storage':\n wrap(moduleExports, 'onObjectFinalized', patchV2Functions(tracer, functionsConfig, 'storage.object.finalized'));\n wrap(moduleExports, 'onObjectArchived', patchV2Functions(tracer, functionsConfig, 'storage.object.archived'));\n wrap(moduleExports, 'onObjectDeleted', patchV2Functions(tracer, functionsConfig, 'storage.object.deleted'));\n wrap(\n moduleExports,\n 'onObjectMetadataUpdated',\n patchV2Functions(tracer, functionsConfig, 'storage.object.metadataUpdated'),\n );\n break;\n }\n\n return moduleExports;\n}\n\nfunction unwrapCommonFunctions(\n moduleExports: AvailableFirebaseFunctions,\n unwrap: InstrumentationBase<FirebaseInstrumentationConfig>['_unwrap'],\n): AvailableFirebaseFunctions {\n const methods: (keyof AvailableFirebaseFunctions)[] = [\n 'onSchedule',\n 'onRequest',\n 'onCall',\n 'onObjectFinalized',\n 'onObjectArchived',\n 'onObjectDeleted',\n 'onObjectMetadataUpdated',\n 'onDocumentCreated',\n 'onDocumentUpdated',\n 'onDocumentDeleted',\n 'onDocumentWritten',\n 'onDocumentCreatedWithAuthContext',\n 'onDocumentUpdatedWithAuthContext',\n 'onDocumentDeletedWithAuthContext',\n 'onDocumentWrittenWithAuthContext',\n ];\n\n for (const method of methods) {\n if (isWrapped(moduleExports[method])) {\n unwrap(moduleExports, method);\n }\n }\n return moduleExports;\n}\n"],"names":["safeExecuteInTheMiddle","diag","InstrumentationNodeModuleDefinition","InstrumentationNodeModuleFile","SpanKind","context","trace","isWrapped"],"mappings":";;;;;;AAwBO,SAAS,cAAA,CACd,MAAA,EACA,0BAAA,EACA,IAAA,EACA,QACA,MAAA,EACqC;AACrC,EAAA,IAAI,cAA2B,MAAM;AAAA,EAAC,CAAA;AACtC,EAAA,IAAI,eAA6B,MAAM;AAAA,EAAC,CAAA;AACxC,EAAA,MAAM,SAAA,GAAY,OAAO,SAAA,EAAW,SAAA;AACpC,EAAA,MAAM,iBAAA,GAAoB,OAAO,SAAA,EAAW,WAAA;AAC5C,EAAA,MAAM,kBAAA,GAAqB,OAAO,SAAA,EAAW,YAAA;AAE7C,EAAA,IAAI,OAAO,uBAAuB,UAAA,EAAY;AAC5C,IAAA,YAAA,GAAe,CAAC,MAAY,GAAA,KAAiB;AAC3C,MAAAA,sCAAA;AAAA,QACE,MAAM,kBAAA,CA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AU,aAAA,CAAc,MAAM,CAAC,CAAA,EAAG;AACpC,MAAA,MAAA,CAAO,eAAe,MAAM,CAAA;AAAA,IAC9B;AAAA,EACF;AACA,EAAA,OAAO,aAAA;AACT;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../../src/integrations/tracing/google-genai/index.ts"],"sourcesContent":["import type { GoogleGenAIOptions, IntegrationFn } from '@sentry/core';\nimport { defineIntegration, GOOGLE_GENAI_INTEGRATION_NAME } from '@sentry/core';\nimport { generateInstrumentOnce } from '@sentry/node-core';\nimport { SentryGoogleGenAiInstrumentation } from './instrumentation';\n\nexport const instrumentGoogleGenAI = generateInstrumentOnce<GoogleGenAIOptions>(\n GOOGLE_GENAI_INTEGRATION_NAME,\n options => new SentryGoogleGenAiInstrumentation(options),\n);\n\nconst _googleGenAIIntegration = ((options: GoogleGenAIOptions = {}) => {\n return {\n name: GOOGLE_GENAI_INTEGRATION_NAME,\n setupOnce() {\n instrumentGoogleGenAI(options);\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Adds Sentry tracing instrumentation for the Google Generative AI SDK.\n *\n * This integration is enabled by default.\n *\n * When configured, this integration automatically instruments Google GenAI SDK client instances\n * to capture telemetry data following OpenTelemetry Semantic Conventions for Generative AI.\n *\n * @example\n * ```javascript\n * import * as Sentry from '@sentry/node';\n *\n * Sentry.init({\n * integrations: [Sentry.googleGenAiIntegration()],\n * });\n * ```\n *\n * ## Options\n *\n * - `recordInputs`: Whether to record prompt messages (default:
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../../src/integrations/tracing/google-genai/index.ts"],"sourcesContent":["import type { GoogleGenAIOptions, IntegrationFn } from '@sentry/core';\nimport { defineIntegration, GOOGLE_GENAI_INTEGRATION_NAME } from '@sentry/core';\nimport { generateInstrumentOnce } from '@sentry/node-core';\nimport { SentryGoogleGenAiInstrumentation } from './instrumentation';\n\nexport const instrumentGoogleGenAI = generateInstrumentOnce<GoogleGenAIOptions>(\n GOOGLE_GENAI_INTEGRATION_NAME,\n options => new SentryGoogleGenAiInstrumentation(options),\n);\n\nconst _googleGenAIIntegration = ((options: GoogleGenAIOptions = {}) => {\n return {\n name: GOOGLE_GENAI_INTEGRATION_NAME,\n setupOnce() {\n instrumentGoogleGenAI(options);\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Adds Sentry tracing instrumentation for the Google Generative AI SDK.\n *\n * This integration is enabled by default.\n *\n * When configured, this integration automatically instruments Google GenAI SDK client instances\n * to capture telemetry data following OpenTelemetry Semantic Conventions for Generative AI.\n *\n * @example\n * ```javascript\n * import * as Sentry from '@sentry/node';\n *\n * Sentry.init({\n * integrations: [Sentry.googleGenAiIntegration()],\n * });\n * ```\n *\n * ## Options\n *\n * - `recordInputs`: Whether to record prompt messages (default: follows `dataCollection.genAI.inputs`)\n * - `recordOutputs`: Whether to record response text (default: follows `dataCollection.genAI.outputs`)\n *\n * ### Default Behavior\n *\n * By default, the integration will:\n * - Record inputs and outputs based on `dataCollection.genAI` in your Sentry client options\n * (or the deprecated `sendDefaultPii` option, for backwards compatibility)\n * - Integration-level `recordInputs`/`recordOutputs` options take precedence over global config\n *\n * @example\n * ```javascript\n * // Always record inputs and outputs regardless of global dataCollection config\n * Sentry.init({\n * integrations: [\n * Sentry.googleGenAiIntegration({\n * recordInputs: true,\n * recordOutputs: true\n * })\n * ],\n * });\n *\n * // Never record inputs/outputs regardless of global dataCollection config\n * Sentry.init({\n * dataCollection: { genAI: { inputs: true, outputs: true } },\n * integrations: [\n * Sentry.googleGenAiIntegration({\n * recordInputs: false,\n * recordOutputs: false\n * })\n * ],\n * });\n * ```\n *\n */\nexport const googleGenAIIntegration = defineIntegration(_googleGenAIIntegration);\n"],"names":["generateInstrumentOnce","GOOGLE_GENAI_INTEGRATION_NAME","SentryGoogleGenAiInstrumentation","defineIntegration"],"mappings":";;;;;;AAKO,MAAM,qBAAA,GAAwBA,+BAAA;AAAA,EACnCC,kCAAA;AAAA,EACA,CAAA,OAAA,KAAW,IAAIC,gDAAA,CAAiC,OAAO;AACzD;AAEA,MAAM,uBAAA,IAA2B,CAAC,OAAA,GAA8B,EAAC,KAAM;AACrE,EAAA,OAAO;AAAA,IACL,IAAA,EAAMD,kCAAA;AAAA,IACN,SAAA,GAAY;AACV,MAAA,qBAAA,CAAsB,OAAO,CAAA;AAAA,IAC/B;AAAA,GACF;AACF,CAAA,CAAA;AAwDO,MAAM,sBAAA,GAAyBE,uBAAkB,uBAAuB;;;;;"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
|
|
3
3
|
const instrumentation = require('@opentelemetry/instrumentation');
|
|
4
|
+
const InstrumentationNodeModuleFile = require('../InstrumentationNodeModuleFile.js');
|
|
4
5
|
const core = require('@sentry/core');
|
|
5
6
|
|
|
6
7
|
const supportedVersions = [">=0.10.0 <2"];
|
|
@@ -22,7 +23,7 @@ class SentryGoogleGenAiInstrumentation extends instrumentation.InstrumentationBa
|
|
|
22
23
|
// gets overwritten when that file is loaded. We add a file-level patch so that
|
|
23
24
|
// _patch runs again on the concrete implementation
|
|
24
25
|
[
|
|
25
|
-
new
|
|
26
|
+
new InstrumentationNodeModuleFile.InstrumentationNodeModuleFile(
|
|
26
27
|
"@google/genai/dist/node/index.cjs",
|
|
27
28
|
supportedVersions,
|
|
28
29
|
(exports) => this._patch(exports),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentation.js","sources":["../../../../../src/integrations/tracing/google-genai/instrumentation.ts"],"sourcesContent":["import type { InstrumentationConfig, InstrumentationModuleDefinition } from '@opentelemetry/instrumentation';\nimport {
|
|
1
|
+
{"version":3,"file":"instrumentation.js","sources":["../../../../../src/integrations/tracing/google-genai/instrumentation.ts"],"sourcesContent":["import type { InstrumentationConfig, InstrumentationModuleDefinition } from '@opentelemetry/instrumentation';\nimport { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';\nimport { InstrumentationNodeModuleFile } from '../InstrumentationNodeModuleFile';\nimport type { GoogleGenAIClient, GoogleGenAIOptions } from '@sentry/core';\nimport {\n _INTERNAL_shouldSkipAiProviderWrapping,\n GOOGLE_GENAI_INTEGRATION_NAME,\n instrumentGoogleGenAIClient,\n replaceExports,\n SDK_VERSION,\n} 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 // Check if wrapping should be skipped (e.g., when LangChain is handling instrumentation)\n if (_INTERNAL_shouldSkipAiProviderWrapping(GOOGLE_GENAI_INTEGRATION_NAME)) {\n return Reflect.construct(Original, args) as GoogleGenAIClient;\n }\n\n const instance = Reflect.construct(Original, args);\n\n return instrumentGoogleGenAIClient(instance, config);\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","_INTERNAL_shouldSkipAiProviderWrapping","GOOGLE_GENAI_INTEGRATION_NAME","instrumentGoogleGenAIClient","replaceExports"],"mappings":";;;;;;AAYA,MAAM,iBAAA,GAAoB,CAAC,aAAa,CAAA;AAejC,MAAM,yCAAyCA,mCAAA,CAAuD;AAAA,EACpG,WAAA,CAAY,MAAA,GAA4C,EAAC,EAAG;AACjE,IAAA,KAAA,CAAM,sCAAA,EAAwCC,kBAAa,MAAM,CAAA;AAAA,EACnE;AAAA;AAAA;AAAA;AAAA,EAKO,IAAA,GAAwC;AAC7C,IAAA,MAAM,SAAS,IAAIC,mDAAA;AAAA,MACjB,eAAA;AAAA,MACA,iBAAA;AAAA,MACA,CAAA,OAAA,KAAW,IAAA,CAAK,MAAA,CAAO,OAAO,CAAA;AAAA,MAC9B,CAAA,OAAA,KAAW,OAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAKX;AAAA,QACE,IAAIC,2DAAA;AAAA,UACF,mCAAA;AAAA,UACA,iBAAA;AAAA,UACA,CAAA,OAAA,KAAW,IAAA,CAAK,MAAA,CA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AAe,OAAA,EAAS,eAAe,kBAAkB,CAAA;AAEzD,IAAA,OAAO,OAAA;AAAA,EACT;AACF;;;;"}
|
|
@@ -2,6 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
|
|
3
3
|
const api = require('@opentelemetry/api');
|
|
4
4
|
const instrumentation = require('@opentelemetry/instrumentation');
|
|
5
|
+
const InstrumentationNodeModuleFile = require('../../InstrumentationNodeModuleFile.js');
|
|
5
6
|
const _enum = require('./enum.js');
|
|
6
7
|
const AttributeNames = require('./enums/AttributeNames.js');
|
|
7
8
|
const symbols = require('./symbols.js');
|
|
@@ -32,7 +33,7 @@ class GraphQLInstrumentation extends instrumentation.InstrumentationBase {
|
|
|
32
33
|
return module;
|
|
33
34
|
}
|
|
34
35
|
_addPatchingExecute() {
|
|
35
|
-
return new
|
|
36
|
+
return new InstrumentationNodeModuleFile.InstrumentationNodeModuleFile(
|
|
36
37
|
"graphql/execution/execute.js",
|
|
37
38
|
supportedVersions,
|
|
38
39
|
// cannot make it work with appropriate type as execute function has 2
|
|
@@ -52,7 +53,7 @@ class GraphQLInstrumentation extends instrumentation.InstrumentationBase {
|
|
|
52
53
|
);
|
|
53
54
|
}
|
|
54
55
|
_addPatchingParser() {
|
|
55
|
-
return new
|
|
56
|
+
return new InstrumentationNodeModuleFile.InstrumentationNodeModuleFile(
|
|
56
57
|
"graphql/language/parser.js",
|
|
57
58
|
supportedVersions,
|
|
58
59
|
(moduleExports) => {
|
|
@@ -70,7 +71,7 @@ class GraphQLInstrumentation extends instrumentation.InstrumentationBase {
|
|
|
70
71
|
);
|
|
71
72
|
}
|
|
72
73
|
_addPatchingValidate() {
|
|
73
|
-
return new
|
|
74
|
+
return new InstrumentationNodeModuleFile.InstrumentationNodeModuleFile(
|
|
74
75
|
"graphql/validation/validate.js",
|
|
75
76
|
supportedVersions,
|
|
76
77
|
(moduleExports) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentation.js","sources":["../../../../../../src/integrations/tracing/graphql/vendored/instrumentation.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * NOTICE from the Sentry authors:\n * - Vendored from: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/15ef7506553f631ea4181391e0c5725a56f0d082/packages/instrumentation-graphql\n * - Upstream version: @opentelemetry/instrumentation-graphql@0.66.0\n * - Types from `graphql` package inlined as simplified interfaces\n * - Minor TypeScript strictness adjustments\n */\n/* eslint-disable */\n\nimport { context, trace } from '@opentelemetry/api';\nimport {\n isWrapped,\n InstrumentationBase,\n InstrumentationNodeModuleDefinition,\n InstrumentationNodeModuleFile,\n safeExecuteInTheMiddle,\n} from '@opentelemetry/instrumentation';\nimport type {\n DefinitionNode,\n DocumentNode,\n ExecutionArgs,\n ExecutionResult,\n GraphQLError,\n GraphQLFieldResolver,\n GraphQLSchema,\n GraphQLTypeResolver,\n OperationDefinitionNode,\n ParseOptions,\n PromiseOrValue,\n Source,\n TypeInfo,\n ValidationRule,\n} from './graphql-types';\nimport type { Maybe } from './graphql-types';\nimport { SpanNames } from './enum';\nimport { AttributeNames } from './enums/AttributeNames';\nimport { OTEL_GRAPHQL_DATA_SYMBOL } from './symbols';\n\nimport {\n executeFunctionWithObj,\n executeArgumentsArray,\n executeType,\n parseType,\n validateType,\n OtelExecutionArgs,\n ObjectWithGraphQLData,\n OPERATION_NOT_SUPPORTED,\n} from './internal-types';\nimport {\n addInputVariableAttributes,\n addSpanSource,\n endSpan,\n getOperation,\n isPromise,\n wrapFieldResolver,\n wrapFields,\n} from './utils';\n\nimport { SDK_VERSION } from '@sentry/core';\nimport * as api from '@opentelemetry/api';\nimport { GraphQLInstrumentationConfig, GraphQLInstrumentationParsedConfig } from './types';\n\nconst PACKAGE_NAME = '@sentry/instrumentation-graphql';\n\nconst DEFAULT_CONFIG: GraphQLInstrumentationParsedConfig = {\n mergeItems: false,\n depth: -1,\n allowValues: false,\n ignoreResolveSpans: false,\n};\n\nconst supportedVersions = ['>=14.0.0 <17'];\n\nexport class GraphQLInstrumentation extends InstrumentationBase<GraphQLInstrumentationParsedConfig> {\n constructor(config: GraphQLInstrumentationConfig = {}) {\n super(PACKAGE_NAME, SDK_VERSION, { ...DEFAULT_CONFIG, ...config });\n }\n\n override setConfig(config: GraphQLInstrumentationConfig = {}) {\n super.setConfig({ ...DEFAULT_CONFIG, ...config });\n }\n\n protected init() {\n const module = new InstrumentationNodeModuleDefinition('graphql', supportedVersions);\n module.files.push(this._addPatchingExecute());\n module.files.push(this._addPatchingParser());\n module.files.push(this._addPatchingValidate());\n\n return module;\n }\n\n private _addPatchingExecute(): InstrumentationNodeModuleFile {\n return new InstrumentationNodeModuleFile(\n 'graphql/execution/execute.js',\n supportedVersions,\n // cannot make it work with appropriate type as execute function has 2\n //types and/cannot import function but only types\n (moduleExports: any) => {\n if (isWrapped(moduleExports.execute)) {\n this._unwrap(moduleExports, 'execute');\n }\n this._wrap(moduleExports, 'execute', this._patchExecute(moduleExports.defaultFieldResolver));\n return moduleExports;\n },\n moduleExports => {\n if (moduleExports) {\n this._unwrap(moduleExports, 'execute');\n }\n },\n );\n }\n\n private _addPatchingParser(): InstrumentationNodeModuleFile {\n return new InstrumentationNodeModuleFile(\n 'graphql/language/parser.js',\n supportedVersions,\n (moduleExports: { parse: parseType; [key: string]: any }) => {\n if (isWrapped(moduleExports.parse)) {\n this._unwrap(moduleExports, 'parse');\n }\n this._wrap(moduleExports, 'parse', this._patchParse());\n return moduleExports;\n },\n (moduleExports: { parse: parseType; [key: string]: any }) => {\n if (moduleExports) {\n this._unwrap(moduleExports, 'parse');\n }\n },\n );\n }\n\n private _addPatchingValidate(): InstrumentationNodeModuleFile {\n return new InstrumentationNodeModuleFile(\n 'graphql/validation/validate.js',\n supportedVersions,\n moduleExports => {\n if (isWrapped(moduleExports.validate)) {\n this._unwrap(moduleExports, 'validate');\n }\n this._wrap(moduleExports, 'validate', this._patchValidate());\n return moduleExports;\n },\n moduleExports => {\n if (moduleExports) {\n this._unwrap(moduleExports, 'validate');\n }\n },\n );\n }\n\n private _patchExecute(defaultFieldResolved: GraphQLFieldResolver<any, any>): (original: executeType) => executeType {\n const instrumentation = this;\n return function execute(original) {\n return function patchExecute(this: executeType): PromiseOrValue<ExecutionResult> {\n let processedArgs: OtelExecutionArgs;\n\n // case when apollo server is used for example\n if (arguments.length >= 2) {\n const args = arguments as unknown as executeArgumentsArray;\n processedArgs = instrumentation._wrapExecuteArgs(\n args[0],\n args[1],\n args[2],\n args[3],\n args[4],\n args[5],\n args[6],\n args[7],\n defaultFieldResolved,\n );\n } else {\n const args = arguments[0] as ExecutionArgs;\n processedArgs = instrumentation._wrapExecuteArgs(\n args.schema,\n args.document,\n args.rootValue,\n args.contextValue,\n args.variableValues,\n args.operationName,\n args.fieldResolver,\n args.typeResolver,\n defaultFieldResolved,\n );\n }\n\n const operation = getOperation(processedArgs.document, processedArgs.operationName);\n\n const span = instrumentation._createExecuteSpan(operation, processedArgs);\n\n processedArgs.contextValue[OTEL_GRAPHQL_DATA_SYMBOL] = {\n source: processedArgs.document\n ? processedArgs.document || (processedArgs.document as ObjectWithGraphQLData)[OTEL_GRAPHQL_DATA_SYMBOL]\n : undefined,\n span,\n fields: {},\n };\n\n return context.with(trace.setSpan(context.active(), span), () => {\n return safeExecuteInTheMiddle<PromiseOrValue<ExecutionResult>>(\n () => {\n return (original as executeFunctionWithObj).apply(this, [processedArgs]);\n },\n (err, result) => {\n instrumentation._handleExecutionResult(span, err, result);\n },\n );\n });\n };\n };\n }\n\n private _handleExecutionResult(span: api.Span, err?: Error, result?: PromiseOrValue<ExecutionResult>) {\n const config = this.getConfig();\n if (result === undefined || err) {\n endSpan(span, err);\n return;\n }\n\n if (isPromise(result)) {\n (result as Promise<ExecutionResult>).then(\n resultData => {\n if (typeof config.responseHook !== 'function') {\n endSpan(span);\n return;\n }\n this._executeResponseHook(span, resultData);\n },\n error => {\n endSpan(span, error);\n },\n );\n } else {\n if (typeof config.responseHook !== 'function') {\n endSpan(span);\n return;\n }\n this._executeResponseHook(span, result as ExecutionResult);\n }\n }\n\n private _executeResponseHook(span: api.Span, result: ExecutionResult) {\n const { responseHook } = this.getConfig();\n if (!responseHook) {\n return;\n }\n\n safeExecuteInTheMiddle(\n () => {\n responseHook(span, result);\n },\n err => {\n if (err) {\n this._diag.error('Error running response hook', err);\n }\n\n endSpan(span, undefined);\n },\n true,\n );\n }\n\n private _patchParse(): (original: parseType) => parseType {\n const instrumentation = this;\n return function parse(original) {\n return function patchParse(this: parseType, source: string | Source, options?: ParseOptions): DocumentNode {\n return instrumentation._parse(this, original, source, options);\n };\n };\n }\n\n private _patchValidate(): (original: validateType) => validateType {\n const instrumentation = this;\n return function validate(original: validateType) {\n return function patchValidate(\n this: validateType,\n schema: GraphQLSchema,\n documentAST: DocumentNode,\n rules?: ReadonlyArray<ValidationRule>,\n options?: { maxErrors?: number },\n typeInfo?: TypeInfo,\n ): ReadonlyArray<GraphQLError> {\n return instrumentation._validate(this, original, schema, documentAST, rules, typeInfo, options);\n };\n };\n }\n\n private _parse(obj: parseType, original: parseType, source: string | Source, options?: ParseOptions): DocumentNode {\n const config = this.getConfig();\n const span = this.tracer.startSpan(SpanNames.PARSE);\n\n return context.with(trace.setSpan(context.active(), span), () => {\n return safeExecuteInTheMiddle<DocumentNode & ObjectWithGraphQLData>(\n () => {\n return original.call(obj, source, options);\n },\n (err, result) => {\n if (result) {\n const operation = getOperation(result);\n if (!operation) {\n span.updateName(SpanNames.SCHEMA_PARSE);\n } else if (result.loc) {\n addSpanSource(span, result.loc, config.allowValues);\n }\n }\n endSpan(span, err);\n },\n );\n });\n }\n\n private _validate(\n obj: validateType,\n original: validateType,\n schema: GraphQLSchema,\n documentAST: DocumentNode,\n rules?: ReadonlyArray<ValidationRule>,\n typeInfo?: TypeInfo,\n options?: { maxErrors?: number },\n ): ReadonlyArray<GraphQLError> {\n const span = this.tracer.startSpan(SpanNames.VALIDATE, {});\n\n return context.with(trace.setSpan(context.active(), span), () => {\n return safeExecuteInTheMiddle<ReadonlyArray<GraphQLError>>(\n () => {\n return original.call(obj, schema, documentAST, rules, options, typeInfo);\n },\n (err, errors) => {\n if (!documentAST.loc) {\n span.updateName(SpanNames.SCHEMA_VALIDATE);\n }\n if (errors && errors.length) {\n span.recordException({\n name: AttributeNames.ERROR_VALIDATION_NAME,\n message: JSON.stringify(errors),\n });\n }\n endSpan(span, err);\n },\n );\n });\n }\n\n private _createExecuteSpan(operation: DefinitionNode | undefined, processedArgs: ExecutionArgs): api.Span {\n const config = this.getConfig();\n\n const span = this.tracer.startSpan(SpanNames.EXECUTE, {});\n if (operation) {\n const { operation: operationType, name: nameNode } = operation as OperationDefinitionNode;\n\n span.setAttribute(AttributeNames.OPERATION_TYPE, operationType);\n\n const operationName = nameNode?.value;\n\n // https://opentelemetry.io/docs/reference/specification/trace/semantic_conventions/instrumentation/graphql/\n // > The span name MUST be of the format <graphql.operation.type> <graphql.operation.name> provided that graphql.operation.type and graphql.operation.name are available.\n // > If graphql.operation.name is not available, the span SHOULD be named <graphql.operation.type>.\n if (operationName) {\n span.setAttribute(AttributeNames.OPERATION_NAME, operationName);\n span.updateName(`${operationType} ${operationName}`);\n } else {\n span.updateName(operationType);\n }\n } else {\n let operationName = ' ';\n if (processedArgs.operationName) {\n operationName = ` \"${processedArgs.operationName}\" `;\n }\n operationName = OPERATION_NOT_SUPPORTED.replace('$operationName$', operationName);\n span.setAttribute(AttributeNames.OPERATION_NAME, operationName);\n }\n\n if (processedArgs.document?.loc) {\n addSpanSource(span, processedArgs.document.loc, config.allowValues);\n }\n\n if (processedArgs.variableValues && config.allowValues) {\n addInputVariableAttributes(span, processedArgs.variableValues);\n }\n\n return span;\n }\n\n private _wrapExecuteArgs(\n schema: GraphQLSchema,\n document: DocumentNode,\n rootValue: any,\n contextValue: any,\n variableValues: Maybe<{ [key: string]: any }>,\n operationName: Maybe<string>,\n fieldResolver: Maybe<GraphQLFieldResolver<any, any>>,\n typeResolver: Maybe<GraphQLTypeResolver<any, any>>,\n defaultFieldResolved: GraphQLFieldResolver<any, any>,\n ): OtelExecutionArgs {\n if (!contextValue) {\n contextValue = {};\n }\n\n if (contextValue[OTEL_GRAPHQL_DATA_SYMBOL] || this.getConfig().ignoreResolveSpans) {\n return {\n schema,\n document,\n rootValue,\n contextValue,\n variableValues,\n operationName,\n fieldResolver,\n typeResolver,\n };\n }\n\n const isUsingDefaultResolver = fieldResolver == null;\n // follows graphql implementation here:\n // https://github.com/graphql/graphql-js/blob/0b7daed9811731362c71900e12e5ea0d1ecc7f1f/src/execution/execute.ts#L494\n const fieldResolverForExecute = fieldResolver ?? defaultFieldResolved;\n fieldResolver = wrapFieldResolver(\n this.tracer,\n () => this.getConfig(),\n fieldResolverForExecute,\n isUsingDefaultResolver,\n );\n\n if (schema) {\n wrapFields(schema.getQueryType() as any, this.tracer, () => this.getConfig());\n wrapFields(schema.getMutationType() as any, this.tracer, () => this.getConfig());\n }\n\n return {\n schema,\n document,\n rootValue,\n contextValue,\n variableValues,\n operationName,\n fieldResolver,\n typeResolver,\n };\n }\n}\n"],"names":["InstrumentationBase","SDK_VERSION","InstrumentationNodeModuleDefinition","InstrumentationNodeModuleFile","isWrapped","instrumentation","getOperation","OTEL_GRAPHQL_DATA_SYMBOL","context","trace","safeExecuteInTheMiddle","endSpan","isPromise","SpanNames","addSpanSource","AttributeNames","OPERATION_NOT_SUPPORTED","addInputVariableAttributes","wrapFieldResolver","wrapFields"],"mappings":";;;;;;;;;;;AA4EA,MAAM,YAAA,GAAe,iCAAA;AAErB,MAAM,cAAA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,kBAAA,EAAoB;AACjF,MAAA,OAAO;AAAA,QACL,MAAA;AAAA,QACA,QAAA;AAAA,QACA,SAAA;AAAA,QACA,YAAA;AAAA,QACA,cAAA;AAAA,QACA,aAAA;AAAA,QACA,aAAA;AAAA,QACA;AAAA,OACF;AAAA,IACF;AAEA,IAAA,MAAM,yBAAyB,aAAA,IAAiB,IAAA;AAGhD,IAAA,MAAM,0BAA0B,aAAA,IAAiB,oBAAA;AACjD,IAAA,aAAA,GAAgBW,uBAAA;AAAA,MACd,IAAA,CAAK,MAAA;AAAA,MACL,MAAM,KAAK,SAAA,EAAU;AAAA,MACrB,uBAAA;AAAA,MACA;AAAA,KACF;AAEA,IAAA,IAAI,MAAA,EAAQ;AACV,MAAAC,gBAAA,CAAW,MAAA,CAAO,cAAa,EAAU,IAAA,CAAK,QAAQ,MAAM,IAAA,CAAK,WAAW,CAAA;AAC5E,MAAAA,gBAAA,CAAW,MAAA,CAAO,iBAAgB,EAAU,IAAA,CAAK,QAAQ,MAAM,IAAA,CAAK,WAAW,CAAA;AAAA,IACjF;AAEA,IAAA,OAAO;AAAA,MACL,MAAA;AAAA,MACA,QAAA;AAAA,MACA,SAAA;AAAA,MACA,YAAA;AAAA,MACA,cAAA;AAAA,MACA,aAAA;AAAA,MACA,aAAA;AAAA,MACA;AAAA,KACF;AAAA,EACF;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"instrumentation.js","sources":["../../../../../../src/integrations/tracing/graphql/vendored/instrumentation.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * NOTICE from the Sentry authors:\n * - Vendored from: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/15ef7506553f631ea4181391e0c5725a56f0d082/packages/instrumentation-graphql\n * - Upstream version: @opentelemetry/instrumentation-graphql@0.66.0\n * - Types from `graphql` package inlined as simplified interfaces\n * - Minor TypeScript strictness adjustments\n */\n/* eslint-disable */\n\nimport { context, trace } from '@opentelemetry/api';\nimport {\n isWrapped,\n InstrumentationBase,\n InstrumentationNodeModuleDefinition,\n safeExecuteInTheMiddle,\n} from '@opentelemetry/instrumentation';\nimport { InstrumentationNodeModuleFile } from '../../InstrumentationNodeModuleFile';\nimport type {\n DefinitionNode,\n DocumentNode,\n ExecutionArgs,\n ExecutionResult,\n GraphQLError,\n GraphQLFieldResolver,\n GraphQLSchema,\n GraphQLTypeResolver,\n OperationDefinitionNode,\n ParseOptions,\n PromiseOrValue,\n Source,\n TypeInfo,\n ValidationRule,\n} from './graphql-types';\nimport type { Maybe } from './graphql-types';\nimport { SpanNames } from './enum';\nimport { AttributeNames } from './enums/AttributeNames';\nimport { OTEL_GRAPHQL_DATA_SYMBOL } from './symbols';\n\nimport {\n executeFunctionWithObj,\n executeArgumentsArray,\n executeType,\n parseType,\n validateType,\n OtelExecutionArgs,\n ObjectWithGraphQLData,\n OPERATION_NOT_SUPPORTED,\n} from './internal-types';\nimport {\n addInputVariableAttributes,\n addSpanSource,\n endSpan,\n getOperation,\n isPromise,\n wrapFieldResolver,\n wrapFields,\n} from './utils';\n\nimport { SDK_VERSION } from '@sentry/core';\nimport * as api from '@opentelemetry/api';\nimport { GraphQLInstrumentationConfig, GraphQLInstrumentationParsedConfig } from './types';\n\nconst PACKAGE_NAME = '@sentry/instrumentation-graphql';\n\nconst DEFAULT_CONFIG: GraphQLInstrumentationParsedConfig = {\n mergeItems: false,\n depth: -1,\n allowValues: false,\n ignoreResolveSpans: false,\n};\n\nconst supportedVersions = ['>=14.0.0 <17'];\n\nexport class GraphQLInstrumentation extends InstrumentationBase<GraphQLInstrumentationParsedConfig> {\n constructor(config: GraphQLInstrumentationConfig = {}) {\n super(PACKAGE_NAME, SDK_VERSION, { ...DEFAULT_CONFIG, ...config });\n }\n\n override setConfig(config: GraphQLInstrumentationConfig = {}) {\n super.setConfig({ ...DEFAULT_CONFIG, ...config });\n }\n\n protected init() {\n const module = new InstrumentationNodeModuleDefinition('graphql', supportedVersions);\n module.files.push(this._addPatchingExecute());\n module.files.push(this._addPatchingParser());\n module.files.push(this._addPatchingValidate());\n\n return module;\n }\n\n private _addPatchingExecute(): InstrumentationNodeModuleFile {\n return new InstrumentationNodeModuleFile(\n 'graphql/execution/execute.js',\n supportedVersions,\n // cannot make it work with appropriate type as execute function has 2\n //types and/cannot import function but only types\n (moduleExports: any) => {\n if (isWrapped(moduleExports.execute)) {\n this._unwrap(moduleExports, 'execute');\n }\n this._wrap(moduleExports, 'execute', this._patchExecute(moduleExports.defaultFieldResolver));\n return moduleExports;\n },\n moduleExports => {\n if (moduleExports) {\n this._unwrap(moduleExports, 'execute');\n }\n },\n );\n }\n\n private _addPatchingParser(): InstrumentationNodeModuleFile {\n return new InstrumentationNodeModuleFile(\n 'graphql/language/parser.js',\n supportedVersions,\n (moduleExports: { parse: parseType; [key: string]: any }) => {\n if (isWrapped(moduleExports.parse)) {\n this._unwrap(moduleExports, 'parse');\n }\n this._wrap(moduleExports, 'parse', this._patchParse());\n return moduleExports;\n },\n (moduleExports: { parse: parseType; [key: string]: any }) => {\n if (moduleExports) {\n this._unwrap(moduleExports, 'parse');\n }\n },\n );\n }\n\n private _addPatchingValidate(): InstrumentationNodeModuleFile {\n return new InstrumentationNodeModuleFile(\n 'graphql/validation/validate.js',\n supportedVersions,\n moduleExports => {\n if (isWrapped(moduleExports.validate)) {\n this._unwrap(moduleExports, 'validate');\n }\n this._wrap(moduleExports, 'validate', this._patchValidate());\n return moduleExports;\n },\n moduleExports => {\n if (moduleExports) {\n this._unwrap(moduleExports, 'validate');\n }\n },\n );\n }\n\n private _patchExecute(defaultFieldResolved: GraphQLFieldResolver<any, any>): (original: executeType) => executeType {\n const instrumentation = this;\n return function execute(original) {\n return function patchExecute(this: executeType): PromiseOrValue<ExecutionResult> {\n let processedArgs: OtelExecutionArgs;\n\n // case when apollo server is used for example\n if (arguments.length >= 2) {\n const args = arguments as unknown as executeArgumentsArray;\n processedArgs = instrumentation._wrapExecuteArgs(\n args[0],\n args[1],\n args[2],\n args[3],\n args[4],\n args[5],\n args[6],\n args[7],\n defaultFieldResolved,\n );\n } else {\n const args = arguments[0] as ExecutionArgs;\n processedArgs = instrumentation._wrapExecuteArgs(\n args.schema,\n args.document,\n args.rootValue,\n args.contextValue,\n args.variableValues,\n args.operationName,\n args.fieldResolver,\n args.typeResolver,\n defaultFieldResolved,\n );\n }\n\n const operation = getOperation(processedArgs.document, processedArgs.operationName);\n\n const span = instrumentation._createExecuteSpan(operation, processedArgs);\n\n processedArgs.contextValue[OTEL_GRAPHQL_DATA_SYMBOL] = {\n source: processedArgs.document\n ? processedArgs.document || (processedArgs.document as ObjectWithGraphQLData)[OTEL_GRAPHQL_DATA_SYMBOL]\n : undefined,\n span,\n fields: {},\n };\n\n return context.with(trace.setSpan(context.active(), span), () => {\n return safeExecuteInTheMiddle<PromiseOrValue<ExecutionResult>>(\n () => {\n return (original as executeFunctionWithObj).apply(this, [processedArgs]);\n },\n (err, result) => {\n instrumentation._handleExecutionResult(span, err, result);\n },\n );\n });\n };\n };\n }\n\n private _handleExecutionResult(span: api.Span, err?: Error, result?: PromiseOrValue<ExecutionResult>) {\n const config = this.getConfig();\n if (result === undefined || err) {\n endSpan(span, err);\n return;\n }\n\n if (isPromise(result)) {\n (result as Promise<ExecutionResult>).then(\n resultData => {\n if (typeof config.responseHook !== 'function') {\n endSpan(span);\n return;\n }\n this._executeResponseHook(span, resultData);\n },\n error => {\n endSpan(span, error);\n },\n );\n } else {\n if (typeof config.responseHook !== 'function') {\n endSpan(span);\n return;\n }\n this._executeResponseHook(span, result as ExecutionResult);\n }\n }\n\n private _executeResponseHook(span: api.Span, result: ExecutionResult) {\n const { responseHook } = this.getConfig();\n if (!responseHook) {\n return;\n }\n\n safeExecuteInTheMiddle(\n () => {\n responseHook(span, result);\n },\n err => {\n if (err) {\n this._diag.error('Error running response hook', err);\n }\n\n endSpan(span, undefined);\n },\n true,\n );\n }\n\n private _patchParse(): (original: parseType) => parseType {\n const instrumentation = this;\n return function parse(original) {\n return function patchParse(this: parseType, source: string | Source, options?: ParseOptions): DocumentNode {\n return instrumentation._parse(this, original, source, options);\n };\n };\n }\n\n private _patchValidate(): (original: validateType) => validateType {\n const instrumentation = this;\n return function validate(original: validateType) {\n return function patchValidate(\n this: validateType,\n schema: GraphQLSchema,\n documentAST: DocumentNode,\n rules?: ReadonlyArray<ValidationRule>,\n options?: { maxErrors?: number },\n typeInfo?: TypeInfo,\n ): ReadonlyArray<GraphQLError> {\n return instrumentation._validate(this, original, schema, documentAST, rules, typeInfo, options);\n };\n };\n }\n\n private _parse(obj: parseType, original: parseType, source: string | Source, options?: ParseOptions): DocumentNode {\n const config = this.getConfig();\n const span = this.tracer.startSpan(SpanNames.PARSE);\n\n return context.with(trace.setSpan(context.active(), span), () => {\n return safeExecuteInTheMiddle<DocumentNode & ObjectWithGraphQLData>(\n () => {\n return original.call(obj, source, options);\n },\n (err, result) => {\n if (result) {\n const operation = getOperation(result);\n if (!operation) {\n span.updateName(SpanNames.SCHEMA_PARSE);\n } else if (result.loc) {\n addSpanSource(span, result.loc, config.allowValues);\n }\n }\n endSpan(span, err);\n },\n );\n });\n }\n\n private _validate(\n obj: validateType,\n original: validateType,\n schema: GraphQLSchema,\n documentAST: DocumentNode,\n rules?: ReadonlyArray<ValidationRule>,\n typeInfo?: TypeInfo,\n options?: { maxErrors?: number },\n ): ReadonlyArray<GraphQLError> {\n const span = this.tracer.startSpan(SpanNames.VALIDATE, {});\n\n return context.with(trace.setSpan(context.active(), span), () => {\n return safeExecuteInTheMiddle<ReadonlyArray<GraphQLError>>(\n () => {\n return original.call(obj, schema, documentAST, rules, options, typeInfo);\n },\n (err, errors) => {\n if (!documentAST.loc) {\n span.updateName(SpanNames.SCHEMA_VALIDATE);\n }\n if (errors && errors.length) {\n span.recordException({\n name: AttributeNames.ERROR_VALIDATION_NAME,\n message: JSON.stringify(errors),\n });\n }\n endSpan(span, err);\n },\n );\n });\n }\n\n private _createExecuteSpan(operation: DefinitionNode | undefined, processedArgs: ExecutionArgs): api.Span {\n const config = this.getConfig();\n\n const span = this.tracer.startSpan(SpanNames.EXECUTE, {});\n if (operation) {\n const { operation: operationType, name: nameNode } = operation as OperationDefinitionNode;\n\n span.setAttribute(AttributeNames.OPERATION_TYPE, operationType);\n\n const operationName = nameNode?.value;\n\n // https://opentelemetry.io/docs/reference/specification/trace/semantic_conventions/instrumentation/graphql/\n // > The span name MUST be of the format <graphql.operation.type> <graphql.operation.name> provided that graphql.operation.type and graphql.operation.name are available.\n // > If graphql.operation.name is not available, the span SHOULD be named <graphql.operation.type>.\n if (operationName) {\n span.setAttribute(AttributeNames.OPERATION_NAME, operationName);\n span.updateName(`${operationType} ${operationName}`);\n } else {\n span.updateName(operationType);\n }\n } else {\n let operationName = ' ';\n if (processedArgs.operationName) {\n operationName = ` \"${processedArgs.operationName}\" `;\n }\n operationName = OPERATION_NOT_SUPPORTED.replace('$operationName$', operationName);\n span.setAttribute(AttributeNames.OPERATION_NAME, operationName);\n }\n\n if (processedArgs.document?.loc) {\n addSpanSource(span, processedArgs.document.loc, config.allowValues);\n }\n\n if (processedArgs.variableValues && config.allowValues) {\n addInputVariableAttributes(span, processedArgs.variableValues);\n }\n\n return span;\n }\n\n private _wrapExecuteArgs(\n schema: GraphQLSchema,\n document: DocumentNode,\n rootValue: any,\n contextValue: any,\n variableValues: Maybe<{ [key: string]: any }>,\n operationName: Maybe<string>,\n fieldResolver: Maybe<GraphQLFieldResolver<any, any>>,\n typeResolver: Maybe<GraphQLTypeResolver<any, any>>,\n defaultFieldResolved: GraphQLFieldResolver<any, any>,\n ): OtelExecutionArgs {\n if (!contextValue) {\n contextValue = {};\n }\n\n if (contextValue[OTEL_GRAPHQL_DATA_SYMBOL] || this.getConfig().ignoreResolveSpans) {\n return {\n schema,\n document,\n rootValue,\n contextValue,\n variableValues,\n operationName,\n fieldResolver,\n typeResolver,\n };\n }\n\n const isUsingDefaultResolver = fieldResolver == null;\n // follows graphql implementation here:\n // https://github.com/graphql/graphql-js/blob/0b7daed9811731362c71900e12e5ea0d1ecc7f1f/src/execution/execute.ts#L494\n const fieldResolverForExecute = fieldResolver ?? defaultFieldResolved;\n fieldResolver = wrapFieldResolver(\n this.tracer,\n () => this.getConfig(),\n fieldResolverForExecute,\n isUsingDefaultResolver,\n );\n\n if (schema) {\n wrapFields(schema.getQueryType() as any, this.tracer, () => this.getConfig());\n wrapFields(schema.getMutationType() as any, this.tracer, () => this.getConfig());\n }\n\n return {\n schema,\n document,\n rootValue,\n contextValue,\n variableValues,\n operationName,\n fieldResolver,\n typeResolver,\n };\n }\n}\n"],"names":["InstrumentationBase","SDK_VERSION","InstrumentationNodeModuleDefinition","InstrumentationNodeModuleFile","isWrapped","instrumentation","getOperation","OTEL_GRAPHQL_DATA_SYMBOL","context","trace","safeExecuteInTheMiddle","endSpan","isPromise","SpanNames","addSpanSource","AttributeNames","OPERATION_NOT_SUPPORTED","addInputVariableAttributes","wrapFieldResolver","wrapFields"],"mappings":";;;;;;;;;;;;AA4EA,MAAM,YAAA,GAAe,iCAAA;AAErB,MAAM,cAAA,GAAqD;AAAA,EACzD,UAAA,EAAY,KAAA;AAAA,EACZ,KAAA,EAAO,EAAA;AAAA,EACP,WAAA,EAAa,KAAA;AAAA,EACb,kBAAA,EAAoB;AACtB,CAAA;AAEA,MAAM,iBAAA,GAAoB,CAAC,cAAc,CAAA;AAElC,MAAM,+BAA+BA,mCAAA,CAAwD;AAAA,EAClG,WAAA,CAAY,MAAA,GAAuC,EAAC,EAAG;AACrD,IAAA,KAAA,CAAM,cAAcC,gBAAA,EAAa,EAAE,GAAG,cAAA,EAAgB,GAA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A;AAAA,MACL,MAAM,KAAK,SAAA,EAAU;AAAA,MACrB,uBAAA;AAAA,MACA;AAAA,KACF;AAEA,IAAA,IAAI,MAAA,EAAQ;AACV,MAAAC,gBAAA,CAAW,MAAA,CAAO,cAAa,EAAU,IAAA,CAAK,QAAQ,MAAM,IAAA,CAAK,WAAW,CAAA;AAC5E,MAAAA,gBAAA,CAAW,MAAA,CAAO,iBAAgB,EAAU,IAAA,CAAK,QAAQ,MAAM,IAAA,CAAK,WAAW,CAAA;AAAA,IACjF;AAEA,IAAA,OAAO;AAAA,MACL,MAAA;AAAA,MACA,QAAA;AAAA,MACA,SAAA;AAAA,MACA,YAAA;AAAA,MACA,cAAA;AAAA,MACA,aAAA;AAAA,MACA,aAAA;AAAA,MACA;AAAA,KACF;AAAA,EACF;AACF;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
|
|
3
3
|
const api = require('@opentelemetry/api');
|
|
4
|
-
const
|
|
4
|
+
const setHttpServerSpanRouteAttribute = require('../../../../utils/setHttpServerSpanRouteAttribute.js');
|
|
5
5
|
const instrumentation = require('@opentelemetry/instrumentation');
|
|
6
6
|
const core = require('@sentry/core');
|
|
7
7
|
const internalTypes = require('./internal-types.js');
|
|
@@ -228,10 +228,7 @@ class HapiInstrumentation extends instrumentation.InstrumentationBase {
|
|
|
228
228
|
if (api.trace.getSpan(api.context.active()) === void 0) {
|
|
229
229
|
return await oldHandler.call(this, ...params);
|
|
230
230
|
}
|
|
231
|
-
|
|
232
|
-
if (rpcMetadata?.type === core$1.RPCType.HTTP) {
|
|
233
|
-
rpcMetadata.route = route.path;
|
|
234
|
-
}
|
|
231
|
+
setHttpServerSpanRouteAttribute.setHttpServerSpanRouteAttribute(route.path);
|
|
235
232
|
const metadata = utils.getRouteMetadata(route, instrumentation._semconvStability, pluginName);
|
|
236
233
|
const span = instrumentation.tracer.startSpan(metadata.name, {
|
|
237
234
|
attributes: metadata.attributes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentation.js","sources":["../../../../../../src/integrations/tracing/hapi/vendored/instrumentation.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * NOTICE from the Sentry authors:\n * - Vendored from: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/15ef7506553f631ea4181391e0c5725a56f0d082/packages/instrumentation-hapi\n * - Upstream version: @opentelemetry/instrumentation-hapi@0.64.0\n * - Types vendored from @hapi/hapi as simplified interfaces\n * - Minor TypeScript strictness adjustments for this repository's compiler settings\n */\n/* eslint-disable */\n\nimport * as api from '@opentelemetry/api';\nimport { getRPCMetadata, RPCType } from '@opentelemetry/core';\nimport {\n InstrumentationBase,\n InstrumentationConfig,\n InstrumentationNodeModuleDefinition,\n isWrapped,\n SemconvStability,\n semconvStabilityFromStr,\n} from '@opentelemetry/instrumentation';\n\nimport type * as Hapi from './hapi-types';\nimport { SDK_VERSION } from '@sentry/core';\nimport {\n HapiComponentName,\n HapiServerRouteInput,\n handlerPatched,\n PatchableServerRoute,\n HapiServerRouteInputMethod,\n HapiPluginInput,\n RegisterFunction,\n PatchableExtMethod,\n ServerExtDirectInput,\n} from './internal-types';\nimport {\n getRouteMetadata,\n getPluginName,\n isLifecycleExtType,\n isLifecycleExtEventObj,\n getExtMetadata,\n isDirectExtInput,\n isPatchableExtMethod,\n getPluginFromInput,\n} from './utils';\n\nconst PACKAGE_NAME = '@sentry/instrumentation-hapi';\n\n/** Hapi instrumentation for OpenTelemetry */\nexport class HapiInstrumentation extends InstrumentationBase {\n private _semconvStability: SemconvStability;\n\n constructor(config: InstrumentationConfig = {}) {\n super(PACKAGE_NAME, SDK_VERSION, config);\n this._semconvStability = semconvStabilityFromStr('http', process.env.OTEL_SEMCONV_STABILITY_OPT_IN);\n }\n\n protected init() {\n return new InstrumentationNodeModuleDefinition(\n HapiComponentName,\n ['>=17.0.0 <22'],\n (module: any) => {\n const moduleExports: typeof Hapi = module[Symbol.toStringTag] === 'Module' ? module.default : module;\n if (!isWrapped(moduleExports.server)) {\n this._wrap(moduleExports, 'server', this._getServerPatch.bind(this) as any);\n }\n\n if (!isWrapped(moduleExports.Server)) {\n this._wrap(moduleExports, 'Server', this._getServerPatch.bind(this) as any);\n }\n return moduleExports;\n },\n (module: any) => {\n const moduleExports: typeof Hapi = module[Symbol.toStringTag] === 'Module' ? module.default : module;\n this._massUnwrap([moduleExports], ['server', 'Server']);\n },\n );\n }\n\n /**\n * Patches the Hapi.server and Hapi.Server functions in order to instrument\n * the server.route, server.ext, and server.register functions via calls to the\n * @function _getServerRoutePatch, @function _getServerExtPatch, and\n * @function _getServerRegisterPatch functions\n * @param original - the original Hapi Server creation function\n */\n private _getServerPatch(original: (options?: Hapi.ServerOptions) => Hapi.Server) {\n const instrumentation: HapiInstrumentation = this;\n const self = this;\n return function server(this: Hapi.Server, opts?: Hapi.ServerOptions) {\n const newServer: Hapi.Server = original.apply(this, [opts]);\n\n self._wrap(newServer, 'route', originalRouter => {\n return instrumentation._getServerRoutePatch.bind(instrumentation)(originalRouter);\n });\n\n // Casting as any is necessary here due to multiple overloads on the Hapi.ext\n // function, which requires supporting a variety of different parameters\n // as extension inputs\n self._wrap(newServer, 'ext', originalExtHandler => {\n return instrumentation._getServerExtPatch.bind(instrumentation)(originalExtHandler as any);\n });\n\n // Casting as any is necessary here due to multiple overloads on the Hapi.Server.register\n // function, which requires supporting a variety of different types of Plugin inputs\n self._wrap(newServer, 'register', instrumentation._getServerRegisterPatch.bind(instrumentation) as any);\n return newServer;\n };\n }\n\n /**\n * Patches the plugin register function used by the Hapi Server. This function\n * goes through each plugin that is being registered and adds instrumentation\n * via a call to the @function _wrapRegisterHandler function.\n * @param {RegisterFunction<T>} original - the original register function which\n * registers each plugin on the server\n */\n private _getServerRegisterPatch<T>(original: RegisterFunction<T>): RegisterFunction<T> {\n const instrumentation: HapiInstrumentation = this;\n return function register(this: Hapi.Server, pluginInput: HapiPluginInput<T>, options?: Hapi.ServerRegisterOptions) {\n if (Array.isArray(pluginInput)) {\n for (const pluginObj of pluginInput) {\n const plugin = getPluginFromInput(pluginObj);\n instrumentation._wrapRegisterHandler(plugin);\n }\n } else {\n const plugin = getPluginFromInput(pluginInput);\n instrumentation._wrapRegisterHandler(plugin);\n }\n return original.apply(this, [pluginInput, options]);\n };\n }\n\n /**\n * Patches the Server.ext function which adds extension methods to the specified\n * point along the request lifecycle. This function accepts the full range of\n * accepted input into the standard Hapi `server.ext` function. For each extension,\n * it adds instrumentation to the handler via a call to the @function _wrapExtMethods\n * function.\n * @param original - the original ext function which adds the extension method to the server\n * @param {string} [pluginName] - if present, represents the name of the plugin responsible\n * for adding this server extension. Else, signifies that the extension was added directly\n */\n private _getServerExtPatch(original: (...args: unknown[]) => unknown, pluginName?: string) {\n const instrumentation: HapiInstrumentation = this;\n\n return function ext(this: ThisParameterType<typeof original>, ...args: Parameters<typeof original>) {\n if (Array.isArray(args[0])) {\n const eventsList: Hapi.ServerExtEventsObject[] | Hapi.ServerExtEventsRequestObject[] = args[0];\n for (let i = 0; i < eventsList.length; i++) {\n const eventObj = eventsList[i]!;\n if (isLifecycleExtType(eventObj.type)) {\n const lifecycleEventObj = eventObj as Hapi.ServerExtEventsRequestObject;\n const handler = instrumentation._wrapExtMethods(lifecycleEventObj.method, eventObj.type, pluginName);\n lifecycleEventObj.method = handler;\n eventsList[i] = lifecycleEventObj;\n }\n }\n return original.apply(this, args);\n } else if (isDirectExtInput(args)) {\n const extInput: ServerExtDirectInput = args;\n const method: PatchableExtMethod = extInput[1];\n const handler = instrumentation._wrapExtMethods(method, extInput[0], pluginName);\n return original.apply(this, [extInput[0], handler, extInput[2]]);\n } else if (isLifecycleExtEventObj(args[0])) {\n const lifecycleEventObj = args[0];\n const handler = instrumentation._wrapExtMethods(lifecycleEventObj.method, lifecycleEventObj.type, pluginName);\n lifecycleEventObj.method = handler;\n return original.call(this, lifecycleEventObj);\n }\n return original.apply(this, args);\n };\n }\n\n /**\n * Patches the Server.route function. This function accepts either one or an array\n * of Hapi.ServerRoute objects and adds instrumentation on each route via a call to\n * the @function _wrapRouteHandler function.\n * @param {HapiServerRouteInputMethod} original - the original route function which adds\n * the route to the server\n * @param {string} [pluginName] - if present, represents the name of the plugin responsible\n * for adding this server route. Else, signifies that the route was added directly\n */\n private _getServerRoutePatch(original: HapiServerRouteInputMethod, pluginName?: string) {\n const instrumentation: HapiInstrumentation = this;\n return function route(this: Hapi.Server, route: HapiServerRouteInput): void {\n if (Array.isArray(route)) {\n for (let i = 0; i < route.length; i++) {\n const newRoute = instrumentation._wrapRouteHandler.call(instrumentation, route[i]!, pluginName);\n route[i] = newRoute;\n }\n } else {\n route = instrumentation._wrapRouteHandler.call(instrumentation, route, pluginName);\n }\n return original.apply(this, [route]);\n };\n }\n\n /**\n * Wraps newly registered plugins to add instrumentation to the plugin's clone of\n * the original server. Specifically, wraps the server.route and server.ext functions\n * via calls to @function _getServerRoutePatch and @function _getServerExtPatch\n * @param {Hapi.Plugin<T>} plugin - the new plugin which is being instrumented\n */\n private _wrapRegisterHandler<T>(plugin: Hapi.Plugin<T>): void {\n const instrumentation: HapiInstrumentation = this;\n const pluginName = getPluginName(plugin);\n const oldRegister = plugin.register;\n const self = this;\n const newRegisterHandler = function (this: typeof plugin, server: Hapi.Server, options: T) {\n self._wrap(server, 'route', original => {\n return instrumentation._getServerRoutePatch.bind(instrumentation)(original, pluginName);\n });\n\n // Casting as any is necessary here due to multiple overloads on the Hapi.ext\n // function, which requires supporting a variety of different parameters\n // as extension inputs\n self._wrap(server, 'ext', originalExtHandler => {\n return instrumentation._getServerExtPatch.bind(instrumentation)(originalExtHandler as any, pluginName);\n });\n return oldRegister.call(this, server, options);\n };\n plugin.register = newRegisterHandler;\n }\n\n /**\n * Wraps request extension methods to add instrumentation to each new extension handler.\n * Patches each individual extension in order to create the\n * span and propagate context. It does not create spans when there is no parent span.\n * @param {PatchableExtMethod | PatchableExtMethod[]} method - the request extension\n * handler which is being instrumented\n * @param {Hapi.ServerRequestExtType} extPoint - the point in the Hapi request lifecycle\n * which this extension targets\n * @param {string} [pluginName] - if present, represents the name of the plugin responsible\n * for adding this server route. Else, signifies that the route was added directly\n */\n private _wrapExtMethods<T extends PatchableExtMethod | PatchableExtMethod[]>(\n method: T,\n extPoint: Hapi.ServerRequestExtType,\n pluginName?: string,\n ): T {\n const instrumentation: HapiInstrumentation = this;\n if (method instanceof Array) {\n for (let i = 0; i < method.length; i++) {\n method[i] = instrumentation._wrapExtMethods(method[i]!, extPoint) as PatchableExtMethod;\n }\n return method;\n } else if (isPatchableExtMethod(method)) {\n if (method[handlerPatched] === true) return method;\n method[handlerPatched] = true;\n\n const newHandler: PatchableExtMethod = async function (this: any, ...params: Parameters<Hapi.Lifecycle.Method>) {\n if (api.trace.getSpan(api.context.active()) === undefined) {\n return await method.apply(this, params);\n }\n const metadata = getExtMetadata(extPoint, pluginName, method.name);\n const span = instrumentation.tracer.startSpan(metadata.name, {\n attributes: metadata.attributes,\n });\n try {\n return await api.context.with<Parameters<Hapi.Lifecycle.Method>, Hapi.Lifecycle.Method>(\n api.trace.setSpan(api.context.active(), span),\n method,\n undefined,\n ...params,\n );\n } catch (err: any) {\n span.recordException(err);\n span.setStatus({\n code: api.SpanStatusCode.ERROR,\n message: err.message,\n });\n throw err;\n } finally {\n span.end();\n }\n };\n return newHandler as T;\n }\n return method;\n }\n\n /**\n * Patches each individual route handler method in order to create the\n * span and propagate context. It does not create spans when there is no parent span.\n * @param {PatchableServerRoute} route - the route handler which is being instrumented\n * @param {string} [pluginName] - if present, represents the name of the plugin responsible\n * for adding this server route. Else, signifies that the route was added directly\n */\n private _wrapRouteHandler(route: PatchableServerRoute, pluginName?: string): PatchableServerRoute {\n const instrumentation: HapiInstrumentation = this;\n if (route[handlerPatched] === true) return route;\n route[handlerPatched] = true;\n\n const wrapHandler: (oldHandler: Hapi.Lifecycle.Method) => Hapi.Lifecycle.Method = oldHandler => {\n return async function (this: any, ...params: Parameters<Hapi.Lifecycle.Method>) {\n if (api.trace.getSpan(api.context.active()) === undefined) {\n return await oldHandler.call(this, ...params);\n }\n const rpcMetadata = getRPCMetadata(api.context.active());\n if (rpcMetadata?.type === RPCType.HTTP) {\n rpcMetadata.route = route.path;\n }\n const metadata = getRouteMetadata(route, instrumentation._semconvStability, pluginName);\n const span = instrumentation.tracer.startSpan(metadata.name, {\n attributes: metadata.attributes,\n });\n try {\n return await api.context.with(api.trace.setSpan(api.context.active(), span), () =>\n oldHandler.call(this, ...params),\n );\n } catch (err: any) {\n span.recordException(err);\n span.setStatus({\n code: api.SpanStatusCode.ERROR,\n message: err.message,\n });\n throw err;\n } finally {\n span.end();\n }\n };\n };\n\n if (typeof route.handler === 'function') {\n route.handler = wrapHandler(route.handler as Hapi.Lifecycle.Method);\n } else if (typeof route.options === 'function') {\n const oldOptions = route.options;\n route.options = function (server) {\n const options = oldOptions(server);\n if (typeof options.handler === 'function') {\n options.handler = wrapHandler(options.handler as Hapi.Lifecycle.Method);\n }\n return options;\n };\n } else if (typeof route.options?.handler === 'function') {\n route.options.handler = wrapHandler(route.options.handler as Hapi.Lifecycle.Method);\n }\n return route;\n }\n}\n"],"names":["InstrumentationBase","SDK_VERSION","semconvStabilityFromStr","InstrumentationNodeModuleDefinition","HapiComponentName","isWrapped","getPluginFromInput","isLifecycleExtType","isDirectExtInput","isLifecycleExtEventObj","getPluginName","isPatchableExtMethod","handlerPatched","getExtMetadata","getRPCMetadata","RPCType","getRouteMetadata"],"mappings":";;;;;;;;;AA0DA,MAAM,YAAA,GAAe,8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AACA,IAAA,OAAO,KAAA;AAAA,EACT;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"instrumentation.js","sources":["../../../../../../src/integrations/tracing/hapi/vendored/instrumentation.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * NOTICE from the Sentry authors:\n * - Vendored from: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/15ef7506553f631ea4181391e0c5725a56f0d082/packages/instrumentation-hapi\n * - Upstream version: @opentelemetry/instrumentation-hapi@0.64.0\n * - Types vendored from @hapi/hapi as simplified interfaces\n * - Minor TypeScript strictness adjustments for this repository's compiler settings\n */\n/* eslint-disable */\n\nimport * as api from '@opentelemetry/api';\nimport { setHttpServerSpanRouteAttribute } from '../../../../utils/setHttpServerSpanRouteAttribute';\nimport {\n InstrumentationBase,\n InstrumentationConfig,\n InstrumentationNodeModuleDefinition,\n isWrapped,\n SemconvStability,\n semconvStabilityFromStr,\n} from '@opentelemetry/instrumentation';\n\nimport type * as Hapi from './hapi-types';\nimport { SDK_VERSION } from '@sentry/core';\nimport {\n HapiComponentName,\n HapiServerRouteInput,\n handlerPatched,\n PatchableServerRoute,\n HapiServerRouteInputMethod,\n HapiPluginInput,\n RegisterFunction,\n PatchableExtMethod,\n ServerExtDirectInput,\n} from './internal-types';\nimport {\n getRouteMetadata,\n getPluginName,\n isLifecycleExtType,\n isLifecycleExtEventObj,\n getExtMetadata,\n isDirectExtInput,\n isPatchableExtMethod,\n getPluginFromInput,\n} from './utils';\n\nconst PACKAGE_NAME = '@sentry/instrumentation-hapi';\n\n/** Hapi instrumentation for OpenTelemetry */\nexport class HapiInstrumentation extends InstrumentationBase {\n private _semconvStability: SemconvStability;\n\n constructor(config: InstrumentationConfig = {}) {\n super(PACKAGE_NAME, SDK_VERSION, config);\n this._semconvStability = semconvStabilityFromStr('http', process.env.OTEL_SEMCONV_STABILITY_OPT_IN);\n }\n\n protected init() {\n return new InstrumentationNodeModuleDefinition(\n HapiComponentName,\n ['>=17.0.0 <22'],\n (module: any) => {\n const moduleExports: typeof Hapi = module[Symbol.toStringTag] === 'Module' ? module.default : module;\n if (!isWrapped(moduleExports.server)) {\n this._wrap(moduleExports, 'server', this._getServerPatch.bind(this) as any);\n }\n\n if (!isWrapped(moduleExports.Server)) {\n this._wrap(moduleExports, 'Server', this._getServerPatch.bind(this) as any);\n }\n return moduleExports;\n },\n (module: any) => {\n const moduleExports: typeof Hapi = module[Symbol.toStringTag] === 'Module' ? module.default : module;\n this._massUnwrap([moduleExports], ['server', 'Server']);\n },\n );\n }\n\n /**\n * Patches the Hapi.server and Hapi.Server functions in order to instrument\n * the server.route, server.ext, and server.register functions via calls to the\n * @function _getServerRoutePatch, @function _getServerExtPatch, and\n * @function _getServerRegisterPatch functions\n * @param original - the original Hapi Server creation function\n */\n private _getServerPatch(original: (options?: Hapi.ServerOptions) => Hapi.Server) {\n const instrumentation: HapiInstrumentation = this;\n const self = this;\n return function server(this: Hapi.Server, opts?: Hapi.ServerOptions) {\n const newServer: Hapi.Server = original.apply(this, [opts]);\n\n self._wrap(newServer, 'route', originalRouter => {\n return instrumentation._getServerRoutePatch.bind(instrumentation)(originalRouter);\n });\n\n // Casting as any is necessary here due to multiple overloads on the Hapi.ext\n // function, which requires supporting a variety of different parameters\n // as extension inputs\n self._wrap(newServer, 'ext', originalExtHandler => {\n return instrumentation._getServerExtPatch.bind(instrumentation)(originalExtHandler as any);\n });\n\n // Casting as any is necessary here due to multiple overloads on the Hapi.Server.register\n // function, which requires supporting a variety of different types of Plugin inputs\n self._wrap(newServer, 'register', instrumentation._getServerRegisterPatch.bind(instrumentation) as any);\n return newServer;\n };\n }\n\n /**\n * Patches the plugin register function used by the Hapi Server. This function\n * goes through each plugin that is being registered and adds instrumentation\n * via a call to the @function _wrapRegisterHandler function.\n * @param {RegisterFunction<T>} original - the original register function which\n * registers each plugin on the server\n */\n private _getServerRegisterPatch<T>(original: RegisterFunction<T>): RegisterFunction<T> {\n const instrumentation: HapiInstrumentation = this;\n return function register(this: Hapi.Server, pluginInput: HapiPluginInput<T>, options?: Hapi.ServerRegisterOptions) {\n if (Array.isArray(pluginInput)) {\n for (const pluginObj of pluginInput) {\n const plugin = getPluginFromInput(pluginObj);\n instrumentation._wrapRegisterHandler(plugin);\n }\n } else {\n const plugin = getPluginFromInput(pluginInput);\n instrumentation._wrapRegisterHandler(plugin);\n }\n return original.apply(this, [pluginInput, options]);\n };\n }\n\n /**\n * Patches the Server.ext function which adds extension methods to the specified\n * point along the request lifecycle. This function accepts the full range of\n * accepted input into the standard Hapi `server.ext` function. For each extension,\n * it adds instrumentation to the handler via a call to the @function _wrapExtMethods\n * function.\n * @param original - the original ext function which adds the extension method to the server\n * @param {string} [pluginName] - if present, represents the name of the plugin responsible\n * for adding this server extension. Else, signifies that the extension was added directly\n */\n private _getServerExtPatch(original: (...args: unknown[]) => unknown, pluginName?: string) {\n const instrumentation: HapiInstrumentation = this;\n\n return function ext(this: ThisParameterType<typeof original>, ...args: Parameters<typeof original>) {\n if (Array.isArray(args[0])) {\n const eventsList: Hapi.ServerExtEventsObject[] | Hapi.ServerExtEventsRequestObject[] = args[0];\n for (let i = 0; i < eventsList.length; i++) {\n const eventObj = eventsList[i]!;\n if (isLifecycleExtType(eventObj.type)) {\n const lifecycleEventObj = eventObj as Hapi.ServerExtEventsRequestObject;\n const handler = instrumentation._wrapExtMethods(lifecycleEventObj.method, eventObj.type, pluginName);\n lifecycleEventObj.method = handler;\n eventsList[i] = lifecycleEventObj;\n }\n }\n return original.apply(this, args);\n } else if (isDirectExtInput(args)) {\n const extInput: ServerExtDirectInput = args;\n const method: PatchableExtMethod = extInput[1];\n const handler = instrumentation._wrapExtMethods(method, extInput[0], pluginName);\n return original.apply(this, [extInput[0], handler, extInput[2]]);\n } else if (isLifecycleExtEventObj(args[0])) {\n const lifecycleEventObj = args[0];\n const handler = instrumentation._wrapExtMethods(lifecycleEventObj.method, lifecycleEventObj.type, pluginName);\n lifecycleEventObj.method = handler;\n return original.call(this, lifecycleEventObj);\n }\n return original.apply(this, args);\n };\n }\n\n /**\n * Patches the Server.route function. This function accepts either one or an array\n * of Hapi.ServerRoute objects and adds instrumentation on each route via a call to\n * the @function _wrapRouteHandler function.\n * @param {HapiServerRouteInputMethod} original - the original route function which adds\n * the route to the server\n * @param {string} [pluginName] - if present, represents the name of the plugin responsible\n * for adding this server route. Else, signifies that the route was added directly\n */\n private _getServerRoutePatch(original: HapiServerRouteInputMethod, pluginName?: string) {\n const instrumentation: HapiInstrumentation = this;\n return function route(this: Hapi.Server, route: HapiServerRouteInput): void {\n if (Array.isArray(route)) {\n for (let i = 0; i < route.length; i++) {\n const newRoute = instrumentation._wrapRouteHandler.call(instrumentation, route[i]!, pluginName);\n route[i] = newRoute;\n }\n } else {\n route = instrumentation._wrapRouteHandler.call(instrumentation, route, pluginName);\n }\n return original.apply(this, [route]);\n };\n }\n\n /**\n * Wraps newly registered plugins to add instrumentation to the plugin's clone of\n * the original server. Specifically, wraps the server.route and server.ext functions\n * via calls to @function _getServerRoutePatch and @function _getServerExtPatch\n * @param {Hapi.Plugin<T>} plugin - the new plugin which is being instrumented\n */\n private _wrapRegisterHandler<T>(plugin: Hapi.Plugin<T>): void {\n const instrumentation: HapiInstrumentation = this;\n const pluginName = getPluginName(plugin);\n const oldRegister = plugin.register;\n const self = this;\n const newRegisterHandler = function (this: typeof plugin, server: Hapi.Server, options: T) {\n self._wrap(server, 'route', original => {\n return instrumentation._getServerRoutePatch.bind(instrumentation)(original, pluginName);\n });\n\n // Casting as any is necessary here due to multiple overloads on the Hapi.ext\n // function, which requires supporting a variety of different parameters\n // as extension inputs\n self._wrap(server, 'ext', originalExtHandler => {\n return instrumentation._getServerExtPatch.bind(instrumentation)(originalExtHandler as any, pluginName);\n });\n return oldRegister.call(this, server, options);\n };\n plugin.register = newRegisterHandler;\n }\n\n /**\n * Wraps request extension methods to add instrumentation to each new extension handler.\n * Patches each individual extension in order to create the\n * span and propagate context. It does not create spans when there is no parent span.\n * @param {PatchableExtMethod | PatchableExtMethod[]} method - the request extension\n * handler which is being instrumented\n * @param {Hapi.ServerRequestExtType} extPoint - the point in the Hapi request lifecycle\n * which this extension targets\n * @param {string} [pluginName] - if present, represents the name of the plugin responsible\n * for adding this server route. Else, signifies that the route was added directly\n */\n private _wrapExtMethods<T extends PatchableExtMethod | PatchableExtMethod[]>(\n method: T,\n extPoint: Hapi.ServerRequestExtType,\n pluginName?: string,\n ): T {\n const instrumentation: HapiInstrumentation = this;\n if (method instanceof Array) {\n for (let i = 0; i < method.length; i++) {\n method[i] = instrumentation._wrapExtMethods(method[i]!, extPoint) as PatchableExtMethod;\n }\n return method;\n } else if (isPatchableExtMethod(method)) {\n if (method[handlerPatched] === true) return method;\n method[handlerPatched] = true;\n\n const newHandler: PatchableExtMethod = async function (this: any, ...params: Parameters<Hapi.Lifecycle.Method>) {\n if (api.trace.getSpan(api.context.active()) === undefined) {\n return await method.apply(this, params);\n }\n const metadata = getExtMetadata(extPoint, pluginName, method.name);\n const span = instrumentation.tracer.startSpan(metadata.name, {\n attributes: metadata.attributes,\n });\n try {\n return await api.context.with<Parameters<Hapi.Lifecycle.Method>, Hapi.Lifecycle.Method>(\n api.trace.setSpan(api.context.active(), span),\n method,\n undefined,\n ...params,\n );\n } catch (err: any) {\n span.recordException(err);\n span.setStatus({\n code: api.SpanStatusCode.ERROR,\n message: err.message,\n });\n throw err;\n } finally {\n span.end();\n }\n };\n return newHandler as T;\n }\n return method;\n }\n\n /**\n * Patches each individual route handler method in order to create the\n * span and propagate context. It does not create spans when there is no parent span.\n * @param {PatchableServerRoute} route - the route handler which is being instrumented\n * @param {string} [pluginName] - if present, represents the name of the plugin responsible\n * for adding this server route. Else, signifies that the route was added directly\n */\n private _wrapRouteHandler(route: PatchableServerRoute, pluginName?: string): PatchableServerRoute {\n const instrumentation: HapiInstrumentation = this;\n if (route[handlerPatched] === true) return route;\n route[handlerPatched] = true;\n\n const wrapHandler: (oldHandler: Hapi.Lifecycle.Method) => Hapi.Lifecycle.Method = oldHandler => {\n return async function (this: any, ...params: Parameters<Hapi.Lifecycle.Method>) {\n if (api.trace.getSpan(api.context.active()) === undefined) {\n return await oldHandler.call(this, ...params);\n }\n setHttpServerSpanRouteAttribute(route.path);\n const metadata = getRouteMetadata(route, instrumentation._semconvStability, pluginName);\n const span = instrumentation.tracer.startSpan(metadata.name, {\n attributes: metadata.attributes,\n });\n try {\n return await api.context.with(api.trace.setSpan(api.context.active(), span), () =>\n oldHandler.call(this, ...params),\n );\n } catch (err: any) {\n span.recordException(err);\n span.setStatus({\n code: api.SpanStatusCode.ERROR,\n message: err.message,\n });\n throw err;\n } finally {\n span.end();\n }\n };\n };\n\n if (typeof route.handler === 'function') {\n route.handler = wrapHandler(route.handler as Hapi.Lifecycle.Method);\n } else if (typeof route.options === 'function') {\n const oldOptions = route.options;\n route.options = function (server) {\n const options = oldOptions(server);\n if (typeof options.handler === 'function') {\n options.handler = wrapHandler(options.handler as Hapi.Lifecycle.Method);\n }\n return options;\n };\n } else if (typeof route.options?.handler === 'function') {\n route.options.handler = wrapHandler(route.options.handler as Hapi.Lifecycle.Method);\n }\n return route;\n }\n}\n"],"names":["InstrumentationBase","SDK_VERSION","semconvStabilityFromStr","InstrumentationNodeModuleDefinition","HapiComponentName","isWrapped","getPluginFromInput","isLifecycleExtType","isDirectExtInput","isLifecycleExtEventObj","getPluginName","isPatchableExtMethod","handlerPatched","getExtMetadata","setHttpServerSpanRouteAttribute","getRouteMetadata"],"mappings":";;;;;;;;;AA0DA,MAAM,YAAA,GAAe,8BAAA;AAGd,MAAM,4BAA4BA,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AS,GAAA,EAAU;AACjB,UAAA,IAAA,CAAK,gBAAgB,GAAG,CAAA;AACxB,UAAA,IAAA,CAAK,SAAA,CAAU;AAAA,YACb,IAAA,EAAM,IAAI,cAAA,CAAe,KAAA;AAAA,YACzB,SAAS,GAAA,CAAI;AAAA,WACd,CAAA;AACD,UAAA,MAAM,GAAA;AAAA,QACR,CAAA,SAAE;AACA,UAAA,IAAA,CAAK,GAAA,EAAI;AAAA,QACX;AAAA,MACF,CAAA;AAAA,IACF,CAAA;AAEA,IAAA,IAAI,OAAO,KAAA,CAAM,OAAA,KAAY,UAAA,EAAY;AACvC,MAAA,KAAA,CAAM,OAAA,GAAU,WAAA,CAAY,KAAA,CAAM,OAAgC,CAAA;AAAA,IACpE,CAAA,MAAA,IAAW,OAAO,KAAA,CAAM,OAAA,KAAY,UAAA,EAAY;AAC9C,MAAA,MAAM,aAAa,KAAA,CAAM,OAAA;AACzB,MAAA,KAAA,CAAM,OAAA,GAAU,SAAU,MAAA,EAAQ;AAChC,QAAA,MAAM,OAAA,GAAU,WAAW,MAAM,CAAA;AACjC,QAAA,IAAI,OAAO,OAAA,CAAQ,OAAA,KAAY,UAAA,EAAY;AACzC,UAAA,OAAA,CAAQ,OAAA,GAAU,WAAA,CAAY,OAAA,CAAQ,OAAgC,CAAA;AAAA,QACxE;AACA,QAAA,OAAO,OAAA;AAAA,MACT,CAAA;AAAA,IACF,CAAA,MAAA,IAAW,OAAO,KAAA,CAAM,OAAA,EAAS,YAAY,UAAA,EAAY;AACvD,MAAA,KAAA,CAAM,OAAA,CAAQ,OAAA,GAAU,WAAA,CAAY,KAAA,CAAM,QAAQ,OAAgC,CAAA;AAAA,IACpF;AACA,IAAA,OAAO,KAAA;AAAA,EACT;AACF;;;;"}
|
|
@@ -4,6 +4,7 @@ const api = require('@opentelemetry/api');
|
|
|
4
4
|
const core = require('@sentry/core');
|
|
5
5
|
const constants = require('./constants.js');
|
|
6
6
|
const instrumentation = require('@opentelemetry/instrumentation');
|
|
7
|
+
const InstrumentationNodeModuleFile = require('../../InstrumentationNodeModuleFile.js');
|
|
7
8
|
const utils = require('./utils.js');
|
|
8
9
|
const semanticConventions = require('@opentelemetry/semantic-conventions');
|
|
9
10
|
const semconv = require('./semconv.js');
|
|
@@ -34,7 +35,7 @@ class KnexInstrumentation extends instrumentation.InstrumentationBase {
|
|
|
34
35
|
return module;
|
|
35
36
|
}
|
|
36
37
|
getRunnerNodeModuleFileInstrumentation(basePath) {
|
|
37
|
-
return new
|
|
38
|
+
return new InstrumentationNodeModuleFile.InstrumentationNodeModuleFile(
|
|
38
39
|
`knex/${basePath}/runner.js`,
|
|
39
40
|
constants.SUPPORTED_VERSIONS,
|
|
40
41
|
(Runner, moduleVersion) => {
|
|
@@ -48,7 +49,7 @@ class KnexInstrumentation extends instrumentation.InstrumentationBase {
|
|
|
48
49
|
);
|
|
49
50
|
}
|
|
50
51
|
getClientNodeModuleFileInstrumentation(basePath) {
|
|
51
|
-
return new
|
|
52
|
+
return new InstrumentationNodeModuleFile.InstrumentationNodeModuleFile(
|
|
52
53
|
`knex/${basePath}/client.js`,
|
|
53
54
|
constants.SUPPORTED_VERSIONS,
|
|
54
55
|
(Client) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentation.js","sources":["../../../../../../src/integrations/tracing/knex/vendored/instrumentation.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * NOTICE from the Sentry authors:\n * - Vendored from: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/15ef7506553f631ea4181391e0c5725a56f0d082/packages/instrumentation-knex\n * - Upstream version: @opentelemetry/instrumentation-knex@0.62.0\n * - Minor TypeScript strictness adjustments for this repository's compiler settings\n */\n/* eslint-disable */\n\nimport * as api from '@opentelemetry/api';\nimport { SDK_VERSION } from '@sentry/core';\nimport * as constants from './constants';\nimport {\n InstrumentationBase,\n InstrumentationNodeModuleDefinition,\n InstrumentationNodeModuleFile,\n isWrapped,\n SemconvStability,\n semconvStabilityFromStr,\n} from '@opentelemetry/instrumentation';\nimport * as utils from './utils';\nimport { KnexInstrumentationConfig } from './types';\nimport {\n ATTR_DB_COLLECTION_NAME,\n ATTR_DB_NAMESPACE,\n ATTR_DB_OPERATION_NAME,\n ATTR_DB_QUERY_TEXT,\n ATTR_DB_SYSTEM_NAME,\n ATTR_SERVER_ADDRESS,\n ATTR_SERVER_PORT,\n} from '@opentelemetry/semantic-conventions';\nimport {\n ATTR_DB_NAME,\n ATTR_DB_OPERATION,\n ATTR_DB_SQL_TABLE,\n ATTR_DB_STATEMENT,\n ATTR_DB_SYSTEM,\n ATTR_DB_USER,\n ATTR_NET_PEER_NAME,\n ATTR_NET_PEER_PORT,\n ATTR_NET_TRANSPORT,\n} from './semconv';\n\nconst PACKAGE_NAME = '@sentry/instrumentation-knex';\n\nconst contextSymbol = Symbol('opentelemetry.instrumentation-knex.context');\nconst DEFAULT_CONFIG: KnexInstrumentationConfig = {\n maxQueryLength: 1022,\n requireParentSpan: false,\n};\n\nexport class KnexInstrumentation extends InstrumentationBase<KnexInstrumentationConfig> {\n private _semconvStability: SemconvStability;\n\n constructor(config: KnexInstrumentationConfig = {}) {\n super(PACKAGE_NAME, SDK_VERSION, { ...DEFAULT_CONFIG, ...config });\n\n this._semconvStability = semconvStabilityFromStr('database', process.env.OTEL_SEMCONV_STABILITY_OPT_IN);\n }\n\n override setConfig(config: KnexInstrumentationConfig = {}) {\n super.setConfig({ ...DEFAULT_CONFIG, ...config });\n }\n\n init() {\n const module = new InstrumentationNodeModuleDefinition(constants.MODULE_NAME, constants.SUPPORTED_VERSIONS);\n\n module.files.push(\n this.getClientNodeModuleFileInstrumentation('src'),\n this.getClientNodeModuleFileInstrumentation('lib'),\n this.getRunnerNodeModuleFileInstrumentation('src'),\n this.getRunnerNodeModuleFileInstrumentation('lib'),\n this.getRunnerNodeModuleFileInstrumentation('lib/execution'),\n );\n\n return module;\n }\n\n private getRunnerNodeModuleFileInstrumentation(basePath: string) {\n return new InstrumentationNodeModuleFile(\n `knex/${basePath}/runner.js`,\n constants.SUPPORTED_VERSIONS,\n (Runner: any, moduleVersion?: string) => {\n this.ensureWrapped(Runner.prototype, 'query', this.createQueryWrapper(moduleVersion));\n return Runner;\n },\n (Runner: any, _moduleVersion?: string) => {\n this._unwrap(Runner.prototype, 'query');\n return Runner;\n },\n );\n }\n\n private getClientNodeModuleFileInstrumentation(basePath: string) {\n return new InstrumentationNodeModuleFile(\n `knex/${basePath}/client.js`,\n constants.SUPPORTED_VERSIONS,\n (Client: any) => {\n this.ensureWrapped(Client.prototype, 'queryBuilder', this.storeContext.bind(this));\n this.ensureWrapped(Client.prototype, 'schemaBuilder', this.storeContext.bind(this));\n this.ensureWrapped(Client.prototype, 'raw', this.storeContext.bind(this));\n return Client;\n },\n (Client: any) => {\n this._unwrap(Client.prototype, 'queryBuilder');\n this._unwrap(Client.prototype, 'schemaBuilder');\n this._unwrap(Client.prototype, 'raw');\n return Client;\n },\n );\n }\n\n private createQueryWrapper(moduleVersion?: string) {\n const instrumentation = this;\n\n return function wrapQuery(original: (...args: any[]) => any) {\n return function wrapped_logging_method(this: any, query: any) {\n const config = this.client.config;\n\n const table = utils.extractTableName(this.builder);\n const operation = query?.method;\n const connectionString = config?.connection?.connectionString;\n const name =\n config?.connection?.filename ||\n config?.connection?.database ||\n utils.extractDatabaseFromConnectionString(connectionString);\n const { maxQueryLength } = instrumentation.getConfig();\n\n const attributes: api.Attributes = {\n 'knex.version': moduleVersion,\n };\n const transport = config?.connection?.filename === ':memory:' ? 'inproc' : undefined;\n\n if (instrumentation._semconvStability & SemconvStability.OLD) {\n Object.assign(attributes, {\n [ATTR_DB_SYSTEM]: utils.mapSystem(this.client.driverName),\n [ATTR_DB_SQL_TABLE]: table,\n [ATTR_DB_OPERATION]: operation,\n [ATTR_DB_USER]: config?.connection?.user,\n [ATTR_DB_NAME]: name,\n [ATTR_NET_PEER_NAME]: config?.connection?.host ?? utils.extractHostFromConnectionString(connectionString),\n [ATTR_NET_PEER_PORT]: config?.connection?.port ?? utils.extractPortFromConnectionString(connectionString),\n [ATTR_NET_TRANSPORT]: transport,\n });\n }\n if (instrumentation._semconvStability & SemconvStability.STABLE) {\n Object.assign(attributes, {\n [ATTR_DB_SYSTEM_NAME]: utils.mapSystem(this.client.driverName),\n [ATTR_DB_COLLECTION_NAME]: table,\n [ATTR_DB_OPERATION_NAME]: operation,\n [ATTR_DB_NAMESPACE]: name,\n [ATTR_SERVER_ADDRESS]: config?.connection?.host ?? utils.extractHostFromConnectionString(connectionString),\n [ATTR_SERVER_PORT]: config?.connection?.port ?? utils.extractPortFromConnectionString(connectionString),\n });\n }\n if (maxQueryLength) {\n const queryText = utils.limitLength(query?.sql, maxQueryLength);\n if (instrumentation._semconvStability & SemconvStability.STABLE) {\n attributes[ATTR_DB_QUERY_TEXT] = queryText;\n }\n if (instrumentation._semconvStability & SemconvStability.OLD) {\n attributes[ATTR_DB_STATEMENT] = queryText;\n }\n }\n\n const parentContext = this.builder[contextSymbol] || api.context.active();\n const parentSpan = api.trace.getSpan(parentContext);\n const hasActiveParent = parentSpan && api.trace.isSpanContextValid(parentSpan.spanContext());\n if (instrumentation._config.requireParentSpan && !hasActiveParent) {\n return original.bind(this)(...arguments);\n }\n\n const span = instrumentation.tracer.startSpan(\n utils.getName(name, operation, table),\n {\n kind: api.SpanKind.CLIENT,\n attributes,\n },\n parentContext,\n );\n const spanContext = api.trace.setSpan(api.context.active(), span);\n\n return api.context\n .with(spanContext, original, this, ...arguments)\n .then((result: unknown) => {\n span.end();\n return result;\n })\n .catch((err: any) => {\n const formatter = utils.getFormatter(this);\n const fullQuery = formatter(query.sql, query.bindings || []);\n const message = err.message.replace(fullQuery + ' - ', '');\n const exc = utils.otelExceptionFromKnexError(err, message);\n span.recordException(exc);\n span.setStatus({ code: api.SpanStatusCode.ERROR, message });\n span.end();\n throw err;\n });\n };\n };\n }\n\n private storeContext(original: Function) {\n return function wrapped_logging_method(this: any) {\n const builder = original.apply(this, arguments);\n Object.defineProperty(builder, contextSymbol, {\n value: api.context.active(),\n });\n return builder;\n };\n }\n\n ensureWrapped(obj: any, methodName: string, wrapper: (original: any) => any) {\n if (isWrapped(obj[methodName])) {\n this._unwrap(obj, methodName);\n }\n this._wrap(obj, methodName, wrapper);\n }\n}\n"],"names":["InstrumentationBase","SDK_VERSION","semconvStabilityFromStr","InstrumentationNodeModuleDefinition","constants.MODULE_NAME","constants.SUPPORTED_VERSIONS","InstrumentationNodeModuleFile","instrumentation","utils.extractTableName","utils.extractDatabaseFromConnectionString","SemconvStability","ATTR_DB_SYSTEM","utils.mapSystem","ATTR_DB_SQL_TABLE","ATTR_DB_OPERATION","ATTR_DB_USER","ATTR_DB_NAME","ATTR_NET_PEER_NAME","utils.extractHostFromConnectionString","ATTR_NET_PEER_PORT","utils.extractPortFromConnectionString","ATTR_NET_TRANSPORT","ATTR_DB_SYSTEM_NAME","ATTR_DB_COLLECTION_NAME","ATTR_DB_OPERATION_NAME","ATTR_DB_NAMESPACE","ATTR_SERVER_ADDRESS","ATTR_SERVER_PORT","utils.limitLength","ATTR_DB_QUERY_TEXT","ATTR_DB_STATEMENT","utils.getName","utils.getFormatter","utils.otelExceptionFromKnexError","isWrapped"],"mappings":";;;;;;;;;;AAwDA,MAAM,YAAA,GAAe,8BAAA;AAErB,MAAM,aAAA,0BAAuB,4CAA4C,CAAA;AACzE,MAAM,cAAA,GAA4C;AAAA,EAChD,cAAA,EAAgB,IAAA;AAAA,EAChB,iBAAA,EAAmB;AACrB,CAAA;AAEO,MAAM,4BAA4BA,mCAAA,CAA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;AAC9C,MAAA,MAAA,CAAO,cAAA,CAAe,SAAS,aAAA,EAAe;AAAA,QAC5C,KAAA,EAAO,GAAA,CAAI,OAAA,CAAQ,MAAA;AAAO,OAC3B,CAAA;AACD,MAAA,OAAO,OAAA;AAAA,IACT,CAAA;AAAA,EACF;AAAA,EAEA,aAAA,CAAc,GAAA,EAAU,UAAA,EAAoB,OAAA,EAAiC;AAC3E,IAAA,IAAIC,yBAAA,CAAU,GAAA,CAAI,UAAU,CAAC,CAAA,EAAG;AAC9B,MAAA,IAAA,CAAK,OAAA,CAAQ,KAAK,UAAU,CAAA;AAAA,IAC9B;AACA,IAAA,IAAA,CAAK,KAAA,CAAM,GAAA,EAAK,UAAA,EAAY,OAAO,CAAA;AAAA,EACrC;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"instrumentation.js","sources":["../../../../../../src/integrations/tracing/knex/vendored/instrumentation.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * NOTICE from the Sentry authors:\n * - Vendored from: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/15ef7506553f631ea4181391e0c5725a56f0d082/packages/instrumentation-knex\n * - Upstream version: @opentelemetry/instrumentation-knex@0.62.0\n * - Minor TypeScript strictness adjustments for this repository's compiler settings\n */\n/* eslint-disable */\n\nimport * as api from '@opentelemetry/api';\nimport { SDK_VERSION } from '@sentry/core';\nimport * as constants from './constants';\nimport {\n InstrumentationBase,\n InstrumentationNodeModuleDefinition,\n isWrapped,\n SemconvStability,\n semconvStabilityFromStr,\n} from '@opentelemetry/instrumentation';\nimport { InstrumentationNodeModuleFile } from '../../InstrumentationNodeModuleFile';\nimport * as utils from './utils';\nimport { KnexInstrumentationConfig } from './types';\nimport {\n ATTR_DB_COLLECTION_NAME,\n ATTR_DB_NAMESPACE,\n ATTR_DB_OPERATION_NAME,\n ATTR_DB_QUERY_TEXT,\n ATTR_DB_SYSTEM_NAME,\n ATTR_SERVER_ADDRESS,\n ATTR_SERVER_PORT,\n} from '@opentelemetry/semantic-conventions';\nimport {\n ATTR_DB_NAME,\n ATTR_DB_OPERATION,\n ATTR_DB_SQL_TABLE,\n ATTR_DB_STATEMENT,\n ATTR_DB_SYSTEM,\n ATTR_DB_USER,\n ATTR_NET_PEER_NAME,\n ATTR_NET_PEER_PORT,\n ATTR_NET_TRANSPORT,\n} from './semconv';\n\nconst PACKAGE_NAME = '@sentry/instrumentation-knex';\n\nconst contextSymbol = Symbol('opentelemetry.instrumentation-knex.context');\nconst DEFAULT_CONFIG: KnexInstrumentationConfig = {\n maxQueryLength: 1022,\n requireParentSpan: false,\n};\n\nexport class KnexInstrumentation extends InstrumentationBase<KnexInstrumentationConfig> {\n private _semconvStability: SemconvStability;\n\n constructor(config: KnexInstrumentationConfig = {}) {\n super(PACKAGE_NAME, SDK_VERSION, { ...DEFAULT_CONFIG, ...config });\n\n this._semconvStability = semconvStabilityFromStr('database', process.env.OTEL_SEMCONV_STABILITY_OPT_IN);\n }\n\n override setConfig(config: KnexInstrumentationConfig = {}) {\n super.setConfig({ ...DEFAULT_CONFIG, ...config });\n }\n\n init() {\n const module = new InstrumentationNodeModuleDefinition(constants.MODULE_NAME, constants.SUPPORTED_VERSIONS);\n\n module.files.push(\n this.getClientNodeModuleFileInstrumentation('src'),\n this.getClientNodeModuleFileInstrumentation('lib'),\n this.getRunnerNodeModuleFileInstrumentation('src'),\n this.getRunnerNodeModuleFileInstrumentation('lib'),\n this.getRunnerNodeModuleFileInstrumentation('lib/execution'),\n );\n\n return module;\n }\n\n private getRunnerNodeModuleFileInstrumentation(basePath: string) {\n return new InstrumentationNodeModuleFile(\n `knex/${basePath}/runner.js`,\n constants.SUPPORTED_VERSIONS,\n (Runner: any, moduleVersion?: string) => {\n this.ensureWrapped(Runner.prototype, 'query', this.createQueryWrapper(moduleVersion));\n return Runner;\n },\n (Runner: any, _moduleVersion?: string) => {\n this._unwrap(Runner.prototype, 'query');\n return Runner;\n },\n );\n }\n\n private getClientNodeModuleFileInstrumentation(basePath: string) {\n return new InstrumentationNodeModuleFile(\n `knex/${basePath}/client.js`,\n constants.SUPPORTED_VERSIONS,\n (Client: any) => {\n this.ensureWrapped(Client.prototype, 'queryBuilder', this.storeContext.bind(this));\n this.ensureWrapped(Client.prototype, 'schemaBuilder', this.storeContext.bind(this));\n this.ensureWrapped(Client.prototype, 'raw', this.storeContext.bind(this));\n return Client;\n },\n (Client: any) => {\n this._unwrap(Client.prototype, 'queryBuilder');\n this._unwrap(Client.prototype, 'schemaBuilder');\n this._unwrap(Client.prototype, 'raw');\n return Client;\n },\n );\n }\n\n private createQueryWrapper(moduleVersion?: string) {\n const instrumentation = this;\n\n return function wrapQuery(original: (...args: any[]) => any) {\n return function wrapped_logging_method(this: any, query: any) {\n const config = this.client.config;\n\n const table = utils.extractTableName(this.builder);\n const operation = query?.method;\n const connectionString = config?.connection?.connectionString;\n const name =\n config?.connection?.filename ||\n config?.connection?.database ||\n utils.extractDatabaseFromConnectionString(connectionString);\n const { maxQueryLength } = instrumentation.getConfig();\n\n const attributes: api.Attributes = {\n 'knex.version': moduleVersion,\n };\n const transport = config?.connection?.filename === ':memory:' ? 'inproc' : undefined;\n\n if (instrumentation._semconvStability & SemconvStability.OLD) {\n Object.assign(attributes, {\n [ATTR_DB_SYSTEM]: utils.mapSystem(this.client.driverName),\n [ATTR_DB_SQL_TABLE]: table,\n [ATTR_DB_OPERATION]: operation,\n [ATTR_DB_USER]: config?.connection?.user,\n [ATTR_DB_NAME]: name,\n [ATTR_NET_PEER_NAME]: config?.connection?.host ?? utils.extractHostFromConnectionString(connectionString),\n [ATTR_NET_PEER_PORT]: config?.connection?.port ?? utils.extractPortFromConnectionString(connectionString),\n [ATTR_NET_TRANSPORT]: transport,\n });\n }\n if (instrumentation._semconvStability & SemconvStability.STABLE) {\n Object.assign(attributes, {\n [ATTR_DB_SYSTEM_NAME]: utils.mapSystem(this.client.driverName),\n [ATTR_DB_COLLECTION_NAME]: table,\n [ATTR_DB_OPERATION_NAME]: operation,\n [ATTR_DB_NAMESPACE]: name,\n [ATTR_SERVER_ADDRESS]: config?.connection?.host ?? utils.extractHostFromConnectionString(connectionString),\n [ATTR_SERVER_PORT]: config?.connection?.port ?? utils.extractPortFromConnectionString(connectionString),\n });\n }\n if (maxQueryLength) {\n const queryText = utils.limitLength(query?.sql, maxQueryLength);\n if (instrumentation._semconvStability & SemconvStability.STABLE) {\n attributes[ATTR_DB_QUERY_TEXT] = queryText;\n }\n if (instrumentation._semconvStability & SemconvStability.OLD) {\n attributes[ATTR_DB_STATEMENT] = queryText;\n }\n }\n\n const parentContext = this.builder[contextSymbol] || api.context.active();\n const parentSpan = api.trace.getSpan(parentContext);\n const hasActiveParent = parentSpan && api.trace.isSpanContextValid(parentSpan.spanContext());\n if (instrumentation._config.requireParentSpan && !hasActiveParent) {\n return original.bind(this)(...arguments);\n }\n\n const span = instrumentation.tracer.startSpan(\n utils.getName(name, operation, table),\n {\n kind: api.SpanKind.CLIENT,\n attributes,\n },\n parentContext,\n );\n const spanContext = api.trace.setSpan(api.context.active(), span);\n\n return api.context\n .with(spanContext, original, this, ...arguments)\n .then((result: unknown) => {\n span.end();\n return result;\n })\n .catch((err: any) => {\n const formatter = utils.getFormatter(this);\n const fullQuery = formatter(query.sql, query.bindings || []);\n const message = err.message.replace(fullQuery + ' - ', '');\n const exc = utils.otelExceptionFromKnexError(err, message);\n span.recordException(exc);\n span.setStatus({ code: api.SpanStatusCode.ERROR, message });\n span.end();\n throw err;\n });\n };\n };\n }\n\n private storeContext(original: Function) {\n return function wrapped_logging_method(this: any) {\n const builder = original.apply(this, arguments);\n Object.defineProperty(builder, contextSymbol, {\n value: api.context.active(),\n });\n return builder;\n };\n }\n\n ensureWrapped(obj: any, methodName: string, wrapper: (original: any) => any) {\n if (isWrapped(obj[methodName])) {\n this._unwrap(obj, methodName);\n }\n this._wrap(obj, methodName, wrapper);\n }\n}\n"],"names":["InstrumentationBase","SDK_VERSION","semconvStabilityFromStr","InstrumentationNodeModuleDefinition","constants.MODULE_NAME","constants.SUPPORTED_VERSIONS","InstrumentationNodeModuleFile","instrumentation","utils.extractTableName","utils.extractDatabaseFromConnectionString","SemconvStability","ATTR_DB_SYSTEM","utils.mapSystem","ATTR_DB_SQL_TABLE","ATTR_DB_OPERATION","ATTR_DB_USER","ATTR_DB_NAME","ATTR_NET_PEER_NAME","utils.extractHostFromConnectionString","ATTR_NET_PEER_PORT","utils.extractPortFromConnectionString","ATTR_NET_TRANSPORT","ATTR_DB_SYSTEM_NAME","ATTR_DB_COLLECTION_NAME","ATTR_DB_OPERATION_NAME","ATTR_DB_NAMESPACE","ATTR_SERVER_ADDRESS","ATTR_SERVER_PORT","utils.limitLength","ATTR_DB_QUERY_TEXT","ATTR_DB_STATEMENT","utils.getName","utils.getFormatter","utils.otelExceptionFromKnexError","isWrapped"],"mappings":";;;;;;;;;;;AAwDA,MAAM,YAAA,GAAe,8BAAA;AAErB,MAAM,aAAA,0BAAuB,4CAA4C,CAAA;AACzE,MAAM,cAAA,GAA4C;AAAA,EAChD,cAAA,EAAgB,IAAA;AAAA,EAChB,iBAAA,EAAmB;AACrB,CAAA;AAEO,MAAM,4BAA4BA,mCAAA,CAA+C;AAAA,EAGtF,WAAA,CAAY,MAAA,GAAoC,EAAC,EAAG;AAClD,IAAA,KAAA,CAAM,cAAcC,gBAAA,EAAa,EAAE,GAAG,cAAA,EAAgB,GAAG,QAAQ,CAAA;AAEjE,IAAA,IAAA,CAAK,iBAAA,GAAoBC,uCAAA,CAAwB,UAAA,EAAY,OAAA,CAAQ,IAAI,6BAA6B,CAAA;AAAA,EAC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IAAA,IAAIC,yBAAA,CAAU,GAAA,CAAI,UAAU,CAAC,CAAA,EAAG;AAC9B,MAAA,IAAA,CAAK,OAAA,CAAQ,KAAK,UAAU,CAAA;AAAA,IAC9B;AACA,IAAA,IAAA,CAAK,KAAA,CAAM,GAAA,EAAK,UAAA,EAAY,OAAO,CAAA;AAAA,EACrC;AACF;;;;"}
|
|
@@ -5,7 +5,7 @@ const instrumentation = require('@opentelemetry/instrumentation');
|
|
|
5
5
|
const types = require('./types.js');
|
|
6
6
|
const core = require('@sentry/core');
|
|
7
7
|
const utils = require('./utils.js');
|
|
8
|
-
const
|
|
8
|
+
const setHttpServerSpanRouteAttribute = require('../../../../utils/setHttpServerSpanRouteAttribute.js');
|
|
9
9
|
const internalTypes = require('./internal-types.js');
|
|
10
10
|
|
|
11
11
|
const PACKAGE_NAME = "@sentry/instrumentation-koa";
|
|
@@ -101,9 +101,8 @@ class KoaInstrumentation extends instrumentation.InstrumentationBase {
|
|
|
101
101
|
const span = this.tracer.startSpan(metadata.name, {
|
|
102
102
|
attributes: metadata.attributes
|
|
103
103
|
});
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
rpcMetadata.route = context._matchedRoute.toString();
|
|
104
|
+
if (context._matchedRoute) {
|
|
105
|
+
setHttpServerSpanRouteAttribute.setHttpServerSpanRouteAttribute(context._matchedRoute.toString());
|
|
107
106
|
}
|
|
108
107
|
const { requestHook } = this.getConfig();
|
|
109
108
|
if (requestHook) {
|