@sentry/server-utils 10.62.0 → 10.64.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/index.js +10 -2
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/integrations/tracing-channel/anthropic.js +101 -0
- package/build/cjs/integrations/tracing-channel/anthropic.js.map +1 -0
- package/build/cjs/integrations/tracing-channel/fastify/errors.js +42 -0
- package/build/cjs/integrations/tracing-channel/fastify/errors.js.map +1 -0
- package/build/cjs/integrations/tracing-channel/fastify/index.js +34 -0
- package/build/cjs/integrations/tracing-channel/fastify/index.js.map +1 -0
- package/build/cjs/integrations/tracing-channel/fastify/instrumentation.js +279 -0
- package/build/cjs/integrations/tracing-channel/fastify/instrumentation.js.map +1 -0
- package/build/cjs/integrations/tracing-channel/fastify/utils.js +11 -0
- package/build/cjs/integrations/tracing-channel/fastify/utils.js.map +1 -0
- package/build/cjs/integrations/tracing-channel/hapi-types.js +30 -0
- package/build/cjs/integrations/tracing-channel/hapi-types.js.map +1 -0
- package/build/cjs/integrations/tracing-channel/hapi-utils.js +177 -0
- package/build/cjs/integrations/tracing-channel/hapi-utils.js.map +1 -0
- package/build/cjs/integrations/tracing-channel/hapi.js +52 -0
- package/build/cjs/integrations/tracing-channel/hapi.js.map +1 -0
- package/build/cjs/integrations/tracing-channel/ioredis.js +96 -0
- package/build/cjs/integrations/tracing-channel/ioredis.js.map +1 -0
- package/build/cjs/integrations/tracing-channel/lru-memoizer.js +31 -0
- package/build/cjs/integrations/tracing-channel/lru-memoizer.js.map +1 -0
- package/build/cjs/integrations/tracing-channel/mysql.js +46 -83
- package/build/cjs/integrations/tracing-channel/mysql.js.map +1 -1
- package/build/cjs/integrations/tracing-channel/openai.js +83 -0
- package/build/cjs/integrations/tracing-channel/openai.js.map +1 -0
- package/build/cjs/integrations/tracing-channel/postgres.js +170 -0
- package/build/cjs/integrations/tracing-channel/postgres.js.map +1 -0
- package/build/cjs/integrations/tracing-channel/vercel-ai.js +25 -0
- package/build/cjs/integrations/tracing-channel/vercel-ai.js.map +1 -0
- package/build/cjs/mongoose/index.js +23 -0
- package/build/cjs/mongoose/index.js.map +1 -0
- package/build/cjs/mongoose/mongoose-dc-subscriber.js +97 -0
- package/build/cjs/mongoose/mongoose-dc-subscriber.js.map +1 -0
- package/build/cjs/orchestrion/bundler/vite.js +3 -3
- package/build/cjs/orchestrion/bundler/vite.js.map +1 -1
- package/build/cjs/orchestrion/channels.js +17 -1
- package/build/cjs/orchestrion/channels.js.map +1 -1
- package/build/cjs/orchestrion/config/anthropic-ai.js +43 -0
- package/build/cjs/orchestrion/config/anthropic-ai.js.map +1 -0
- package/build/cjs/orchestrion/config/hapi.js +26 -0
- package/build/cjs/orchestrion/config/hapi.js.map +1 -0
- package/build/cjs/orchestrion/config/index.js +35 -0
- package/build/cjs/orchestrion/config/index.js.map +1 -0
- package/build/cjs/orchestrion/config/ioredis.js +35 -0
- package/build/cjs/orchestrion/config/ioredis.js.map +1 -0
- package/build/cjs/orchestrion/config/lru-memoizer.js +17 -0
- package/build/cjs/orchestrion/config/lru-memoizer.js.map +1 -0
- package/build/cjs/orchestrion/config/mysql.js +16 -0
- package/build/cjs/orchestrion/config/mysql.js.map +1 -0
- package/build/cjs/orchestrion/config/openai.js +40 -0
- package/build/cjs/orchestrion/config/openai.js.map +1 -0
- package/build/cjs/orchestrion/config/pg.js +51 -0
- package/build/cjs/orchestrion/config/pg.js.map +1 -0
- package/build/cjs/orchestrion/config/vercel-ai.js +44 -0
- package/build/cjs/orchestrion/config/vercel-ai.js.map +1 -0
- package/build/cjs/orchestrion/detect.js +6 -1
- package/build/cjs/orchestrion/detect.js.map +1 -1
- package/build/cjs/orchestrion/index.js +27 -3
- package/build/cjs/orchestrion/index.js.map +1 -1
- package/build/cjs/orchestrion/runtime/register.js +10 -7
- package/build/cjs/orchestrion/runtime/register.js.map +1 -1
- package/build/cjs/redis/redis-statement-serializer.js +34 -0
- package/build/cjs/redis/redis-statement-serializer.js.map +1 -0
- package/build/cjs/tracing-channel.js +50 -11
- package/build/cjs/tracing-channel.js.map +1 -1
- package/build/cjs/vercel-ai/index.js +5 -3
- package/build/cjs/vercel-ai/index.js.map +1 -1
- package/build/cjs/vercel-ai/vercel-ai-dc-subscriber.js +11 -4
- package/build/cjs/vercel-ai/vercel-ai-dc-subscriber.js.map +1 -1
- package/build/cjs/vercel-ai/vercel-ai-orchestrion-v6-subscriber.js +256 -0
- package/build/cjs/vercel-ai/vercel-ai-orchestrion-v6-subscriber.js.map +1 -0
- package/build/esm/index.js +3 -0
- package/build/esm/index.js.map +1 -1
- package/build/esm/integrations/tracing-channel/anthropic.js +99 -0
- package/build/esm/integrations/tracing-channel/anthropic.js.map +1 -0
- package/build/esm/integrations/tracing-channel/fastify/errors.js +39 -0
- package/build/esm/integrations/tracing-channel/fastify/errors.js.map +1 -0
- package/build/esm/integrations/tracing-channel/fastify/index.js +30 -0
- package/build/esm/integrations/tracing-channel/fastify/index.js.map +1 -0
- package/build/esm/integrations/tracing-channel/fastify/instrumentation.js +277 -0
- package/build/esm/integrations/tracing-channel/fastify/instrumentation.js.map +1 -0
- package/build/esm/integrations/tracing-channel/fastify/utils.js +8 -0
- package/build/esm/integrations/tracing-channel/fastify/utils.js.map +1 -0
- package/build/esm/integrations/tracing-channel/hapi-types.js +25 -0
- package/build/esm/integrations/tracing-channel/hapi-types.js.map +1 -0
- package/build/esm/integrations/tracing-channel/hapi-utils.js +172 -0
- package/build/esm/integrations/tracing-channel/hapi-utils.js.map +1 -0
- package/build/esm/integrations/tracing-channel/hapi.js +50 -0
- package/build/esm/integrations/tracing-channel/hapi.js.map +1 -0
- package/build/esm/integrations/tracing-channel/ioredis.js +94 -0
- package/build/esm/integrations/tracing-channel/ioredis.js.map +1 -0
- package/build/esm/integrations/tracing-channel/lru-memoizer.js +29 -0
- package/build/esm/integrations/tracing-channel/lru-memoizer.js.map +1 -0
- package/build/esm/integrations/tracing-channel/mysql.js +47 -84
- package/build/esm/integrations/tracing-channel/mysql.js.map +1 -1
- package/build/esm/integrations/tracing-channel/openai.js +81 -0
- package/build/esm/integrations/tracing-channel/openai.js.map +1 -0
- package/build/esm/integrations/tracing-channel/postgres.js +168 -0
- package/build/esm/integrations/tracing-channel/postgres.js.map +1 -0
- package/build/esm/integrations/tracing-channel/vercel-ai.js +23 -0
- package/build/esm/integrations/tracing-channel/vercel-ai.js.map +1 -0
- package/build/esm/mongoose/index.js +21 -0
- package/build/esm/mongoose/index.js.map +1 -0
- package/build/esm/mongoose/mongoose-dc-subscriber.js +89 -0
- package/build/esm/mongoose/mongoose-dc-subscriber.js.map +1 -0
- package/build/esm/orchestrion/bundler/vite.js +1 -1
- package/build/esm/orchestrion/channels.js +17 -1
- package/build/esm/orchestrion/channels.js.map +1 -1
- package/build/esm/orchestrion/config/anthropic-ai.js +40 -0
- package/build/esm/orchestrion/config/anthropic-ai.js.map +1 -0
- package/build/esm/orchestrion/config/hapi.js +23 -0
- package/build/esm/orchestrion/config/hapi.js.map +1 -0
- package/build/esm/orchestrion/config/index.js +31 -0
- package/build/esm/orchestrion/config/index.js.map +1 -0
- package/build/esm/orchestrion/config/ioredis.js +32 -0
- package/build/esm/orchestrion/config/ioredis.js.map +1 -0
- package/build/esm/orchestrion/config/lru-memoizer.js +14 -0
- package/build/esm/orchestrion/config/lru-memoizer.js.map +1 -0
- package/build/esm/orchestrion/config/mysql.js +13 -0
- package/build/esm/orchestrion/config/mysql.js.map +1 -0
- package/build/esm/orchestrion/config/openai.js +37 -0
- package/build/esm/orchestrion/config/openai.js.map +1 -0
- package/build/esm/orchestrion/config/pg.js +48 -0
- package/build/esm/orchestrion/config/pg.js.map +1 -0
- package/build/esm/orchestrion/config/vercel-ai.js +41 -0
- package/build/esm/orchestrion/config/vercel-ai.js.map +1 -0
- package/build/esm/orchestrion/detect.js +6 -2
- package/build/esm/orchestrion/detect.js.map +1 -1
- package/build/esm/orchestrion/index.js +21 -2
- package/build/esm/orchestrion/index.js.map +1 -1
- package/build/esm/orchestrion/runtime/register.js +8 -4
- package/build/esm/orchestrion/runtime/register.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/esm/redis/redis-statement-serializer.js +32 -0
- package/build/esm/redis/redis-statement-serializer.js.map +1 -0
- package/build/esm/tracing-channel.js +51 -12
- package/build/esm/tracing-channel.js.map +1 -1
- package/build/esm/vercel-ai/index.js +6 -4
- package/build/esm/vercel-ai/index.js.map +1 -1
- package/build/esm/vercel-ai/vercel-ai-dc-subscriber.js +14 -8
- package/build/esm/vercel-ai/vercel-ai-dc-subscriber.js.map +1 -1
- package/build/esm/vercel-ai/vercel-ai-orchestrion-v6-subscriber.js +254 -0
- package/build/esm/vercel-ai/vercel-ai-orchestrion-v6-subscriber.js.map +1 -0
- package/build/types/index.d.ts +3 -0
- package/build/types/index.d.ts.map +1 -1
- package/build/types/integrations/tracing-channel/anthropic.d.ts +10 -0
- package/build/types/integrations/tracing-channel/anthropic.d.ts.map +1 -0
- package/build/types/integrations/tracing-channel/fastify/errors.d.ts +12 -0
- package/build/types/integrations/tracing-channel/fastify/errors.d.ts.map +1 -0
- package/build/types/integrations/tracing-channel/fastify/index.d.ts +66 -0
- package/build/types/integrations/tracing-channel/fastify/index.d.ts.map +1 -0
- package/build/types/integrations/tracing-channel/fastify/instrumentation.d.ts +10 -0
- package/build/types/integrations/tracing-channel/fastify/instrumentation.d.ts.map +1 -0
- package/build/types/integrations/tracing-channel/fastify/types.d.ts +32 -0
- package/build/types/integrations/tracing-channel/fastify/types.d.ts.map +1 -0
- package/build/types/integrations/tracing-channel/fastify/utils.d.ts +9 -0
- package/build/types/integrations/tracing-channel/fastify/utils.d.ts.map +1 -0
- package/build/types/integrations/tracing-channel/hapi-types.d.ts +53 -0
- package/build/types/integrations/tracing-channel/hapi-types.d.ts.map +1 -0
- package/build/types/integrations/tracing-channel/hapi-utils.d.ts +25 -0
- package/build/types/integrations/tracing-channel/hapi-utils.d.ts.map +1 -0
- package/build/types/integrations/tracing-channel/hapi.d.ts +9 -0
- package/build/types/integrations/tracing-channel/hapi.d.ts.map +1 -0
- package/build/types/integrations/tracing-channel/ioredis.d.ts +17 -0
- package/build/types/integrations/tracing-channel/ioredis.d.ts.map +1 -0
- package/build/types/integrations/tracing-channel/lru-memoizer.d.ts +10 -0
- package/build/types/integrations/tracing-channel/lru-memoizer.d.ts.map +1 -0
- package/build/types/integrations/tracing-channel/mysql.d.ts +3 -1
- package/build/types/integrations/tracing-channel/mysql.d.ts.map +1 -1
- package/build/types/integrations/tracing-channel/openai.d.ts +10 -0
- package/build/types/integrations/tracing-channel/openai.d.ts.map +1 -0
- package/build/types/integrations/tracing-channel/postgres.d.ts +15 -0
- package/build/types/integrations/tracing-channel/postgres.d.ts.map +1 -0
- package/build/types/integrations/tracing-channel/vercel-ai.d.ts +13 -0
- package/build/types/integrations/tracing-channel/vercel-ai.d.ts.map +1 -0
- package/build/types/mongoose/index.d.ts +11 -0
- package/build/types/mongoose/index.d.ts.map +1 -0
- package/build/types/mongoose/mongoose-dc-subscriber.d.ts +63 -0
- package/build/types/mongoose/mongoose-dc-subscriber.d.ts.map +1 -0
- package/build/types/orchestrion/channels.d.ts +21 -0
- package/build/types/orchestrion/channels.d.ts.map +1 -1
- package/build/types/orchestrion/config/anthropic-ai.d.ts +31 -0
- package/build/types/orchestrion/config/anthropic-ai.d.ts.map +1 -0
- package/build/types/orchestrion/config/hapi.d.ts +17 -0
- package/build/types/orchestrion/config/hapi.d.ts.map +1 -0
- package/build/types/orchestrion/{config.d.ts → config/index.d.ts} +1 -12
- package/build/types/orchestrion/config/index.d.ts.map +1 -0
- package/build/types/orchestrion/config/ioredis.d.ts +7 -0
- package/build/types/orchestrion/config/ioredis.d.ts.map +1 -0
- package/build/types/orchestrion/config/lru-memoizer.d.ts +16 -0
- package/build/types/orchestrion/config/lru-memoizer.d.ts.map +1 -0
- package/build/types/orchestrion/config/mysql.d.ts +16 -0
- package/build/types/orchestrion/config/mysql.d.ts.map +1 -0
- package/build/types/orchestrion/config/openai.d.ts +20 -0
- package/build/types/orchestrion/config/openai.d.ts.map +1 -0
- package/build/types/orchestrion/config/pg.d.ts +33 -0
- package/build/types/orchestrion/config/pg.d.ts.map +1 -0
- package/build/types/orchestrion/config/vercel-ai.d.ts +11 -0
- package/build/types/orchestrion/config/vercel-ai.d.ts.map +1 -0
- package/build/types/orchestrion/detect.d.ts +10 -0
- package/build/types/orchestrion/detect.d.ts.map +1 -1
- package/build/types/orchestrion/index.d.ts +53 -2
- package/build/types/orchestrion/index.d.ts.map +1 -1
- package/build/types/orchestrion/runtime/register.d.ts.map +1 -1
- package/build/types/redis/redis-statement-serializer.d.ts +6 -0
- package/build/types/redis/redis-statement-serializer.d.ts.map +1 -0
- package/build/types/tracing-channel.d.ts +22 -0
- package/build/types/tracing-channel.d.ts.map +1 -1
- package/build/types/vercel-ai/index.d.ts +3 -1
- package/build/types/vercel-ai/index.d.ts.map +1 -1
- package/build/types/vercel-ai/vercel-ai-dc-subscriber.d.ts +10 -4
- package/build/types/vercel-ai/vercel-ai-dc-subscriber.d.ts.map +1 -1
- package/build/types/vercel-ai/vercel-ai-orchestrion-v6-subscriber.d.ts +12 -0
- package/build/types/vercel-ai/vercel-ai-orchestrion-v6-subscriber.d.ts.map +1 -0
- package/build/types-ts3.8/index.d.ts +4 -0
- package/build/types-ts3.8/integrations/tracing-channel/anthropic.d.ts +10 -0
- package/build/types-ts3.8/integrations/tracing-channel/fastify/errors.d.ts +12 -0
- package/build/types-ts3.8/integrations/tracing-channel/fastify/index.d.ts +66 -0
- package/build/types-ts3.8/integrations/tracing-channel/fastify/instrumentation.d.ts +10 -0
- package/build/types-ts3.8/integrations/tracing-channel/fastify/types.d.ts +32 -0
- package/build/types-ts3.8/integrations/tracing-channel/fastify/utils.d.ts +9 -0
- package/build/types-ts3.8/integrations/tracing-channel/hapi-types.d.ts +65 -0
- package/build/types-ts3.8/integrations/tracing-channel/hapi-utils.d.ts +25 -0
- package/build/types-ts3.8/integrations/tracing-channel/hapi.d.ts +9 -0
- package/build/types-ts3.8/integrations/tracing-channel/ioredis.d.ts +17 -0
- package/build/types-ts3.8/integrations/tracing-channel/lru-memoizer.d.ts +10 -0
- package/build/types-ts3.8/integrations/tracing-channel/mysql.d.ts +3 -1
- package/build/types-ts3.8/integrations/tracing-channel/openai.d.ts +10 -0
- package/build/types-ts3.8/integrations/tracing-channel/postgres.d.ts +15 -0
- package/build/types-ts3.8/integrations/tracing-channel/vercel-ai.d.ts +13 -0
- package/build/types-ts3.8/mongoose/index.d.ts +11 -0
- package/build/types-ts3.8/mongoose/mongoose-dc-subscriber.d.ts +63 -0
- package/build/types-ts3.8/node-diagnostics-channel.d.ts +19 -0
- package/build/types-ts3.8/orchestrion/channels.d.ts +21 -0
- package/build/types-ts3.8/orchestrion/config/anthropic-ai.d.ts +31 -0
- package/build/types-ts3.8/orchestrion/config/hapi.d.ts +17 -0
- package/build/types-ts3.8/orchestrion/{config.d.ts → config/index.d.ts} +1 -12
- package/build/types-ts3.8/orchestrion/config/ioredis.d.ts +7 -0
- package/build/types-ts3.8/orchestrion/config/lru-memoizer.d.ts +16 -0
- package/build/types-ts3.8/orchestrion/config/mysql.d.ts +16 -0
- package/build/types-ts3.8/orchestrion/config/openai.d.ts +20 -0
- package/build/types-ts3.8/orchestrion/config/pg.d.ts +33 -0
- package/build/types-ts3.8/orchestrion/config/vercel-ai.d.ts +11 -0
- package/build/types-ts3.8/orchestrion/detect.d.ts +10 -0
- package/build/types-ts3.8/orchestrion/index.d.ts +53 -2
- package/build/types-ts3.8/redis/redis-statement-serializer.d.ts +6 -0
- package/build/types-ts3.8/tracing-channel.d.ts +22 -0
- package/build/types-ts3.8/vercel-ai/index.d.ts +3 -1
- package/build/types-ts3.8/vercel-ai/vercel-ai-dc-subscriber.d.ts +10 -4
- package/build/types-ts3.8/vercel-ai/vercel-ai-orchestrion-v6-subscriber.d.ts +12 -0
- package/package.json +10 -10
- package/build/cjs/orchestrion/config.js +0 -38
- package/build/cjs/orchestrion/config.js.map +0 -1
- package/build/esm/orchestrion/config.js +0 -34
- package/build/esm/orchestrion/config.js.map +0 -1
- package/build/types/orchestrion/config.d.ts.map +0 -1
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import * as diagnosticsChannel from 'node:diagnostics_channel';
|
|
2
|
+
import { HTTP_ROUTE, URL_PATH, HTTP_REQUEST_METHOD, HTTP_RESPONSE_STATUS_CODE } from '@sentry/conventions/attributes';
|
|
3
|
+
import { debug, getIsolationScope, getActiveSpan, getRootSpan, spanToJSON, SEMANTIC_ATTRIBUTE_SENTRY_OP, startInactiveSpan, withActiveSpan, startSpan, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SPAN_STATUS_ERROR } from '@sentry/core';
|
|
4
|
+
import { DEBUG_BUILD } from '../../../debug-build.js';
|
|
5
|
+
|
|
6
|
+
const PACKAGE_NAME = "@sentry/instrumentation-fastify";
|
|
7
|
+
const SUPPORTED_VERSIONS = ">=3.21.0 <6";
|
|
8
|
+
const ORIGIN = "auto.http.otel.fastify";
|
|
9
|
+
const HOOK_OP = "hook.fastify";
|
|
10
|
+
const REQUEST_HANDLER_OP = "request_handler.fastify";
|
|
11
|
+
const FASTIFY_HOOKS = [
|
|
12
|
+
"onRequest",
|
|
13
|
+
"preParsing",
|
|
14
|
+
"preValidation",
|
|
15
|
+
"preHandler",
|
|
16
|
+
"preSerialization",
|
|
17
|
+
"onSend",
|
|
18
|
+
"onResponse",
|
|
19
|
+
"onError"
|
|
20
|
+
];
|
|
21
|
+
const ATTRIBUTE_HOOK_NAME = "hook.name";
|
|
22
|
+
const ATTRIBUTE_FASTIFY_TYPE = "fastify.type";
|
|
23
|
+
const ATTRIBUTE_HOOK_CALLBACK_NAME = "hook.callback.name";
|
|
24
|
+
const ATTRIBUTE_FASTIFY_ROOT = "fastify.root";
|
|
25
|
+
const HOOK_TYPE_ROUTE = "route-hook";
|
|
26
|
+
const HOOK_TYPE_INSTANCE = "hook";
|
|
27
|
+
const HOOK_TYPE_HANDLER = "request-handler";
|
|
28
|
+
const ANONYMOUS_FUNCTION_NAME = "anonymous";
|
|
29
|
+
const kRequestSpan = /* @__PURE__ */ Symbol("sentry fastify request span");
|
|
30
|
+
const kAddHookOriginal = /* @__PURE__ */ Symbol("sentry fastify addHook original");
|
|
31
|
+
const kSetNotFoundOriginal = /* @__PURE__ */ Symbol("sentry fastify setNotFoundHandler original");
|
|
32
|
+
function getRequestRouteUrl(request) {
|
|
33
|
+
return request.routeOptions?.url ?? request.routerPath;
|
|
34
|
+
}
|
|
35
|
+
function getRequestRouteConfig(request) {
|
|
36
|
+
return request.routeOptions?.config ?? request.routeConfig;
|
|
37
|
+
}
|
|
38
|
+
function isFastifyRequest(arg) {
|
|
39
|
+
return !!arg && typeof arg === "object" && !!arg.method && !!arg.url && (!!arg.routeOptions || "routerPath" in arg);
|
|
40
|
+
}
|
|
41
|
+
function fastifyOtelPlugin(instance, _opts, done) {
|
|
42
|
+
instance.decorate(kAddHookOriginal, instance.addHook);
|
|
43
|
+
instance.decorate(kSetNotFoundOriginal, instance.setNotFoundHandler);
|
|
44
|
+
instance.decorateRequest("opentelemetry", function opentelemetry() {
|
|
45
|
+
return { span: this[kRequestSpan] };
|
|
46
|
+
});
|
|
47
|
+
instance.decorateRequest(kRequestSpan, null);
|
|
48
|
+
instance.addHook("onRoute", otelWireRoute);
|
|
49
|
+
instance.addHook("onRequest", startRequestSpanHook);
|
|
50
|
+
instance.addHook("onResponse", finalizeNotFoundSpanHook);
|
|
51
|
+
instance.addHook = addHookPatched;
|
|
52
|
+
instance.setNotFoundHandler = setNotFoundHandlerPatched;
|
|
53
|
+
done();
|
|
54
|
+
}
|
|
55
|
+
const pluginSymbols = fastifyOtelPlugin;
|
|
56
|
+
pluginSymbols[/* @__PURE__ */ Symbol.for("skip-override")] = true;
|
|
57
|
+
pluginSymbols[/* @__PURE__ */ Symbol.for("fastify.display-name")] = PACKAGE_NAME;
|
|
58
|
+
pluginSymbols[/* @__PURE__ */ Symbol.for("plugin-meta")] = {
|
|
59
|
+
fastify: SUPPORTED_VERSIONS,
|
|
60
|
+
name: PACKAGE_NAME
|
|
61
|
+
};
|
|
62
|
+
function otelWireRoute(routeOptions) {
|
|
63
|
+
if (routeOptions.config?.otel === false) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
for (const hook of FASTIFY_HOOKS) {
|
|
67
|
+
const handlerLike = routeOptions[hook];
|
|
68
|
+
if (typeof handlerLike === "function") {
|
|
69
|
+
routeOptions[hook] = handlerWrapper(
|
|
70
|
+
handlerLike,
|
|
71
|
+
hook,
|
|
72
|
+
routeHookAttributes(this.pluginName, hook, handlerLike, routeOptions.url)
|
|
73
|
+
);
|
|
74
|
+
} else if (Array.isArray(handlerLike)) {
|
|
75
|
+
routeOptions[hook] = handlerLike.map(
|
|
76
|
+
(handler) => handlerWrapper(handler, hook, routeHookAttributes(this.pluginName, hook, handler, routeOptions.url))
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
routeOptions.onSend = appendRouteHook(routeOptions.onSend, finalizeResponseSpanHook);
|
|
81
|
+
routeOptions.onError = appendRouteHook(routeOptions.onError, recordErrorInSpanHook);
|
|
82
|
+
routeOptions.handler = handlerWrapper(routeOptions.handler, "handler", {
|
|
83
|
+
[ATTRIBUTE_HOOK_NAME]: `${this.pluginName} - route-handler`,
|
|
84
|
+
[ATTRIBUTE_FASTIFY_TYPE]: HOOK_TYPE_HANDLER,
|
|
85
|
+
[HTTP_ROUTE]: routeOptions.url,
|
|
86
|
+
[ATTRIBUTE_HOOK_CALLBACK_NAME]: routeOptions.handler.name.length > 0 ? routeOptions.handler.name : ANONYMOUS_FUNCTION_NAME
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
function routeHookAttributes(pluginName, hook, handler, url) {
|
|
90
|
+
return {
|
|
91
|
+
[ATTRIBUTE_HOOK_NAME]: `${pluginName} - route -> ${hook}`,
|
|
92
|
+
[ATTRIBUTE_FASTIFY_TYPE]: HOOK_TYPE_ROUTE,
|
|
93
|
+
[HTTP_ROUTE]: url,
|
|
94
|
+
[ATTRIBUTE_HOOK_CALLBACK_NAME]: handler.name?.length > 0 ? handler.name : ANONYMOUS_FUNCTION_NAME
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function appendRouteHook(existing, hook) {
|
|
98
|
+
if (existing == null) {
|
|
99
|
+
return hook;
|
|
100
|
+
}
|
|
101
|
+
return Array.isArray(existing) ? [...existing, hook] : [existing, hook];
|
|
102
|
+
}
|
|
103
|
+
function startRequestSpanHook(request, _reply, hookDone) {
|
|
104
|
+
if (getRequestRouteConfig(request)?.otel === false) {
|
|
105
|
+
return hookDone();
|
|
106
|
+
}
|
|
107
|
+
const attributes = {
|
|
108
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,
|
|
109
|
+
[ATTRIBUTE_FASTIFY_ROOT]: PACKAGE_NAME,
|
|
110
|
+
[HTTP_REQUEST_METHOD]: request.method,
|
|
111
|
+
[URL_PATH]: request.url
|
|
112
|
+
};
|
|
113
|
+
const route = getRequestRouteUrl(request);
|
|
114
|
+
if (route != null) {
|
|
115
|
+
attributes[HTTP_ROUTE] = route;
|
|
116
|
+
const activeSpan = getActiveSpan();
|
|
117
|
+
const rootSpan = activeSpan && getRootSpan(activeSpan);
|
|
118
|
+
if (rootSpan && spanToJSON(rootSpan).data[SEMANTIC_ATTRIBUTE_SENTRY_OP] === "http.server") {
|
|
119
|
+
rootSpan.setAttribute(HTTP_ROUTE, route);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const requestSpan = startInactiveSpan({ name: "request", op: REQUEST_HANDLER_OP, attributes });
|
|
123
|
+
request[kRequestSpan] = requestSpan;
|
|
124
|
+
withActiveSpan(requestSpan, () => {
|
|
125
|
+
hookDone();
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
function finalizeNotFoundSpanHook(request, reply, hookDone) {
|
|
129
|
+
const span = request[kRequestSpan];
|
|
130
|
+
if (span != null) {
|
|
131
|
+
span.setAttributes({ [HTTP_RESPONSE_STATUS_CODE]: reply.statusCode });
|
|
132
|
+
span.end();
|
|
133
|
+
}
|
|
134
|
+
request[kRequestSpan] = null;
|
|
135
|
+
hookDone();
|
|
136
|
+
}
|
|
137
|
+
function finalizeResponseSpanHook(request, reply, payload, hookDone) {
|
|
138
|
+
const span = request[kRequestSpan];
|
|
139
|
+
if (span != null) {
|
|
140
|
+
if (reply.statusCode >= 500) {
|
|
141
|
+
span.setStatus({ code: SPAN_STATUS_ERROR });
|
|
142
|
+
}
|
|
143
|
+
span.setAttributes({ [HTTP_RESPONSE_STATUS_CODE]: reply.statusCode });
|
|
144
|
+
span.end();
|
|
145
|
+
}
|
|
146
|
+
request[kRequestSpan] = null;
|
|
147
|
+
hookDone(null, payload);
|
|
148
|
+
}
|
|
149
|
+
function recordErrorInSpanHook(request, _reply, error, hookDone) {
|
|
150
|
+
const span = request[kRequestSpan];
|
|
151
|
+
if (span != null) {
|
|
152
|
+
span.setStatus({ code: SPAN_STATUS_ERROR, message: error.message });
|
|
153
|
+
}
|
|
154
|
+
hookDone();
|
|
155
|
+
}
|
|
156
|
+
function addHookPatched(name, hook) {
|
|
157
|
+
const addHookOriginal = this[kAddHookOriginal];
|
|
158
|
+
if (FASTIFY_HOOKS.includes(name)) {
|
|
159
|
+
return addHookOriginal.call(
|
|
160
|
+
this,
|
|
161
|
+
name,
|
|
162
|
+
handlerWrapper(hook, name, {
|
|
163
|
+
[ATTRIBUTE_HOOK_NAME]: `${this.pluginName} - ${name}`,
|
|
164
|
+
[ATTRIBUTE_FASTIFY_TYPE]: HOOK_TYPE_INSTANCE,
|
|
165
|
+
[ATTRIBUTE_HOOK_CALLBACK_NAME]: hook.name?.length > 0 ? hook.name : ANONYMOUS_FUNCTION_NAME
|
|
166
|
+
})
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
return addHookOriginal.call(this, name, hook);
|
|
170
|
+
}
|
|
171
|
+
function setNotFoundHandlerPatched(hooks, handler) {
|
|
172
|
+
const setNotFoundHandlerOriginal = this[kSetNotFoundOriginal];
|
|
173
|
+
if (typeof hooks === "function") {
|
|
174
|
+
setNotFoundHandlerOriginal.call(
|
|
175
|
+
this,
|
|
176
|
+
handlerWrapper(hooks, "notFoundHandler", {
|
|
177
|
+
[ATTRIBUTE_HOOK_NAME]: `${this.pluginName} - not-found-handler`,
|
|
178
|
+
[ATTRIBUTE_FASTIFY_TYPE]: HOOK_TYPE_INSTANCE,
|
|
179
|
+
[ATTRIBUTE_HOOK_CALLBACK_NAME]: hooks.name?.length > 0 ? hooks.name : ANONYMOUS_FUNCTION_NAME
|
|
180
|
+
})
|
|
181
|
+
);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
if (hooks.preValidation != null) {
|
|
185
|
+
hooks.preValidation = handlerWrapper(hooks.preValidation, "notFoundHandler - preValidation", {
|
|
186
|
+
[ATTRIBUTE_HOOK_NAME]: `${this.pluginName} - not-found-handler - preValidation`,
|
|
187
|
+
[ATTRIBUTE_FASTIFY_TYPE]: HOOK_TYPE_INSTANCE,
|
|
188
|
+
[ATTRIBUTE_HOOK_CALLBACK_NAME]: hooks.preValidation.name?.length > 0 ? hooks.preValidation.name : ANONYMOUS_FUNCTION_NAME
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
if (hooks.preHandler != null) {
|
|
192
|
+
hooks.preHandler = handlerWrapper(hooks.preHandler, "notFoundHandler - preHandler", {
|
|
193
|
+
[ATTRIBUTE_HOOK_NAME]: `${this.pluginName} - not-found-handler - preHandler`,
|
|
194
|
+
[ATTRIBUTE_FASTIFY_TYPE]: HOOK_TYPE_INSTANCE,
|
|
195
|
+
[ATTRIBUTE_HOOK_CALLBACK_NAME]: hooks.preHandler.name?.length > 0 ? hooks.preHandler.name : ANONYMOUS_FUNCTION_NAME
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
if (handler == null) {
|
|
199
|
+
setNotFoundHandlerOriginal.call(this, hooks);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
setNotFoundHandlerOriginal.call(
|
|
203
|
+
this,
|
|
204
|
+
hooks,
|
|
205
|
+
handlerWrapper(handler, "notFoundHandler", {
|
|
206
|
+
[ATTRIBUTE_HOOK_NAME]: `${this.pluginName} - not-found-handler`,
|
|
207
|
+
[ATTRIBUTE_FASTIFY_TYPE]: HOOK_TYPE_INSTANCE,
|
|
208
|
+
[ATTRIBUTE_HOOK_CALLBACK_NAME]: handler.name?.length > 0 ? handler.name : ANONYMOUS_FUNCTION_NAME
|
|
209
|
+
})
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
function getRequestFromArgs(args) {
|
|
213
|
+
for (const arg of args) {
|
|
214
|
+
if (isFastifyRequest(arg)) {
|
|
215
|
+
return arg;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
function handlerWrapper(handler, hookName, spanAttributes = {}) {
|
|
221
|
+
return function handlerWrapped(...args) {
|
|
222
|
+
const request = getRequestFromArgs(args);
|
|
223
|
+
if (request === null || getRequestRouteConfig(request)?.otel === false) {
|
|
224
|
+
return handler.call(this, ...args);
|
|
225
|
+
}
|
|
226
|
+
const parentSpan = request[kRequestSpan] ?? void 0;
|
|
227
|
+
const handlerName = handler.name?.length > 0 ? handler.name : this.pluginName ?? ANONYMOUS_FUNCTION_NAME;
|
|
228
|
+
const hookType = spanAttributes[ATTRIBUTE_FASTIFY_TYPE];
|
|
229
|
+
const op = hookType === HOOK_TYPE_INSTANCE ? HOOK_OP : hookType === HOOK_TYPE_HANDLER ? REQUEST_HANDLER_OP : void 0;
|
|
230
|
+
const name = op ? stripFastifyPrefix(spanAttributes[ATTRIBUTE_HOOK_NAME]) : `${hookName} - ${handlerName}`;
|
|
231
|
+
return startSpan(
|
|
232
|
+
{
|
|
233
|
+
name,
|
|
234
|
+
op,
|
|
235
|
+
attributes: {
|
|
236
|
+
...spanAttributes,
|
|
237
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN
|
|
238
|
+
},
|
|
239
|
+
parentSpan
|
|
240
|
+
},
|
|
241
|
+
() => handler.call(this, ...args)
|
|
242
|
+
);
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
function stripFastifyPrefix(hookName = "") {
|
|
246
|
+
return hookName.replace(/^fastify -> /, "").replace(/^@fastify\/otel -> /, "").replace(/^@sentry\/instrumentation-fastify -> /, "");
|
|
247
|
+
}
|
|
248
|
+
function instrumentOnRequest(fastify) {
|
|
249
|
+
fastify.addHook("onRequest", async (request, _reply) => {
|
|
250
|
+
const routeName = getRequestRouteUrl(request);
|
|
251
|
+
const method = request.method || "GET";
|
|
252
|
+
getIsolationScope().setTransactionName(`${method} ${routeName}`);
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
let _isInstrumented = false;
|
|
256
|
+
const instrumentFastify = Object.assign(
|
|
257
|
+
function instrumentFastify2() {
|
|
258
|
+
if (_isInstrumented) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
_isInstrumented = true;
|
|
262
|
+
diagnosticsChannel.subscribe("fastify.initialization", (message) => {
|
|
263
|
+
const fastifyInstance = message.fastify;
|
|
264
|
+
fastifyInstance?.register(fastifyOtelPlugin).after((err) => {
|
|
265
|
+
if (err) {
|
|
266
|
+
DEBUG_BUILD && debug.error("Failed to setup Fastify instrumentation", err);
|
|
267
|
+
} else if (fastifyInstance) {
|
|
268
|
+
instrumentOnRequest(fastifyInstance);
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
},
|
|
273
|
+
{ id: "Fastify.v5" }
|
|
274
|
+
);
|
|
275
|
+
|
|
276
|
+
export { instrumentFastify };
|
|
277
|
+
//# sourceMappingURL=instrumentation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instrumentation.js","sources":["../../../../../src/integrations/tracing-channel/fastify/instrumentation.ts"],"sourcesContent":["/*\n * Copyright (c) 2024-present The Fastify team <https://github.com/fastify/fastify#team>\n * SPDX-License-Identifier: MIT\n *\n * NOTICE from the Sentry authors:\n * - Based on: https://github.com/fastify/otel/tree/bae80d6caef4287e7f01ff3c8dc753243706ea86 (@fastify/otel@0.18.1)\n * - Streamlined to the Sentry SDK's needs: dropped the `InstrumentationBase` wrapper, the unused\n * request/lifecycle hooks, `ignorePaths`/`minimatch` support and the OpenTelemetry tracer/context\n * APIs in favor of the Sentry span API.\n */\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-this-alias */\n/* eslint-disable max-lines */\n\nimport * as diagnosticsChannel from 'node:diagnostics_channel';\nimport { HTTP_REQUEST_METHOD, HTTP_RESPONSE_STATUS_CODE, HTTP_ROUTE, URL_PATH } from '@sentry/conventions/attributes';\nimport type { Span } from '@sentry/core';\nimport {\n debug,\n getActiveSpan,\n getIsolationScope,\n getRootSpan,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SPAN_STATUS_ERROR,\n spanToJSON,\n startInactiveSpan,\n startSpan,\n withActiveSpan,\n} from '@sentry/core';\nimport type { FastifyInstance, FastifyRequest } from './types';\nimport { DEBUG_BUILD } from '../../../debug-build';\n\nconst PACKAGE_NAME = '@sentry/instrumentation-fastify';\nconst SUPPORTED_VERSIONS = '>=3.21.0 <6';\n\nconst ORIGIN = 'auto.http.otel.fastify';\nconst HOOK_OP = 'hook.fastify';\nconst REQUEST_HANDLER_OP = 'request_handler.fastify';\n\nconst FASTIFY_HOOKS = [\n 'onRequest',\n 'preParsing',\n 'preValidation',\n 'preHandler',\n 'preSerialization',\n 'onSend',\n 'onResponse',\n 'onError',\n];\nconst ATTRIBUTE_HOOK_NAME = 'hook.name' as const;\nconst ATTRIBUTE_FASTIFY_TYPE = 'fastify.type' as const;\nconst ATTRIBUTE_HOOK_CALLBACK_NAME = 'hook.callback.name' as const;\nconst ATTRIBUTE_FASTIFY_ROOT = 'fastify.root' as const;\n\nconst HOOK_TYPE_ROUTE = 'route-hook' as const;\nconst HOOK_TYPE_INSTANCE = 'hook' as const;\nconst HOOK_TYPE_HANDLER = 'request-handler' as const;\nconst ANONYMOUS_FUNCTION_NAME = 'anonymous';\n\nconst kRequestSpan = Symbol('sentry fastify request span');\nconst kAddHookOriginal = Symbol('sentry fastify addHook original');\nconst kSetNotFoundOriginal = Symbol('sentry fastify setNotFoundHandler original');\n\ntype AnyFn = (...args: any[]) => any;\n\n/**\n * Read the matched route URL off a request. Fastify >=4 exposes it on `request.routeOptions.url`,\n * while v3 only has the (since-removed-in-v5) `request.routerPath`.\n */\nfunction getRequestRouteUrl(request: any): string | undefined {\n return request.routeOptions?.url ?? request.routerPath;\n}\n\n/**\n * Read the per-route config off a request. Fastify >=4 exposes it on `request.routeOptions.config`,\n * while v3 uses `request.routeConfig`. Used to honor the `{ config: { otel: false } }` opt-out.\n */\nfunction getRequestRouteConfig(request: any): { otel?: boolean } | undefined {\n return request.routeOptions?.config ?? request.routeConfig;\n}\n\n/**\n * Detect whether one of a wrapped handler's arguments is the Fastify request. We can't rely on a\n * single property since the route metadata moved from `routerPath` (v3) to `routeOptions` (>=4),\n * so we accept either shape.\n */\nfunction isFastifyRequest(arg: any): boolean {\n return !!arg && typeof arg === 'object' && !!arg.method && !!arg.url && (!!arg.routeOptions || 'routerPath' in arg);\n}\n\n/**\n * The Fastify plugin that wires up the request/hook/handler spans. It is registered on every Fastify\n * instance via the `fastify.initialization` diagnostics channel.\n */\nfunction fastifyOtelPlugin(this: unknown, instance: any, _opts: unknown, done: () => void): void {\n instance.decorate(kAddHookOriginal, instance.addHook);\n instance.decorate(kSetNotFoundOriginal, instance.setNotFoundHandler);\n instance.decorateRequest('opentelemetry', function opentelemetry(this: any) {\n return { span: this[kRequestSpan] as Span | null };\n });\n instance.decorateRequest(kRequestSpan, null);\n\n instance.addHook('onRoute', otelWireRoute);\n instance.addHook('onRequest', startRequestSpanHook);\n instance.addHook('onResponse', finalizeNotFoundSpanHook);\n\n instance.addHook = addHookPatched;\n instance.setNotFoundHandler = setNotFoundHandlerPatched;\n\n done();\n}\n\nconst pluginSymbols = fastifyOtelPlugin as unknown as Record<symbol, unknown>;\npluginSymbols[Symbol.for('skip-override')] = true;\npluginSymbols[Symbol.for('fastify.display-name')] = PACKAGE_NAME;\npluginSymbols[Symbol.for('plugin-meta')] = {\n fastify: SUPPORTED_VERSIONS,\n name: PACKAGE_NAME,\n};\n\nfunction otelWireRoute(this: any, routeOptions: any): void {\n if (routeOptions.config?.otel === false) {\n return;\n }\n\n for (const hook of FASTIFY_HOOKS) {\n const handlerLike = routeOptions[hook];\n\n if (typeof handlerLike === 'function') {\n routeOptions[hook] = handlerWrapper(\n handlerLike,\n hook,\n routeHookAttributes(this.pluginName, hook, handlerLike, routeOptions.url),\n );\n } else if (Array.isArray(handlerLike)) {\n routeOptions[hook] = handlerLike.map((handler: AnyFn) =>\n handlerWrapper(handler, hook, routeHookAttributes(this.pluginName, hook, handler, routeOptions.url)),\n );\n }\n }\n\n routeOptions.onSend = appendRouteHook(routeOptions.onSend, finalizeResponseSpanHook);\n routeOptions.onError = appendRouteHook(routeOptions.onError, recordErrorInSpanHook);\n\n routeOptions.handler = handlerWrapper(routeOptions.handler, 'handler', {\n [ATTRIBUTE_HOOK_NAME]: `${this.pluginName} - route-handler`,\n [ATTRIBUTE_FASTIFY_TYPE]: HOOK_TYPE_HANDLER,\n [HTTP_ROUTE]: routeOptions.url,\n [ATTRIBUTE_HOOK_CALLBACK_NAME]:\n routeOptions.handler.name.length > 0 ? routeOptions.handler.name : ANONYMOUS_FUNCTION_NAME,\n });\n}\n\nfunction routeHookAttributes(pluginName: string, hook: string, handler: AnyFn, url: string): Record<string, string> {\n return {\n [ATTRIBUTE_HOOK_NAME]: `${pluginName} - route -> ${hook}`,\n [ATTRIBUTE_FASTIFY_TYPE]: HOOK_TYPE_ROUTE,\n [HTTP_ROUTE]: url,\n [ATTRIBUTE_HOOK_CALLBACK_NAME]: handler.name?.length > 0 ? handler.name : ANONYMOUS_FUNCTION_NAME,\n };\n}\n\nfunction appendRouteHook(existing: AnyFn | AnyFn[] | undefined, hook: AnyFn): AnyFn | AnyFn[] {\n if (existing == null) {\n return hook;\n }\n return Array.isArray(existing) ? [...existing, hook] : [existing, hook];\n}\n\nfunction startRequestSpanHook(this: any, request: any, _reply: any, hookDone: () => void): void {\n if (getRequestRouteConfig(request)?.otel === false) {\n return hookDone();\n }\n\n const attributes: Record<string, string> = {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,\n [ATTRIBUTE_FASTIFY_ROOT]: PACKAGE_NAME,\n [HTTP_REQUEST_METHOD]: request.method,\n [URL_PATH]: request.url,\n };\n\n const route = getRequestRouteUrl(request);\n if (route != null) {\n attributes[HTTP_ROUTE] = route;\n\n // Update the route of the request on the root span, if it is a http.server span\n const activeSpan = getActiveSpan();\n const rootSpan = activeSpan && getRootSpan(activeSpan);\n if (rootSpan && spanToJSON(rootSpan).data[SEMANTIC_ATTRIBUTE_SENTRY_OP] === 'http.server') {\n rootSpan.setAttribute(HTTP_ROUTE, route);\n }\n }\n\n const requestSpan = startInactiveSpan({ name: 'request', op: REQUEST_HANDLER_OP, attributes });\n request[kRequestSpan] = requestSpan;\n\n // Set the request span as the active span for the remainder of the request lifecycle, so that\n // downstream hooks/handlers as well as errors captured via the error diagnostics channel are\n // parented to it (otherwise they would attach to the root `http.server` span instead).\n withActiveSpan(requestSpan, () => {\n hookDone();\n });\n}\n\nfunction finalizeNotFoundSpanHook(request: any, reply: any, hookDone: () => void): void {\n const span = request[kRequestSpan] as Span | null;\n\n if (span != null) {\n span.setAttributes({ [HTTP_RESPONSE_STATUS_CODE]: reply.statusCode });\n span.end();\n }\n\n request[kRequestSpan] = null;\n\n hookDone();\n}\n\nfunction finalizeResponseSpanHook(\n request: any,\n reply: any,\n payload: any,\n hookDone: (err: null, payload: any) => void,\n): void {\n const span = request[kRequestSpan] as Span | null;\n\n if (span != null) {\n if (reply.statusCode >= 500) {\n span.setStatus({ code: SPAN_STATUS_ERROR });\n }\n span.setAttributes({ [HTTP_RESPONSE_STATUS_CODE]: reply.statusCode });\n span.end();\n }\n\n request[kRequestSpan] = null;\n\n hookDone(null, payload);\n}\n\nfunction recordErrorInSpanHook(request: any, _reply: any, error: any, hookDone: () => void): void {\n const span = request[kRequestSpan] as Span | null;\n\n if (span != null) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: error.message });\n }\n\n hookDone();\n}\n\nfunction addHookPatched(this: any, name: string, hook: AnyFn): unknown {\n const addHookOriginal = this[kAddHookOriginal];\n\n if (FASTIFY_HOOKS.includes(name)) {\n return addHookOriginal.call(\n this,\n name,\n handlerWrapper(hook, name, {\n [ATTRIBUTE_HOOK_NAME]: `${this.pluginName} - ${name}`,\n [ATTRIBUTE_FASTIFY_TYPE]: HOOK_TYPE_INSTANCE,\n [ATTRIBUTE_HOOK_CALLBACK_NAME]: hook.name?.length > 0 ? hook.name : ANONYMOUS_FUNCTION_NAME,\n }),\n );\n }\n\n return addHookOriginal.call(this, name, hook);\n}\n\nfunction setNotFoundHandlerPatched(this: any, hooks: any, handler?: any): void {\n const setNotFoundHandlerOriginal = this[kSetNotFoundOriginal];\n\n if (typeof hooks === 'function') {\n setNotFoundHandlerOriginal.call(\n this,\n handlerWrapper(hooks, 'notFoundHandler', {\n [ATTRIBUTE_HOOK_NAME]: `${this.pluginName} - not-found-handler`,\n [ATTRIBUTE_FASTIFY_TYPE]: HOOK_TYPE_INSTANCE,\n [ATTRIBUTE_HOOK_CALLBACK_NAME]: hooks.name?.length > 0 ? hooks.name : ANONYMOUS_FUNCTION_NAME,\n }),\n );\n return;\n }\n\n if (hooks.preValidation != null) {\n hooks.preValidation = handlerWrapper(hooks.preValidation, 'notFoundHandler - preValidation', {\n [ATTRIBUTE_HOOK_NAME]: `${this.pluginName} - not-found-handler - preValidation`,\n [ATTRIBUTE_FASTIFY_TYPE]: HOOK_TYPE_INSTANCE,\n [ATTRIBUTE_HOOK_CALLBACK_NAME]:\n hooks.preValidation.name?.length > 0 ? hooks.preValidation.name : ANONYMOUS_FUNCTION_NAME,\n });\n }\n\n if (hooks.preHandler != null) {\n hooks.preHandler = handlerWrapper(hooks.preHandler, 'notFoundHandler - preHandler', {\n [ATTRIBUTE_HOOK_NAME]: `${this.pluginName} - not-found-handler - preHandler`,\n [ATTRIBUTE_FASTIFY_TYPE]: HOOK_TYPE_INSTANCE,\n [ATTRIBUTE_HOOK_CALLBACK_NAME]:\n hooks.preHandler.name?.length > 0 ? hooks.preHandler.name : ANONYMOUS_FUNCTION_NAME,\n });\n }\n\n // Fastify allows `setNotFoundHandler(opts)` without a handler, falling back to its built-in 404\n // handler. Forward the (already-wrapped) hooks unchanged so that fallback still applies.\n if (handler == null) {\n setNotFoundHandlerOriginal.call(this, hooks);\n return;\n }\n\n setNotFoundHandlerOriginal.call(\n this,\n hooks,\n handlerWrapper(handler, 'notFoundHandler', {\n [ATTRIBUTE_HOOK_NAME]: `${this.pluginName} - not-found-handler`,\n [ATTRIBUTE_FASTIFY_TYPE]: HOOK_TYPE_INSTANCE,\n [ATTRIBUTE_HOOK_CALLBACK_NAME]: handler.name?.length > 0 ? handler.name : ANONYMOUS_FUNCTION_NAME,\n }),\n );\n}\n\nfunction getRequestFromArgs(args: any[]): any | null {\n for (const arg of args) {\n if (isFastifyRequest(arg)) {\n return arg;\n }\n }\n return null;\n}\n\nfunction handlerWrapper(handler: AnyFn, hookName: string, spanAttributes: Record<string, string> = {}): AnyFn {\n return function handlerWrapped(this: any, ...args: any[]) {\n const request = getRequestFromArgs(args);\n\n if (request === null || getRequestRouteConfig(request)?.otel === false) {\n return handler.call(this, ...args);\n }\n\n const parentSpan = (request[kRequestSpan] as Span | null) ?? undefined;\n const handlerName = handler.name?.length > 0 ? handler.name : (this.pluginName ?? ANONYMOUS_FUNCTION_NAME);\n\n const hookType = spanAttributes[ATTRIBUTE_FASTIFY_TYPE];\n const op =\n hookType === HOOK_TYPE_INSTANCE ? HOOK_OP : hookType === HOOK_TYPE_HANDLER ? REQUEST_HANDLER_OP : undefined;\n\n const name = op ? stripFastifyPrefix(spanAttributes[ATTRIBUTE_HOOK_NAME]) : `${hookName} - ${handlerName}`;\n\n return startSpan(\n {\n name,\n op,\n attributes: {\n ...spanAttributes,\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,\n },\n parentSpan,\n },\n () => handler.call(this, ...args),\n );\n };\n}\n\n/**\n * Strip the framework/plugin prefixes from a Fastify `hook.name` to derive a readable span name.\n * This is a bit of a hack and does not always work for all spans, but it's the best we can do without a proper API.\n */\nfunction stripFastifyPrefix(hookName = ''): string {\n return hookName\n .replace(/^fastify -> /, '')\n .replace(/^@fastify\\/otel -> /, '')\n .replace(/^@sentry\\/instrumentation-fastify -> /, '');\n}\n\nfunction instrumentOnRequest(fastify: FastifyInstance): void {\n fastify.addHook('onRequest', async (request: FastifyRequest, _reply) => {\n const routeName = getRequestRouteUrl(request);\n const method = request.method || 'GET';\n\n getIsolationScope().setTransactionName(`${method} ${routeName}`);\n });\n}\n\nlet _isInstrumented = false;\n\n/**\n * Set up the Fastify (>= 3.21.0 < 6) instrumentation by subscribing to the `fastify.initialization`\n * diagnostics channel and registering the span-creating plugin on every Fastify instance.\n *\n * Idempotent and exposes an `id` so it can participate in the OpenTelemetry preload list.\n */\nexport const instrumentFastify = Object.assign(\n function instrumentFastify(): void {\n if (_isInstrumented) {\n return;\n }\n _isInstrumented = true;\n\n diagnosticsChannel.subscribe('fastify.initialization', message => {\n const fastifyInstance = (message as { fastify?: FastifyInstance }).fastify;\n\n fastifyInstance?.register(fastifyOtelPlugin).after(err => {\n if (err) {\n DEBUG_BUILD && debug.error('Failed to setup Fastify instrumentation', err);\n } else if (fastifyInstance) {\n instrumentOnRequest(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AAA,CAAE,KAAA,CAAM,CAAA,GAAA,KAAO;AACxD,QAAA,IAAI,GAAA,EAAK;AACP,UAAA,WAAA,IAAe,KAAA,CAAM,KAAA,CAAM,yCAAA,EAA2C,GAAG,CAAA;AAAA,QAC3E,WAAW,eAAA,EAAiB;AAC1B,UAAA,mBAAA,CAAoB,eAAe,CAAA;AAAA,QACrC;AAAA,MACF,CAAC,CAAA;AAAA,IACH,CAAC,CAAA;AAAA,EACH,CAAA;AAAA,EACA,EAAE,IAAI,YAAA;AACR;;;;"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const INTEGRATION_NAME = "Fastify";
|
|
2
|
+
function defaultShouldHandleError(_error, _request, reply) {
|
|
3
|
+
const statusCode = reply.statusCode;
|
|
4
|
+
return statusCode >= 500 || statusCode <= 299;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export { INTEGRATION_NAME, defaultShouldHandleError };
|
|
8
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../../../src/integrations/tracing-channel/fastify/utils.ts"],"sourcesContent":["import type { FastifyReply, FastifyRequest } from './types';\n\nexport const INTEGRATION_NAME = 'Fastify';\n\n/**\n * Default function to determine if an error should be sent to Sentry\n *\n * 3xx and 4xx errors are not sent by default.\n */\nexport function defaultShouldHandleError(_error: Error, _request: FastifyRequest, reply: FastifyReply): boolean {\n const statusCode = reply.statusCode;\n // 3xx and 4xx errors are not sent by default.\n return statusCode >= 500 || statusCode <= 299;\n}\n"],"names":[],"mappings":"AAEO,MAAM,gBAAA,GAAmB;AAOzB,SAAS,wBAAA,CAAyB,MAAA,EAAe,QAAA,EAA0B,KAAA,EAA8B;AAC9G,EAAA,MAAM,aAAa,KAAA,CAAM,UAAA;AAEzB,EAAA,OAAO,UAAA,IAAc,OAAO,UAAA,IAAc,GAAA;AAC5C;;;;"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const LIFECYCLE_EXT_POINTS = [
|
|
2
|
+
"onPreAuth",
|
|
3
|
+
"onCredentials",
|
|
4
|
+
"onPostAuth",
|
|
5
|
+
"onPreHandler",
|
|
6
|
+
"onPostHandler",
|
|
7
|
+
"onPreResponse",
|
|
8
|
+
"onRequest"
|
|
9
|
+
];
|
|
10
|
+
const handlerPatched = /* @__PURE__ */ Symbol("hapi-handler-patched");
|
|
11
|
+
const HapiLayerType = {
|
|
12
|
+
ROUTER: "router",
|
|
13
|
+
PLUGIN: "plugin",
|
|
14
|
+
EXT: "server.ext"
|
|
15
|
+
};
|
|
16
|
+
const HapiLifecycleMethodNames = new Set(LIFECYCLE_EXT_POINTS);
|
|
17
|
+
var AttributeNames = /* @__PURE__ */ ((AttributeNames2) => {
|
|
18
|
+
AttributeNames2["HAPI_TYPE"] = "hapi.type";
|
|
19
|
+
AttributeNames2["PLUGIN_NAME"] = "hapi.plugin.name";
|
|
20
|
+
AttributeNames2["EXT_TYPE"] = "server.ext.type";
|
|
21
|
+
return AttributeNames2;
|
|
22
|
+
})(AttributeNames || {});
|
|
23
|
+
|
|
24
|
+
export { AttributeNames, HapiLayerType, HapiLifecycleMethodNames, handlerPatched };
|
|
25
|
+
//# sourceMappingURL=hapi-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hapi-types.js","sources":["../../../../src/integrations/tracing-channel/hapi-types.ts"],"sourcesContent":["/*\n * Structural type definitions and constants ported from the vendored\n * `@opentelemetry/instrumentation-hapi` types, with all `@hapi/*` and\n * `@opentelemetry/*` dependencies removed. Only the shapes actually accessed by\n * the orchestrion hapi subscriber are kept.\n */\n\n// Single source of truth for the request lifecycle extension points, so the\n// `ServerRequestExtType` union and the runtime `HapiLifecycleMethodNames` set\n// below can't drift apart.\nconst LIFECYCLE_EXT_POINTS = [\n 'onPreAuth',\n 'onCredentials',\n 'onPostAuth',\n 'onPreHandler',\n 'onPostHandler',\n 'onPreResponse',\n 'onRequest',\n] as const;\n\nexport type ServerRequestExtType = (typeof LIFECYCLE_EXT_POINTS)[number];\n\nexport type LifecycleMethod = (request: unknown, h: unknown, err?: Error) => unknown;\n\nexport interface ServerRouteOptions {\n handler?: LifecycleMethod | unknown;\n [key: string]: unknown;\n}\n\nexport interface ServerRoute {\n path: string;\n method: string;\n handler?: LifecycleMethod | unknown;\n options?: ((server: unknown) => ServerRouteOptions) | ServerRouteOptions;\n [key: string]: unknown;\n}\n\nexport interface ServerExtEventsObject {\n type: string;\n [key: string]: unknown;\n}\n\nexport interface ServerExtEventsRequestObject {\n type: ServerRequestExtType;\n method: LifecycleMethod;\n [key: string]: unknown;\n}\n\nexport interface ServerExtOptions {\n [key: string]: unknown;\n}\n\n/**\n * This symbol is used to mark a Hapi route handler or server extension handler as\n * already patched, since it's possible to use these handlers multiple times\n * i.e. when allowing multiple versions of one plugin, or when registering a plugin\n * multiple times on different servers.\n */\nexport const handlerPatched: unique symbol = Symbol('hapi-handler-patched');\n\nexport type PatchableServerRoute = ServerRoute & {\n [handlerPatched]?: boolean;\n};\n\nexport type PatchableExtMethod = LifecycleMethod & {\n [handlerPatched]?: boolean;\n};\n\nexport type ServerExtDirectInput = [ServerRequestExtType, LifecycleMethod, (ServerExtOptions | undefined)?];\n\nexport const HapiLayerType = {\n ROUTER: 'router',\n PLUGIN: 'plugin',\n EXT: 'server.ext',\n} as const;\n\nexport const HapiLifecycleMethodNames = new Set<string>(LIFECYCLE_EXT_POINTS);\n\nexport enum AttributeNames {\n HAPI_TYPE = 'hapi.type',\n PLUGIN_NAME = 'hapi.plugin.name',\n EXT_TYPE = 'server.ext.type',\n}\n"],"names":["AttributeNames"],"mappings":"AAUA,MAAM,oBAAA,GAAuB;AAAA,EAC3B,WAAA;AAAA,EACA,eAAA;AAAA,EACA,YAAA;AAAA,EACA,cAAA;AAAA,EACA,eAAA;AAAA,EACA,eAAA;AAAA,EACA;AACF,CAAA;AAwCO,MAAM,cAAA,0BAAuC,sBAAsB;AAYnE,MAAM,aAAA,GAAgB;AAAA,EAC3B,MAAA,EAAQ,QAAA;AAAA,EACR,MAAA,EAAQ,QAAA;AAAA,EACR,GAAA,EAAK;AACP;AAEO,MAAM,wBAAA,GAA2B,IAAI,GAAA,CAAY,oBAAoB;AAErE,IAAK,cAAA,qBAAAA,eAAAA,KAAL;AACL,EAAAA,gBAAA,WAAA,CAAA,GAAY,WAAA;AACZ,EAAAA,gBAAA,aAAA,CAAA,GAAc,kBAAA;AACd,EAAAA,gBAAA,UAAA,CAAA,GAAW,iBAAA;AAHD,EAAA,OAAAA,eAAAA;AAAA,CAAA,EAAA,cAAA,IAAA,EAAA;;;;"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { getActiveSpan, getRootSpan, spanToJSON, SEMANTIC_ATTRIBUTE_SENTRY_OP, startSpan, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/core';
|
|
2
|
+
import { HTTP_ROUTE, HTTP_METHOD } from '@sentry/conventions/attributes';
|
|
3
|
+
import { handlerPatched, HapiLifecycleMethodNames, HapiLayerType, AttributeNames } from './hapi-types.js';
|
|
4
|
+
|
|
5
|
+
function setHttpServerSpanRouteAttribute(route) {
|
|
6
|
+
const activeSpan = getActiveSpan();
|
|
7
|
+
if (!activeSpan) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const rootSpan = getRootSpan(activeSpan);
|
|
11
|
+
if (!rootSpan) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (spanToJSON(rootSpan).data[SEMANTIC_ATTRIBUTE_SENTRY_OP] !== "http.server") {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
rootSpan.setAttribute(HTTP_ROUTE, route);
|
|
18
|
+
}
|
|
19
|
+
const isLifecycleExtType = (variableToCheck) => {
|
|
20
|
+
return typeof variableToCheck === "string" && HapiLifecycleMethodNames.has(variableToCheck);
|
|
21
|
+
};
|
|
22
|
+
const isLifecycleExtEventObj = (variableToCheck) => {
|
|
23
|
+
const event = variableToCheck?.type;
|
|
24
|
+
return event !== void 0 && isLifecycleExtType(event);
|
|
25
|
+
};
|
|
26
|
+
const isDirectExtInput = (variableToCheck) => {
|
|
27
|
+
return Array.isArray(variableToCheck) && variableToCheck.length <= 3 && isLifecycleExtType(variableToCheck[0]) && typeof variableToCheck[1] === "function";
|
|
28
|
+
};
|
|
29
|
+
const isPatchableExtMethod = (variableToCheck) => {
|
|
30
|
+
return !Array.isArray(variableToCheck);
|
|
31
|
+
};
|
|
32
|
+
const getRouteMetadata = (route, pluginName) => {
|
|
33
|
+
const attributes = {
|
|
34
|
+
[HTTP_ROUTE]: route.path,
|
|
35
|
+
// eslint-disable-next-line typescript/no-deprecated -- TODO(v11): Replace deprecated attributes
|
|
36
|
+
[HTTP_METHOD]: route.method
|
|
37
|
+
};
|
|
38
|
+
let name;
|
|
39
|
+
if (pluginName) {
|
|
40
|
+
attributes[AttributeNames.HAPI_TYPE] = HapiLayerType.PLUGIN;
|
|
41
|
+
attributes[AttributeNames.PLUGIN_NAME] = pluginName;
|
|
42
|
+
name = `${pluginName}: route - ${route.path}`;
|
|
43
|
+
} else {
|
|
44
|
+
attributes[AttributeNames.HAPI_TYPE] = HapiLayerType.ROUTER;
|
|
45
|
+
name = `route - ${route.path}`;
|
|
46
|
+
}
|
|
47
|
+
return { attributes, name };
|
|
48
|
+
};
|
|
49
|
+
const getExtMetadata = (extPoint, pluginName, methodName) => {
|
|
50
|
+
let baseName = `ext - ${extPoint}`;
|
|
51
|
+
if (methodName && methodName !== "method") {
|
|
52
|
+
baseName = `ext - ${extPoint} - ${methodName}`;
|
|
53
|
+
}
|
|
54
|
+
if (pluginName) {
|
|
55
|
+
return {
|
|
56
|
+
attributes: {
|
|
57
|
+
[AttributeNames.EXT_TYPE]: extPoint,
|
|
58
|
+
[AttributeNames.HAPI_TYPE]: HapiLayerType.EXT,
|
|
59
|
+
[AttributeNames.PLUGIN_NAME]: pluginName
|
|
60
|
+
},
|
|
61
|
+
name: `${pluginName}: ${baseName}`
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
attributes: {
|
|
66
|
+
[AttributeNames.EXT_TYPE]: extPoint,
|
|
67
|
+
[AttributeNames.HAPI_TYPE]: HapiLayerType.EXT
|
|
68
|
+
},
|
|
69
|
+
name: baseName
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
function startMetadataSpan(metadata, original) {
|
|
73
|
+
return startSpan(
|
|
74
|
+
{
|
|
75
|
+
name: metadata.name,
|
|
76
|
+
op: `${metadata.attributes[AttributeNames.HAPI_TYPE]}.hapi`,
|
|
77
|
+
attributes: {
|
|
78
|
+
...metadata.attributes,
|
|
79
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.http.orchestrion.hapi"
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
original
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
function wrapRouteHandler(route, pluginName) {
|
|
86
|
+
if (route[handlerPatched] === true) return route;
|
|
87
|
+
route[handlerPatched] = true;
|
|
88
|
+
const wrapHandler = (oldHandler) => {
|
|
89
|
+
return function(...params) {
|
|
90
|
+
if (!getActiveSpan()) {
|
|
91
|
+
return oldHandler.call(this, ...params);
|
|
92
|
+
}
|
|
93
|
+
setHttpServerSpanRouteAttribute(route.path);
|
|
94
|
+
const metadata = getRouteMetadata(route, pluginName);
|
|
95
|
+
return startMetadataSpan(metadata, () => oldHandler.call(this, ...params));
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
if (typeof route.handler === "function") {
|
|
99
|
+
route.handler = wrapHandler(route.handler);
|
|
100
|
+
} else if (typeof route.options === "function") {
|
|
101
|
+
const oldOptions = route.options;
|
|
102
|
+
route.options = function(server) {
|
|
103
|
+
const options = oldOptions(server);
|
|
104
|
+
if (typeof options.handler === "function") {
|
|
105
|
+
options.handler = wrapHandler(options.handler);
|
|
106
|
+
}
|
|
107
|
+
return options;
|
|
108
|
+
};
|
|
109
|
+
} else if (typeof route.options?.handler === "function") {
|
|
110
|
+
route.options.handler = wrapHandler(route.options.handler);
|
|
111
|
+
}
|
|
112
|
+
return route;
|
|
113
|
+
}
|
|
114
|
+
function wrapExtMethods(method, extPoint, pluginName) {
|
|
115
|
+
if (Array.isArray(method)) {
|
|
116
|
+
for (let i = 0; i < method.length; i++) {
|
|
117
|
+
method[i] = wrapExtMethods(method[i], extPoint);
|
|
118
|
+
}
|
|
119
|
+
return method;
|
|
120
|
+
} else if (isPatchableExtMethod(method)) {
|
|
121
|
+
if (method[handlerPatched] === true) return method;
|
|
122
|
+
method[handlerPatched] = true;
|
|
123
|
+
const newHandler = function(...params) {
|
|
124
|
+
if (!getActiveSpan()) {
|
|
125
|
+
return method.apply(this, params);
|
|
126
|
+
}
|
|
127
|
+
const metadata = getExtMetadata(extPoint, pluginName, method.name);
|
|
128
|
+
return startMetadataSpan(metadata, () => method.apply(void 0, params));
|
|
129
|
+
};
|
|
130
|
+
newHandler[handlerPatched] = true;
|
|
131
|
+
return newHandler;
|
|
132
|
+
}
|
|
133
|
+
return method;
|
|
134
|
+
}
|
|
135
|
+
function wrapRouteArguments(args, pluginName) {
|
|
136
|
+
const route = args[0];
|
|
137
|
+
if (Array.isArray(route)) {
|
|
138
|
+
for (let i = 0; i < route.length; i++) {
|
|
139
|
+
route[i] = wrapRouteHandler(route[i], pluginName);
|
|
140
|
+
}
|
|
141
|
+
} else {
|
|
142
|
+
args[0] = wrapRouteHandler(route, pluginName);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
function wrapExtArguments(args, pluginName) {
|
|
146
|
+
if (Array.isArray(args[0])) {
|
|
147
|
+
const eventsList = args[0];
|
|
148
|
+
for (let i = 0; i < eventsList.length; i++) {
|
|
149
|
+
const eventObj = eventsList[i];
|
|
150
|
+
if (isLifecycleExtType(eventObj.type)) {
|
|
151
|
+
const lifecycleEventObj = eventObj;
|
|
152
|
+
const handler = wrapExtMethods(lifecycleEventObj.method, eventObj.type, pluginName);
|
|
153
|
+
lifecycleEventObj.method = handler;
|
|
154
|
+
eventsList[i] = lifecycleEventObj;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return;
|
|
158
|
+
} else if (isDirectExtInput(args)) {
|
|
159
|
+
const extInput = args;
|
|
160
|
+
const method = extInput[1];
|
|
161
|
+
const handler = wrapExtMethods(method, extInput[0], pluginName);
|
|
162
|
+
args[1] = handler;
|
|
163
|
+
return;
|
|
164
|
+
} else if (isLifecycleExtEventObj(args[0])) {
|
|
165
|
+
const lifecycleEventObj = args[0];
|
|
166
|
+
const handler = wrapExtMethods(lifecycleEventObj.method, lifecycleEventObj.type, pluginName);
|
|
167
|
+
lifecycleEventObj.method = handler;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export { getExtMetadata, getRouteMetadata, wrapExtArguments, wrapRouteArguments };
|
|
172
|
+
//# sourceMappingURL=hapi-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hapi-utils.js","sources":["../../../../src/integrations/tracing-channel/hapi-utils.ts"],"sourcesContent":["/*\n * OTel-free, `@hapi/*`-free port of the span-building helpers and handler/ext\n * wrap logic from the vendored `@opentelemetry/instrumentation-hapi`\n * (upstream @opentelemetry/instrumentation-hapi@0.64.0). Span output (names,\n * ops, origins, attributes) is kept byte-identical to that instrumentation;\n * span creation goes through the `@sentry/core` API and the OTel active-span\n * guard is replaced with `getActiveSpan()`.\n */\n\nimport {\n getActiveSpan,\n getRootSpan,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n spanToJSON,\n startSpan,\n} from '@sentry/core';\nimport type {\n LifecycleMethod,\n PatchableExtMethod,\n PatchableServerRoute,\n ServerExtDirectInput,\n ServerExtEventsObject,\n ServerExtEventsRequestObject,\n ServerRequestExtType,\n ServerRoute,\n ServerRouteOptions,\n} from './hapi-types';\n// eslint-disable-next-line typescript/no-deprecated -- TODO(v11): Replace deprecated attributes\nimport { HTTP_METHOD, HTTP_ROUTE } from '@sentry/conventions/attributes';\nimport { AttributeNames, handlerPatched, HapiLayerType, HapiLifecycleMethodNames } from './hapi-types';\n\ntype SpanAttributes = Record<string, string | undefined>;\n\ninterface SpanMetadata {\n attributes: SpanAttributes;\n name: string;\n}\n\n/**\n * Set the `http.route` attribute on the root HTTP server span for the current trace.\n *\n * No-op when there is no active span, no root span, or the root span is not an\n * `http.server` span — so framework instrumentations can call this unconditionally\n * without risking attribute pollution on non-HTTP root spans.\n */\nfunction setHttpServerSpanRouteAttribute(route: string): void {\n const activeSpan = getActiveSpan();\n if (!activeSpan) {\n return;\n }\n const rootSpan = getRootSpan(activeSpan);\n if (!rootSpan) {\n return;\n }\n if (spanToJSON(rootSpan).data[SEMANTIC_ATTRIBUTE_SENTRY_OP] !== 'http.server') {\n return;\n }\n rootSpan.setAttribute(HTTP_ROUTE, route);\n}\n\nconst isLifecycleExtType = (variableToCheck: unknown): variableToCheck is ServerRequestExtType => {\n return typeof variableToCheck === 'string' && HapiLifecycleMethodNames.has(variableToCheck);\n};\n\nconst isLifecycleExtEventObj = (variableToCheck: unknown): variableToCheck is ServerExtEventsRequestObject => {\n const event = (variableToCheck as ServerExtEventsRequestObject)?.type;\n return event !== undefined && isLifecycleExtType(event);\n};\n\nconst isDirectExtInput = (variableToCheck: unknown): variableToCheck is ServerExtDirectInput => {\n return (\n Array.isArray(variableToCheck) &&\n variableToCheck.length <= 3 &&\n isLifecycleExtType(variableToCheck[0]) &&\n typeof variableToCheck[1] === 'function'\n );\n};\n\nconst isPatchableExtMethod = (\n variableToCheck: PatchableExtMethod | PatchableExtMethod[],\n): variableToCheck is PatchableExtMethod => {\n return !Array.isArray(variableToCheck);\n};\n\n/** Build the span name and attributes for a Hapi route. */\nexport const getRouteMetadata = (route: ServerRoute, pluginName?: string): SpanMetadata => {\n const attributes: SpanAttributes = {\n [HTTP_ROUTE]: route.path,\n // eslint-disable-next-line typescript/no-deprecated -- TODO(v11): Replace deprecated attributes\n [HTTP_METHOD]: route.method,\n };\n\n let name;\n if (pluginName) {\n attributes[AttributeNames.HAPI_TYPE] = HapiLayerType.PLUGIN;\n attributes[AttributeNames.PLUGIN_NAME] = pluginName;\n name = `${pluginName}: route - ${route.path}`;\n } else {\n attributes[AttributeNames.HAPI_TYPE] = HapiLayerType.ROUTER;\n name = `route - ${route.path}`;\n }\n\n return { attributes, name };\n};\n\n/** Build the span name and attributes for a Hapi server extension. */\nexport const getExtMetadata = (\n extPoint: ServerRequestExtType,\n pluginName?: string,\n methodName?: string,\n): SpanMetadata => {\n let baseName = `ext - ${extPoint}`;\n if (methodName && methodName !== 'method') {\n // `method` is the default name for the extension in the ServerExtEventsObject format.\n baseName = `ext - ${extPoint} - ${methodName}`;\n }\n if (pluginName) {\n return {\n attributes: {\n [AttributeNames.EXT_TYPE]: extPoint,\n [AttributeNames.HAPI_TYPE]: HapiLayerType.EXT,\n [AttributeNames.PLUGIN_NAME]: pluginName,\n },\n name: `${pluginName}: ${baseName}`,\n };\n }\n return {\n attributes: {\n [AttributeNames.EXT_TYPE]: extPoint,\n [AttributeNames.HAPI_TYPE]: HapiLayerType.EXT,\n },\n name: baseName,\n };\n};\n\nfunction startMetadataSpan(metadata: SpanMetadata, original: () => unknown): unknown {\n return startSpan(\n {\n name: metadata.name,\n op: `${metadata.attributes[AttributeNames.HAPI_TYPE]}.hapi`,\n attributes: {\n ...metadata.attributes,\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.orchestrion.hapi',\n },\n },\n original,\n );\n}\n\n/**\n * Patches each individual route handler method in order to create the span. It\n * does not create spans when there is no parent span.\n */\nfunction wrapRouteHandler(route: PatchableServerRoute, pluginName?: string): PatchableServerRoute {\n if (route[handlerPatched] === true) return route;\n route[handlerPatched] = true;\n\n const wrapHandler: (oldHandler: LifecycleMethod) => LifecycleMethod = oldHandler => {\n return function (this: unknown, ...params: Parameters<LifecycleMethod>) {\n if (!getActiveSpan()) {\n return oldHandler.call(this, ...params);\n }\n setHttpServerSpanRouteAttribute(route.path);\n const metadata = getRouteMetadata(route, pluginName);\n return startMetadataSpan(metadata, () => oldHandler.call(this, ...params));\n };\n };\n\n if (typeof route.handler === 'function') {\n route.handler = wrapHandler(route.handler as LifecycleMethod);\n } else if (typeof route.options === 'function') {\n const oldOptions = route.options;\n route.options = function (server: unknown): ServerRouteOptions {\n const options = oldOptions(server);\n if (typeof options.handler === 'function') {\n options.handler = wrapHandler(options.handler as LifecycleMethod);\n }\n return options;\n };\n } else if (typeof route.options?.handler === 'function') {\n route.options.handler = wrapHandler(route.options.handler as LifecycleMethod);\n }\n return route;\n}\n\n/**\n * Wraps request extension methods to add instrumentation to each new extension\n * handler. It does not create spans when there is no parent span.\n */\nfunction wrapExtMethods<T extends PatchableExtMethod | PatchableExtMethod[]>(\n method: T,\n extPoint: ServerRequestExtType,\n pluginName?: string,\n): T {\n if (Array.isArray(method)) {\n for (let i = 0; i < method.length; i++) {\n method[i] = wrapExtMethods(method[i]!, extPoint);\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 = function (this: unknown, ...params: Parameters<LifecycleMethod>) {\n if (!getActiveSpan()) {\n return method.apply(this, params);\n }\n const metadata = getExtMetadata(extPoint, pluginName, method.name);\n return startMetadataSpan(metadata, () => method.apply(undefined, params));\n };\n // Mark the wrapper too (not just the original)\n newHandler[handlerPatched] = true;\n return newHandler as T;\n }\n return method;\n}\n\n/**\n * Wrap the route handler(s) in the live `server.route` arguments array, mutating\n * `args[0]` in place. `args[0]` is either a single route options object or an\n * array of them. Idempotent via the `handlerPatched` marker.\n */\nexport function wrapRouteArguments(args: unknown[], pluginName?: string): void {\n const route = args[0] as PatchableServerRoute | PatchableServerRoute[];\n if (Array.isArray(route)) {\n for (let i = 0; i < route.length; i++) {\n route[i] = wrapRouteHandler(route[i]!, pluginName);\n }\n } else {\n args[0] = wrapRouteHandler(route, pluginName);\n }\n}\n\n/**\n * Wrap the extension method(s) in the live `server.ext` arguments array,\n * mutating `args` in place. Handles the three accepted input shapes:\n * `(eventsArray)`, `(lifecycleEventObject)`, and `(extTypeString, method, options)`.\n * Idempotent via the `handlerPatched` marker.\n */\nexport function wrapExtArguments(args: unknown[], pluginName?: string): void {\n if (Array.isArray(args[0])) {\n const eventsList = args[0] as ServerExtEventsObject[] | ServerExtEventsRequestObject[];\n for (let i = 0; i < eventsList.length; i++) {\n const eventObj = eventsList[i]!;\n if (isLifecycleExtType(eventObj.type)) {\n const lifecycleEventObj = eventObj as ServerExtEventsRequestObject;\n const handler = wrapExtMethods(lifecycleEventObj.method, eventObj.type, pluginName);\n lifecycleEventObj.method = handler;\n eventsList[i] = lifecycleEventObj;\n }\n }\n return;\n } else if (isDirectExtInput(args)) {\n const extInput: ServerExtDirectInput = args;\n const method: PatchableExtMethod = extInput[1];\n const handler = wrapExtMethods(method, extInput[0], pluginName);\n args[1] = handler;\n return;\n } else if (isLifecycleExtEventObj(args[0])) {\n const lifecycleEventObj = args[0];\n const handler = wrapExtMethods(lifecycleEventObj.method, lifecycleEventObj.type, pluginName);\n lifecycleEventObj.method = handler;\n }\n}\n"],"names":[],"mappings":";;;;AA8CA,SAAS,gCAAgC,KAAA,EAAqB;AAC5D,EAAA,MAAM,aAAa,aAAA,EAAc;AACjC,EAAA,IAAI,CAAC,UAAA,EAAY;AACf,IAAA;AAAA,EACF;AACA,EAAA,MAAM,QAAA,GAAW,YAAY,UAAU,CAAA;AACvC,EAAA,IAAI,CAAC,QAAA,EAAU;AACb,IAAA;AAAA,EACF;AACA,EAAA,IAAI,WAAW,QAAQ,CAAA,CAAE,IAAA,CAAK,4BAA4B,MAAM,aAAA,EAAe;AAC7E,IAAA;AAAA,EACF;AACA,EAAA,QAAA,CAAS,YAAA,CAAa,YAAY,KAAK,CAAA;AACzC;AAEA,MAAM,kBAAA,GAAqB,CAAC,eAA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cAAA,CAAe,MAAA,EAAQ,QAAA,CAAS,CAAC,GAAG,UAAU,CAAA;AAC9D,IAAA,IAAA,CAAK,CAAC,CAAA,GAAI,OAAA;AACV,IAAA;AAAA,EACF,CAAA,MAAA,IAAW,sBAAA,CAAuB,IAAA,CAAK,CAAC,CAAC,CAAA,EAAG;AAC1C,IAAA,MAAM,iBAAA,GAAoB,KAAK,CAAC,CAAA;AAChC,IAAA,MAAM,UAAU,cAAA,CAAe,iBAAA,CAAkB,MAAA,EAAQ,iBAAA,CAAkB,MAAM,UAAU,CAAA;AAC3F,IAAA,iBAAA,CAAkB,MAAA,GAAS,OAAA;AAAA,EAC7B;AACF;;;;"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as diagnosticsChannel from 'node:diagnostics_channel';
|
|
2
|
+
import { defineIntegration, debug } from '@sentry/core';
|
|
3
|
+
import { DEBUG_BUILD } from '../../debug-build.js';
|
|
4
|
+
import { CHANNELS } from '../../orchestrion/channels.js';
|
|
5
|
+
import { wrapRouteArguments, wrapExtArguments } from './hapi-utils.js';
|
|
6
|
+
|
|
7
|
+
const INTEGRATION_NAME = "Hapi";
|
|
8
|
+
const _hapiChannelIntegration = (() => {
|
|
9
|
+
return {
|
|
10
|
+
name: INTEGRATION_NAME,
|
|
11
|
+
setupOnce() {
|
|
12
|
+
if (!diagnosticsChannel.tracingChannel) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
DEBUG_BUILD && debug.log(`[orchestrion:hapi] subscribing to channels "${CHANNELS.HAPI_ROUTE}" / "${CHANNELS.HAPI_EXT}"`);
|
|
16
|
+
diagnosticsChannel.tracingChannel(CHANNELS.HAPI_ROUTE).subscribe({
|
|
17
|
+
start(rawCtx) {
|
|
18
|
+
const ctx = rawCtx;
|
|
19
|
+
wrapRouteArguments(ctx.arguments, ctx.self?.realm?.plugin);
|
|
20
|
+
},
|
|
21
|
+
end() {
|
|
22
|
+
},
|
|
23
|
+
asyncStart() {
|
|
24
|
+
},
|
|
25
|
+
asyncEnd() {
|
|
26
|
+
},
|
|
27
|
+
error() {
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
diagnosticsChannel.tracingChannel(CHANNELS.HAPI_EXT).subscribe({
|
|
31
|
+
start(rawCtx) {
|
|
32
|
+
const ctx = rawCtx;
|
|
33
|
+
wrapExtArguments(ctx.arguments, ctx.self?.realm?.plugin);
|
|
34
|
+
},
|
|
35
|
+
end() {
|
|
36
|
+
},
|
|
37
|
+
asyncStart() {
|
|
38
|
+
},
|
|
39
|
+
asyncEnd() {
|
|
40
|
+
},
|
|
41
|
+
error() {
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
const hapiChannelIntegration = defineIntegration(_hapiChannelIntegration);
|
|
48
|
+
|
|
49
|
+
export { hapiChannelIntegration };
|
|
50
|
+
//# sourceMappingURL=hapi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hapi.js","sources":["../../../../src/integrations/tracing-channel/hapi.ts"],"sourcesContent":["import * as diagnosticsChannel from 'node:diagnostics_channel';\nimport type { IntegrationFn } from '@sentry/core';\nimport { debug, defineIntegration } from '@sentry/core';\nimport { DEBUG_BUILD } from '../../debug-build';\nimport { CHANNELS } from '../../orchestrion/channels';\nimport { wrapExtArguments, wrapRouteArguments } from './hapi-utils';\n\n// NOTE: same name as the OTel integration by design — when enabled, the OTel\n// 'Hapi' integration is omitted from the default set.\nconst INTEGRATION_NAME = 'Hapi' as const;\n\n/**\n * The shape orchestrion's transform attaches to the `@hapi/hapi` route/ext\n * tracing-channel `context` objects.\n *\n * `arguments` is the *live* args array passed to `server.route` / `server.ext`;\n * we mutate it in place to swap handlers for span-creating proxies. `self` is\n * the hapi server instance: the root server has `self.realm.plugin === undefined`,\n * while a plugin's clone server exposes the registering plugin's name there.\n */\ninterface HapiChannelContext {\n arguments: unknown[];\n self?: { realm?: { plugin?: string } };\n}\n\nconst _hapiChannelIntegration = (() => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n if (!diagnosticsChannel.tracingChannel) {\n return;\n }\n\n DEBUG_BUILD &&\n debug.log(`[orchestrion:hapi] subscribing to channels \"${CHANNELS.HAPI_ROUTE}\" / \"${CHANNELS.HAPI_EXT}\"`);\n\n // `subscribe` requires all five lifecycle hooks. We only act on `start`,\n // which orchestrion fires synchronously with the live args array — that's\n // the moment we mutate the handlers in place.\n diagnosticsChannel.tracingChannel(CHANNELS.HAPI_ROUTE).subscribe({\n start(rawCtx) {\n const ctx = rawCtx as HapiChannelContext;\n wrapRouteArguments(ctx.arguments, ctx.self?.realm?.plugin);\n },\n end() {},\n asyncStart() {},\n asyncEnd() {},\n error() {},\n });\n\n diagnosticsChannel.tracingChannel(CHANNELS.HAPI_EXT).subscribe({\n start(rawCtx) {\n const ctx = rawCtx as HapiChannelContext;\n wrapExtArguments(ctx.arguments, ctx.self?.realm?.plugin);\n },\n end() {},\n asyncStart() {},\n asyncEnd() {},\n error() {},\n });\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * EXPERIMENTAL — orchestrion-driven hapi integration. Subscribes to the\n * `orchestrion:@hapi/hapi:route` / `:ext` channels injected into `@hapi/hapi`'s\n * `lib/server.js`. Requires the orchestrion runtime hook or bundler plugin.\n */\nexport const hapiChannelIntegration = defineIntegration(_hapiChannelIntegration);\n"],"names":[],"mappings":";;;;;;AASA,MAAM,gBAAA,GAAmB,MAAA;AAgBzB,MAAM,2BAA2B,MAAM;AACrC,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,gBAAA;AAAA,IACN,SAAA,GAAY;AACV,MAAA,IAAI,CAAC,mBAAmB,cAAA,EAAgB;AACtC,QAAA;AAAA,MACF;AAEA,MAAA,WAAA,IACE,KAAA,CAAM,IAAI,CAAA,4CAAA,EAA+C,QAAA,CAAS,UAAU,CAAA,KAAA,EAAQ,QAAA,CAAS,QAAQ,CAAA,CAAA,CAAG,CAAA;AA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