@sentry/node 9.16.0 → 9.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/build/cjs/index.js +18 -18
  2. package/build/cjs/integrations/anr/index.js +1 -1
  3. package/build/cjs/integrations/http/index.js +0 -18
  4. package/build/cjs/integrations/http/index.js.map +1 -1
  5. package/build/cjs/integrations/local-variables/local-variables-async.js +1 -1
  6. package/build/cjs/integrations/tracing/fastify/index.js +187 -0
  7. package/build/cjs/integrations/tracing/fastify/index.js.map +1 -0
  8. package/build/cjs/integrations/tracing/fastify/v3/constants.js +23 -0
  9. package/build/cjs/integrations/tracing/fastify/v3/constants.js.map +1 -0
  10. package/build/cjs/integrations/tracing/fastify/v3/enums/AttributeNames.js +37 -0
  11. package/build/cjs/integrations/tracing/fastify/v3/enums/AttributeNames.js.map +1 -0
  12. package/build/cjs/integrations/tracing/fastify/v3/instrumentation.js +303 -0
  13. package/build/cjs/integrations/tracing/fastify/v3/instrumentation.js.map +1 -0
  14. package/build/cjs/integrations/tracing/fastify/v3/utils.js +135 -0
  15. package/build/cjs/integrations/tracing/fastify/v3/utils.js.map +1 -0
  16. package/build/cjs/integrations/tracing/index.js +11 -10
  17. package/build/cjs/integrations/tracing/index.js.map +1 -1
  18. package/build/esm/index.js +1 -1
  19. package/build/esm/integrations/anr/index.js +1 -1
  20. package/build/esm/integrations/anr/worker-script.js +2 -2
  21. package/build/esm/integrations/http/index.js +0 -18
  22. package/build/esm/integrations/http/index.js.map +1 -1
  23. package/build/esm/integrations/local-variables/local-variables-async.js +1 -1
  24. package/build/esm/integrations/local-variables/worker-script.js +2 -2
  25. package/build/esm/integrations/tracing/fastify/index.js +182 -0
  26. package/build/esm/integrations/tracing/fastify/index.js.map +1 -0
  27. package/build/esm/integrations/tracing/fastify/v3/constants.js +21 -0
  28. package/build/esm/integrations/tracing/fastify/v3/constants.js.map +1 -0
  29. package/build/esm/integrations/tracing/fastify/v3/enums/AttributeNames.js +37 -0
  30. package/build/esm/integrations/tracing/fastify/v3/enums/AttributeNames.js.map +1 -0
  31. package/build/esm/integrations/tracing/fastify/v3/instrumentation.js +301 -0
  32. package/build/esm/integrations/tracing/fastify/v3/instrumentation.js.map +1 -0
  33. package/build/esm/integrations/tracing/fastify/v3/utils.js +131 -0
  34. package/build/esm/integrations/tracing/fastify/v3/utils.js.map +1 -0
  35. package/build/esm/integrations/tracing/index.js +2 -1
  36. package/build/esm/integrations/tracing/index.js.map +1 -1
  37. package/build/esm/package.json +1 -1
  38. package/build/types/integrations/http/index.d.ts.map +1 -1
  39. package/build/{types-ts3.8/integrations/tracing/fastify.d.ts → types/integrations/tracing/fastify/index.d.ts} +83 -103
  40. package/build/types/integrations/tracing/fastify/index.d.ts.map +1 -0
  41. package/build/types/integrations/tracing/fastify/types.d.ts +25 -0
  42. package/build/types/integrations/tracing/fastify/types.d.ts.map +1 -0
  43. package/build/types/integrations/tracing/fastify/v3/constants.d.ts +3 -0
  44. package/build/types/integrations/tracing/fastify/v3/constants.d.ts.map +1 -0
  45. package/build/types/integrations/tracing/fastify/v3/enums/AttributeNames.d.ts +15 -0
  46. package/build/types/integrations/tracing/fastify/v3/enums/AttributeNames.d.ts.map +1 -0
  47. package/build/types/integrations/tracing/fastify/v3/instrumentation.d.ts +16 -0
  48. package/build/types/integrations/tracing/fastify/v3/instrumentation.d.ts.map +1 -0
  49. package/build/types/integrations/tracing/fastify/v3/internal-types.d.ts +7 -0
  50. package/build/types/integrations/tracing/fastify/v3/internal-types.d.ts.map +1 -0
  51. package/build/types/integrations/tracing/fastify/v3/types.d.ts +21 -0
  52. package/build/types/integrations/tracing/fastify/v3/types.d.ts.map +1 -0
  53. package/build/types/integrations/tracing/fastify/v3/utils.d.ts +28 -0
  54. package/build/types/integrations/tracing/fastify/v3/utils.d.ts.map +1 -0
  55. package/build/types/integrations/tracing/index.d.ts.map +1 -1
  56. package/build/{types/integrations/tracing/fastify.d.ts → types-ts3.8/integrations/tracing/fastify/index.d.ts} +83 -103
  57. package/build/types-ts3.8/integrations/tracing/fastify/types.d.ts +25 -0
  58. package/build/types-ts3.8/integrations/tracing/fastify/v3/constants.d.ts +3 -0
  59. package/build/types-ts3.8/integrations/tracing/fastify/v3/enums/AttributeNames.d.ts +15 -0
  60. package/build/types-ts3.8/integrations/tracing/fastify/v3/instrumentation.d.ts +16 -0
  61. package/build/types-ts3.8/integrations/tracing/fastify/v3/internal-types.d.ts +7 -0
  62. package/build/types-ts3.8/integrations/tracing/fastify/v3/types.d.ts +21 -0
  63. package/build/types-ts3.8/integrations/tracing/fastify/v3/utils.d.ts +28 -0
  64. package/package.json +4 -4
  65. package/build/cjs/integrations/http/SentryHttpInstrumentationBeforeOtel.js +0 -136
  66. package/build/cjs/integrations/http/SentryHttpInstrumentationBeforeOtel.js.map +0 -1
  67. package/build/cjs/integrations/http/utils.js +0 -44
  68. package/build/cjs/integrations/http/utils.js.map +0 -1
  69. package/build/cjs/integrations/tracing/fastify.js +0 -160
  70. package/build/cjs/integrations/tracing/fastify.js.map +0 -1
  71. package/build/esm/integrations/http/SentryHttpInstrumentationBeforeOtel.js +0 -134
  72. package/build/esm/integrations/http/SentryHttpInstrumentationBeforeOtel.js.map +0 -1
  73. package/build/esm/integrations/http/utils.js +0 -42
  74. package/build/esm/integrations/http/utils.js.map +0 -1
  75. package/build/esm/integrations/tracing/fastify.js +0 -156
  76. package/build/esm/integrations/tracing/fastify.js.map +0 -1
  77. package/build/types/integrations/http/SentryHttpInstrumentationBeforeOtel.d.ts +0 -17
  78. package/build/types/integrations/http/SentryHttpInstrumentationBeforeOtel.d.ts.map +0 -1
  79. package/build/types/integrations/tracing/fastify.d.ts.map +0 -1
  80. package/build/types-ts3.8/integrations/http/SentryHttpInstrumentationBeforeOtel.d.ts +0 -20
@@ -1,103 +1,83 @@
1
- import { FastifyInstrumentation } from '@opentelemetry/instrumentation-fastify';
2
- /**
3
- * Minimal request type containing properties around route information.
4
- * Works for Fastify 3, 4 and presumably 5.
5
- *
6
- * Based on https://github.com/fastify/fastify/blob/ce3811f5f718be278bbcd4392c615d64230065a6/types/request.d.ts
7
- */
8
- interface MinimalFastifyRequest extends Record<string, any> {
9
- method?: string;
10
- routeOptions?: {
11
- url?: string;
12
- };
13
- routerPath?: string;
14
- }
15
- /**
16
- * Minimal reply type containing properties needed for error handling.
17
- *
18
- * Based on https://github.com/fastify/fastify/blob/ce3811f5f718be278bbcd4392c615d64230065a6/types/reply.d.ts
19
- */
20
- interface MinimalFastifyReply extends Record<string, any> {
21
- statusCode: number;
22
- }
23
- interface Fastify {
24
- register: (plugin: any) => void;
25
- addHook: (hook: string, handler: (...params: unknown[]) => void) => void;
26
- }
27
- interface FastifyHandlerOptions {
28
- /**
29
- * Callback method deciding whether error should be captured and sent to Sentry
30
- *
31
- * @param error Captured Fastify error
32
- * @param request Fastify request (or any object containing at least method, routeOptions.url, and routerPath)
33
- * @param reply Fastify reply (or any object containing at least statusCode)
34
- *
35
- * @example
36
- *
37
- * ```javascript
38
- * setupFastifyErrorHandler(app, {
39
- * shouldHandleError(_error, _request, reply) {
40
- * return reply.statusCode >= 400;
41
- * },
42
- * });
43
- * ```
44
- *
45
- * If using TypeScript, you can cast the request and reply to get full type safety.
46
- *
47
- * ```typescript
48
- * import type { FastifyRequest, FastifyReply } from 'fastify';
49
- *
50
- * setupFastifyErrorHandler(app, {
51
- * shouldHandleError(error, minimalRequest, minimalReply) {
52
- * const request = minimalRequest as FastifyRequest;
53
- * const reply = minimalReply as FastifyReply;
54
- * return reply.statusCode >= 500;
55
- * },
56
- * });
57
- * ```
58
- */
59
- shouldHandleError: (error: Error, request: MinimalFastifyRequest, reply: MinimalFastifyReply) => boolean;
60
- }
61
- export declare const instrumentFastify: ((options?: unknown) => FastifyInstrumentation) & {
62
- id: string;
63
- };
64
- /**
65
- * Adds Sentry tracing instrumentation for [Fastify](https://fastify.dev/).
66
- *
67
- * If you also want to capture errors, you need to call `setupFastifyErrorHandler(app)` after you set up your Fastify server.
68
- *
69
- * For more information, see the [fastify documentation](https://docs.sentry.io/platforms/javascript/guides/fastify/).
70
- *
71
- * @example
72
- * ```javascript
73
- * const Sentry = require('@sentry/node');
74
- *
75
- * Sentry.init({
76
- * integrations: [Sentry.fastifyIntegration()],
77
- * })
78
- * ```
79
- */
80
- export declare const fastifyIntegration: () => import("@sentry/core").Integration;
81
- /**
82
- * Add an Fastify error handler to capture errors to Sentry.
83
- *
84
- * @param fastify The Fastify instance to which to add the error handler
85
- * @param options Configuration options for the handler
86
- *
87
- * @example
88
- * ```javascript
89
- * const Sentry = require('@sentry/node');
90
- * const Fastify = require("fastify");
91
- *
92
- * const app = Fastify();
93
- *
94
- * Sentry.setupFastifyErrorHandler(app);
95
- *
96
- * // Add your routes, etc.
97
- *
98
- * app.listen({ port: 3000 });
99
- * ```
100
- */
101
- export declare function setupFastifyErrorHandler(fastify: Fastify, options?: Partial<FastifyHandlerOptions>): void;
102
- export {};
103
- //# sourceMappingURL=fastify.d.ts.map
1
+ import type { Instrumentation, InstrumentationConfig } from '@opentelemetry/instrumentation';
2
+ import type { FastifyInstance, FastifyReply, FastifyRequest } from './types';
3
+ import { FastifyInstrumentationV3 } from './v3/instrumentation';
4
+ interface FastifyHandlerOptions {
5
+ /**
6
+ * Callback method deciding whether error should be captured and sent to Sentry
7
+ *
8
+ * @param error Captured Fastify error
9
+ * @param request Fastify request (or any object containing at least method, routeOptions.url, and routerPath)
10
+ * @param reply Fastify reply (or any object containing at least statusCode)
11
+ *
12
+ * @example
13
+ *
14
+ * ```javascript
15
+ * setupFastifyErrorHandler(app, {
16
+ * shouldHandleError(_error, _request, reply) {
17
+ * return reply.statusCode >= 400;
18
+ * },
19
+ * });
20
+ * ```
21
+ *
22
+ * If using TypeScript, you can cast the request and reply to get full type safety.
23
+ *
24
+ * ```typescript
25
+ * import type { FastifyRequest, FastifyReply } from 'fastify';
26
+ *
27
+ * setupFastifyErrorHandler(app, {
28
+ * shouldHandleError(error, minimalRequest, minimalReply) {
29
+ * const request = minimalRequest as FastifyRequest;
30
+ * const reply = minimalReply as FastifyReply;
31
+ * return reply.statusCode >= 500;
32
+ * },
33
+ * });
34
+ * ```
35
+ */
36
+ shouldHandleError: (error: Error, request: FastifyRequest, reply: FastifyReply) => boolean;
37
+ }
38
+ export declare const instrumentFastifyV3: ((options?: unknown) => FastifyInstrumentationV3) & {
39
+ id: string;
40
+ };
41
+ export declare const instrumentFastify: ((options?: unknown) => Instrumentation<InstrumentationConfig>) & {
42
+ id: string;
43
+ };
44
+ /**
45
+ * Adds Sentry tracing instrumentation for [Fastify](https://fastify.dev/).
46
+ *
47
+ * If you also want to capture errors, you need to call `setupFastifyErrorHandler(app)` after you set up your Fastify server.
48
+ *
49
+ * For more information, see the [fastify documentation](https://docs.sentry.io/platforms/javascript/guides/fastify/).
50
+ *
51
+ * @example
52
+ * ```javascript
53
+ * const Sentry = require('@sentry/node');
54
+ *
55
+ * Sentry.init({
56
+ * integrations: [Sentry.fastifyIntegration()],
57
+ * })
58
+ * ```
59
+ */
60
+ export declare const fastifyIntegration: () => import("@sentry/core").Integration;
61
+ /**
62
+ * Add an Fastify error handler to capture errors to Sentry.
63
+ *
64
+ * @param fastify The Fastify instance to which to add the error handler
65
+ * @param options Configuration options for the handler
66
+ *
67
+ * @example
68
+ * ```javascript
69
+ * const Sentry = require('@sentry/node');
70
+ * const Fastify = require("fastify");
71
+ *
72
+ * const app = Fastify();
73
+ *
74
+ * Sentry.setupFastifyErrorHandler(app);
75
+ *
76
+ * // Add your routes, etc.
77
+ *
78
+ * app.listen({ port: 3000 });
79
+ * ```
80
+ */
81
+ export declare function setupFastifyErrorHandler(fastify: FastifyInstance, options?: Partial<FastifyHandlerOptions>): void;
82
+ export {};
83
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/integrations/tracing/fastify/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAc7F,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAEhE,UAAU,qBAAqB;IAC7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,iBAAiB,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC;CAC5F;AAKD,eAAO,MAAM,mBAAmB;;CAAoF,CAAC;AAErH,eAAO,MAAM,iBAAiB;;CAuB5B,CAAC;AAYH;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,kBAAkB,0CAAyC,CAAC;AAazE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,eAAe,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,qBAAqB,CAAC,GAAG,IAAI,CAqBjH"}
@@ -0,0 +1,25 @@
1
+ export type HandlerOriginal = ((request: FastifyRequest, reply: FastifyReply, done: HookHandlerDoneFunction) => Promise<void>) | ((request: FastifyRequest, reply: FastifyReply, done: HookHandlerDoneFunction) => void);
2
+ export type FastifyError = any;
3
+ export type HookHandlerDoneFunction = <TError extends Error = FastifyError>(err?: TError) => void;
4
+ export type FastifyErrorCodes = any;
5
+ export type FastifyPlugin = (instance: FastifyInstance, opts: any, done: HookHandlerDoneFunction) => unknown | Promise<unknown>;
6
+ export interface FastifyInstance {
7
+ version: string;
8
+ register: (plugin: any) => FastifyInstance;
9
+ after: (listener?: (err: Error) => void) => FastifyInstance;
10
+ addHook(hook: string, handler: HandlerOriginal): FastifyInstance;
11
+ addHook(hook: 'onError', handler: (request: FastifyRequest, reply: FastifyReply, error: Error) => void): FastifyInstance;
12
+ addHook(hook: 'onRequest', handler: (request: FastifyRequest, reply: FastifyReply) => void): FastifyInstance;
13
+ }
14
+ export interface FastifyReply {
15
+ send: () => FastifyReply;
16
+ statusCode: number;
17
+ }
18
+ export interface FastifyRequest {
19
+ method?: string;
20
+ routeOptions?: {
21
+ url?: string;
22
+ };
23
+ routerPath?: string;
24
+ }
25
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/integrations/tracing/fastify/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GACvB,CAAC,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,uBAAuB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,GAChG,CAAC,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,uBAAuB,KAAK,IAAI,CAAC,CAAC;AAE5F,MAAM,MAAM,YAAY,GAAG,GAAG,CAAC;AAE/B,MAAM,MAAM,uBAAuB,GAAG,CAAC,MAAM,SAAS,KAAK,GAAG,YAAY,EAAE,GAAG,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;AAElG,MAAM,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAEpC,MAAM,MAAM,aAAa,GAAG,CAC1B,QAAQ,EAAE,eAAe,EACzB,IAAI,EAAE,GAAG,EACT,IAAI,EAAE,uBAAuB,KAC1B,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAEhC,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,eAAe,CAAC;IAC3C,KAAK,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,IAAI,KAAK,eAAe,CAAC;IAC5D,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,GAAG,eAAe,CAAC;IACjE,OAAO,CACL,IAAI,EAAE,SAAS,EACf,OAAO,EAAE,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,KAAK,KAAK,IAAI,GAC5E,eAAe,CAAC;IACnB,OAAO,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,KAAK,IAAI,GAAG,eAAe,CAAC;CAC9G;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,YAAY,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,YAAY,CAAC,EAAE;QACb,GAAG,CAAC,EAAE,MAAM,CAAC;KACd,CAAC;IACF,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB"}
@@ -0,0 +1,3 @@
1
+ export declare const spanRequestSymbol: unique symbol;
2
+ export declare const hooksNamesToWrap: Set<string>;
3
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../../../src/integrations/tracing/fastify/v3/constants.ts"],"names":[],"mappings":"AAiBA,eAAO,MAAM,iBAAiB,eAAsE,CAAC;AAMrG,eAAO,MAAM,gBAAgB,aAU3B,CAAC"}
@@ -0,0 +1,15 @@
1
+ export declare enum AttributeNames {
2
+ FASTIFY_NAME = "fastify.name",
3
+ FASTIFY_TYPE = "fastify.type",
4
+ HOOK_NAME = "hook.name",
5
+ PLUGIN_NAME = "plugin.name"
6
+ }
7
+ export declare enum FastifyTypes {
8
+ MIDDLEWARE = "middleware",
9
+ REQUEST_HANDLER = "request_handler"
10
+ }
11
+ export declare enum FastifyNames {
12
+ MIDDLEWARE = "middleware",
13
+ REQUEST_HANDLER = "request handler"
14
+ }
15
+ //# sourceMappingURL=AttributeNames.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AttributeNames.d.ts","sourceRoot":"","sources":["../../../../../../../src/integrations/tracing/fastify/v3/enums/AttributeNames.ts"],"names":[],"mappings":"AAkBA,oBAAY,cAAc;IACxB,YAAY,iBAAiB;IAC7B,YAAY,iBAAiB;IAC7B,SAAS,cAAc;IACvB,WAAW,gBAAgB;CAC5B;AAED,oBAAY,YAAY;IACtB,UAAU,eAAe;IACzB,eAAe,oBAAoB;CACpC;AAED,oBAAY,YAAY;IACtB,UAAU,eAAe;IACzB,eAAe,oBAAoB;CACpC"}
@@ -0,0 +1,16 @@
1
+ import { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';
2
+ import type { FastifyInstrumentationConfig } from './types';
3
+ /**
4
+ * Fastify instrumentation for OpenTelemetry
5
+ */
6
+ export declare class FastifyInstrumentationV3 extends InstrumentationBase<FastifyInstrumentationConfig> {
7
+ constructor(config?: FastifyInstrumentationConfig);
8
+ init(): InstrumentationNodeModuleDefinition[];
9
+ private _hookOnRequest;
10
+ private _wrapHandler;
11
+ private _wrapAddHook;
12
+ private _patchConstructor;
13
+ private _patchSend;
14
+ private _hookPreHandler;
15
+ }
16
+ //# sourceMappingURL=instrumentation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instrumentation.d.ts","sourceRoot":"","sources":["../../../../../../src/integrations/tracing/fastify/v3/instrumentation.ts"],"names":[],"mappings":"AAwBA,OAAO,EACL,mBAAmB,EACnB,mCAAmC,EAEpC,MAAM,gCAAgC,CAAC;AAoBxC,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,SAAS,CAAC;AAyB5D;;GAEG;AACH,qBAAa,wBAAyB,SAAQ,mBAAmB,CAAC,4BAA4B,CAAC;gBAC1E,MAAM,GAAE,4BAAiC;IAIrD,IAAI,IAAI,mCAAmC,EAAE;IAQpD,OAAO,CAAC,cAAc;IA0BtB,OAAO,CAAC,YAAY;IAwDpB,OAAO,CAAC,YAAY;IAyBpB,OAAO,CAAC,iBAAiB;IA0BzB,OAAO,CAAC,UAAU;IA4BlB,OAAO,CAAC,eAAe;CA+CxB"}
@@ -0,0 +1,7 @@
1
+ import type { Span } from '@opentelemetry/api';
2
+ import type { FastifyReply } from '../types';
3
+ import type { spanRequestSymbol } from './constants';
4
+ export type PluginFastifyReply = FastifyReply & {
5
+ [spanRequestSymbol]?: Span[];
6
+ };
7
+ //# sourceMappingURL=internal-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal-types.d.ts","sourceRoot":"","sources":["../../../../../../src/integrations/tracing/fastify/v3/internal-types.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD,MAAM,MAAM,kBAAkB,GAAG,YAAY,GAAG;IAC9C,CAAC,iBAAiB,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC;CAC9B,CAAC"}
@@ -0,0 +1,21 @@
1
+ import type { Span } from '@opentelemetry/api';
2
+ import type { InstrumentationConfig } from '@opentelemetry/instrumentation';
3
+ export interface FastifyRequestInfo {
4
+ request: any;
5
+ }
6
+ /**
7
+ * Function that can be used to add custom attributes to the current span
8
+ * @param span - The Fastify handler span.
9
+ * @param info - The Fastify request info object.
10
+ */
11
+ export interface FastifyCustomAttributeFunction {
12
+ (span: Span, info: FastifyRequestInfo): void;
13
+ }
14
+ /**
15
+ * Options available for the Fastify Instrumentation
16
+ */
17
+ export interface FastifyInstrumentationConfig extends InstrumentationConfig {
18
+ /** Function for adding custom attributes to each handler span */
19
+ requestHook?: FastifyCustomAttributeFunction;
20
+ }
21
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../src/integrations/tracing/fastify/v3/types.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAE5E,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,GAAG,CAAC;CACd;AAED;;;;GAIG;AACH,MAAM,WAAW,8BAA8B;IAC7C,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,kBAAkB,GAAG,IAAI,CAAC;CAC9C;AAED;;GAEG;AACH,MAAM,WAAW,4BAA6B,SAAQ,qBAAqB;IACzE,iEAAiE;IACjE,WAAW,CAAC,EAAE,8BAA8B,CAAC;CAC9C"}
@@ -0,0 +1,28 @@
1
+ import { type Attributes, type Span, type Tracer } from '@opentelemetry/api';
2
+ import type { PluginFastifyReply } from './internal-types';
3
+ /**
4
+ * Starts Span
5
+ * @param reply - reply function
6
+ * @param tracer - tracer
7
+ * @param spanName - span name
8
+ * @param spanAttributes - span attributes
9
+ */
10
+ export declare function startSpan(reply: PluginFastifyReply, tracer: Tracer, spanName: string, spanAttributes?: Attributes): Span;
11
+ /**
12
+ * Ends span
13
+ * @param reply - reply function
14
+ * @param err - error
15
+ */
16
+ export declare function endSpan(reply: PluginFastifyReply, err?: any): void;
17
+ /**
18
+ * This function handles the missing case from instrumentation package when
19
+ * execute can either return a promise or void. And using async is not an
20
+ * option as it is producing unwanted side effects.
21
+ * @param execute - function to be executed
22
+ * @param onFinish - function called when function executed
23
+ * @param preventThrowingError - prevent to throw error when execute
24
+ * function fails
25
+ */
26
+ export declare function safeExecuteInTheMiddleMaybePromise<T>(execute: () => Promise<T>, onFinish: (e: unknown, result?: T) => void, preventThrowingError?: boolean): Promise<T>;
27
+ export declare function safeExecuteInTheMiddleMaybePromise<T>(execute: () => T, onFinish: (e: unknown, result?: T) => void, preventThrowingError?: boolean): T;
28
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../../src/integrations/tracing/fastify/v3/utils.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,IAAI,EAAE,KAAK,MAAM,EAAkB,MAAM,oBAAoB,CAAC;AAE7F,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE3D;;;;;;GAMG;AACH,wBAAgB,SAAS,CACvB,KAAK,EAAE,kBAAkB,EACzB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,cAAc,GAAE,UAAe,QAehC;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,kBAAkB,EAAE,GAAG,CAAC,EAAE,GAAG,QAkB3D;AAKD;;;;;;;;GAQG;AACH,wBAAgB,kCAAkC,CAAC,CAAC,EAClD,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACzB,QAAQ,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,CAAC,KAAK,IAAI,EAC1C,oBAAoB,CAAC,EAAE,OAAO,GAC7B,OAAO,CAAC,CAAC,CAAC,CAAC;AACd,wBAAgB,kCAAkC,CAAC,CAAC,EAClD,OAAO,EAAE,MAAM,CAAC,EAChB,QAAQ,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,CAAC,KAAK,IAAI,EAC1C,oBAAoB,CAAC,EAAE,OAAO,GAC7B,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/integrations/tracing/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAsBhD;;GAEG;AACH,wBAAgB,8BAA8B,IAAI,WAAW,EAAE,CAsB9D;AAED;;GAEG;AAEH,wBAAgB,wCAAwC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC,EAAE,CAwBzG"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/integrations/tracing/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAsBhD;;GAEG;AACH,wBAAgB,8BAA8B,IAAI,WAAW,EAAE,CAsB9D;AAED;;GAEG;AAEH,wBAAgB,wCAAwC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC,EAAE,CAyBzG"}
@@ -1,103 +1,83 @@
1
- import { FastifyInstrumentation } from '@opentelemetry/instrumentation-fastify';
2
- /**
3
- * Minimal request type containing properties around route information.
4
- * Works for Fastify 3, 4 and presumably 5.
5
- *
6
- * Based on https://github.com/fastify/fastify/blob/ce3811f5f718be278bbcd4392c615d64230065a6/types/request.d.ts
7
- */
8
- interface MinimalFastifyRequest extends Record<string, any> {
9
- method?: string;
10
- routeOptions?: {
11
- url?: string;
12
- };
13
- routerPath?: string;
14
- }
15
- /**
16
- * Minimal reply type containing properties needed for error handling.
17
- *
18
- * Based on https://github.com/fastify/fastify/blob/ce3811f5f718be278bbcd4392c615d64230065a6/types/reply.d.ts
19
- */
20
- interface MinimalFastifyReply extends Record<string, any> {
21
- statusCode: number;
22
- }
23
- interface Fastify {
24
- register: (plugin: any) => void;
25
- addHook: (hook: string, handler: (...params: unknown[]) => void) => void;
26
- }
27
- interface FastifyHandlerOptions {
28
- /**
29
- * Callback method deciding whether error should be captured and sent to Sentry
30
- *
31
- * @param error Captured Fastify error
32
- * @param request Fastify request (or any object containing at least method, routeOptions.url, and routerPath)
33
- * @param reply Fastify reply (or any object containing at least statusCode)
34
- *
35
- * @example
36
- *
37
- * ```javascript
38
- * setupFastifyErrorHandler(app, {
39
- * shouldHandleError(_error, _request, reply) {
40
- * return reply.statusCode >= 400;
41
- * },
42
- * });
43
- * ```
44
- *
45
- * If using TypeScript, you can cast the request and reply to get full type safety.
46
- *
47
- * ```typescript
48
- * import type { FastifyRequest, FastifyReply } from 'fastify';
49
- *
50
- * setupFastifyErrorHandler(app, {
51
- * shouldHandleError(error, minimalRequest, minimalReply) {
52
- * const request = minimalRequest as FastifyRequest;
53
- * const reply = minimalReply as FastifyReply;
54
- * return reply.statusCode >= 500;
55
- * },
56
- * });
57
- * ```
58
- */
59
- shouldHandleError: (error: Error, request: MinimalFastifyRequest, reply: MinimalFastifyReply) => boolean;
60
- }
61
- export declare const instrumentFastify: ((options?: unknown) => FastifyInstrumentation) & {
62
- id: string;
63
- };
64
- /**
65
- * Adds Sentry tracing instrumentation for [Fastify](https://fastify.dev/).
66
- *
67
- * If you also want to capture errors, you need to call `setupFastifyErrorHandler(app)` after you set up your Fastify server.
68
- *
69
- * For more information, see the [fastify documentation](https://docs.sentry.io/platforms/javascript/guides/fastify/).
70
- *
71
- * @example
72
- * ```javascript
73
- * const Sentry = require('@sentry/node');
74
- *
75
- * Sentry.init({
76
- * integrations: [Sentry.fastifyIntegration()],
77
- * })
78
- * ```
79
- */
80
- export declare const fastifyIntegration: () => import("@sentry/core").Integration;
81
- /**
82
- * Add an Fastify error handler to capture errors to Sentry.
83
- *
84
- * @param fastify The Fastify instance to which to add the error handler
85
- * @param options Configuration options for the handler
86
- *
87
- * @example
88
- * ```javascript
89
- * const Sentry = require('@sentry/node');
90
- * const Fastify = require("fastify");
91
- *
92
- * const app = Fastify();
93
- *
94
- * Sentry.setupFastifyErrorHandler(app);
95
- *
96
- * // Add your routes, etc.
97
- *
98
- * app.listen({ port: 3000 });
99
- * ```
100
- */
101
- export declare function setupFastifyErrorHandler(fastify: Fastify, options?: Partial<FastifyHandlerOptions>): void;
102
- export {};
103
- //# sourceMappingURL=fastify.d.ts.map
1
+ import { Instrumentation, InstrumentationConfig } from '@opentelemetry/instrumentation';
2
+ import { FastifyInstance, FastifyReply, FastifyRequest } from './types';
3
+ import { FastifyInstrumentationV3 } from './v3/instrumentation';
4
+ interface FastifyHandlerOptions {
5
+ /**
6
+ * Callback method deciding whether error should be captured and sent to Sentry
7
+ *
8
+ * @param error Captured Fastify error
9
+ * @param request Fastify request (or any object containing at least method, routeOptions.url, and routerPath)
10
+ * @param reply Fastify reply (or any object containing at least statusCode)
11
+ *
12
+ * @example
13
+ *
14
+ * ```javascript
15
+ * setupFastifyErrorHandler(app, {
16
+ * shouldHandleError(_error, _request, reply) {
17
+ * return reply.statusCode >= 400;
18
+ * },
19
+ * });
20
+ * ```
21
+ *
22
+ * If using TypeScript, you can cast the request and reply to get full type safety.
23
+ *
24
+ * ```typescript
25
+ * import type { FastifyRequest, FastifyReply } from 'fastify';
26
+ *
27
+ * setupFastifyErrorHandler(app, {
28
+ * shouldHandleError(error, minimalRequest, minimalReply) {
29
+ * const request = minimalRequest as FastifyRequest;
30
+ * const reply = minimalReply as FastifyReply;
31
+ * return reply.statusCode >= 500;
32
+ * },
33
+ * });
34
+ * ```
35
+ */
36
+ shouldHandleError: (error: Error, request: FastifyRequest, reply: FastifyReply) => boolean;
37
+ }
38
+ export declare const instrumentFastifyV3: ((options?: unknown) => FastifyInstrumentationV3) & {
39
+ id: string;
40
+ };
41
+ export declare const instrumentFastify: ((options?: unknown) => Instrumentation<InstrumentationConfig>) & {
42
+ id: string;
43
+ };
44
+ /**
45
+ * Adds Sentry tracing instrumentation for [Fastify](https://fastify.dev/).
46
+ *
47
+ * If you also want to capture errors, you need to call `setupFastifyErrorHandler(app)` after you set up your Fastify server.
48
+ *
49
+ * For more information, see the [fastify documentation](https://docs.sentry.io/platforms/javascript/guides/fastify/).
50
+ *
51
+ * @example
52
+ * ```javascript
53
+ * const Sentry = require('@sentry/node');
54
+ *
55
+ * Sentry.init({
56
+ * integrations: [Sentry.fastifyIntegration()],
57
+ * })
58
+ * ```
59
+ */
60
+ export declare const fastifyIntegration: () => import("@sentry/core").Integration;
61
+ /**
62
+ * Add an Fastify error handler to capture errors to Sentry.
63
+ *
64
+ * @param fastify The Fastify instance to which to add the error handler
65
+ * @param options Configuration options for the handler
66
+ *
67
+ * @example
68
+ * ```javascript
69
+ * const Sentry = require('@sentry/node');
70
+ * const Fastify = require("fastify");
71
+ *
72
+ * const app = Fastify();
73
+ *
74
+ * Sentry.setupFastifyErrorHandler(app);
75
+ *
76
+ * // Add your routes, etc.
77
+ *
78
+ * app.listen({ port: 3000 });
79
+ * ```
80
+ */
81
+ export declare function setupFastifyErrorHandler(fastify: FastifyInstance, options?: Partial<FastifyHandlerOptions>): void;
82
+ export {};
83
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,25 @@
1
+ export type HandlerOriginal = ((request: FastifyRequest, reply: FastifyReply, done: HookHandlerDoneFunction) => Promise<void>) | ((request: FastifyRequest, reply: FastifyReply, done: HookHandlerDoneFunction) => void);
2
+ export type FastifyError = any;
3
+ export type HookHandlerDoneFunction = <TError extends Error = FastifyError>(err?: TError) => void;
4
+ export type FastifyErrorCodes = any;
5
+ export type FastifyPlugin = (instance: FastifyInstance, opts: any, done: HookHandlerDoneFunction) => unknown | Promise<unknown>;
6
+ export interface FastifyInstance {
7
+ version: string;
8
+ register: (plugin: any) => FastifyInstance;
9
+ after: (listener?: (err: Error) => void) => FastifyInstance;
10
+ addHook(hook: string, handler: HandlerOriginal): FastifyInstance;
11
+ addHook(hook: 'onError', handler: (request: FastifyRequest, reply: FastifyReply, error: Error) => void): FastifyInstance;
12
+ addHook(hook: 'onRequest', handler: (request: FastifyRequest, reply: FastifyReply) => void): FastifyInstance;
13
+ }
14
+ export interface FastifyReply {
15
+ send: () => FastifyReply;
16
+ statusCode: number;
17
+ }
18
+ export interface FastifyRequest {
19
+ method?: string;
20
+ routeOptions?: {
21
+ url?: string;
22
+ };
23
+ routerPath?: string;
24
+ }
25
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,3 @@
1
+ export declare const spanRequestSymbol: unique symbol;
2
+ export declare const hooksNamesToWrap: Set<string>;
3
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1,15 @@
1
+ export declare enum AttributeNames {
2
+ FASTIFY_NAME = "fastify.name",
3
+ FASTIFY_TYPE = "fastify.type",
4
+ HOOK_NAME = "hook.name",
5
+ PLUGIN_NAME = "plugin.name"
6
+ }
7
+ export declare enum FastifyTypes {
8
+ MIDDLEWARE = "middleware",
9
+ REQUEST_HANDLER = "request_handler"
10
+ }
11
+ export declare enum FastifyNames {
12
+ MIDDLEWARE = "middleware",
13
+ REQUEST_HANDLER = "request handler"
14
+ }
15
+ //# sourceMappingURL=AttributeNames.d.ts.map
@@ -0,0 +1,16 @@
1
+ import { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';
2
+ import { FastifyInstrumentationConfig } from './types';
3
+ /**
4
+ * Fastify instrumentation for OpenTelemetry
5
+ */
6
+ export declare class FastifyInstrumentationV3 extends InstrumentationBase<FastifyInstrumentationConfig> {
7
+ constructor(config?: FastifyInstrumentationConfig);
8
+ init(): InstrumentationNodeModuleDefinition[];
9
+ private _hookOnRequest;
10
+ private _wrapHandler;
11
+ private _wrapAddHook;
12
+ private _patchConstructor;
13
+ private _patchSend;
14
+ private _hookPreHandler;
15
+ }
16
+ //# sourceMappingURL=instrumentation.d.ts.map
@@ -0,0 +1,7 @@
1
+ import { Span } from '@opentelemetry/api';
2
+ import { FastifyReply } from '../types';
3
+ import { spanRequestSymbol } from './constants';
4
+ export type PluginFastifyReply = FastifyReply & {
5
+ [spanRequestSymbol]?: Span[];
6
+ };
7
+ //# sourceMappingURL=internal-types.d.ts.map