@sentry/node 9.16.1 → 9.18.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/SentryHttpInstrumentation.js +61 -0
  4. package/build/cjs/integrations/http/SentryHttpInstrumentation.js.map +1 -1
  5. package/build/cjs/integrations/http/index.js +3 -0
  6. package/build/cjs/integrations/http/index.js.map +1 -1
  7. package/build/cjs/integrations/local-variables/local-variables-async.js +1 -1
  8. package/build/cjs/integrations/tracing/fastify/index.js +187 -0
  9. package/build/cjs/integrations/tracing/fastify/index.js.map +1 -0
  10. package/build/cjs/integrations/tracing/fastify/v3/constants.js +23 -0
  11. package/build/cjs/integrations/tracing/fastify/v3/constants.js.map +1 -0
  12. package/build/cjs/integrations/tracing/fastify/v3/enums/AttributeNames.js +37 -0
  13. package/build/cjs/integrations/tracing/fastify/v3/enums/AttributeNames.js.map +1 -0
  14. package/build/cjs/integrations/tracing/fastify/v3/instrumentation.js +303 -0
  15. package/build/cjs/integrations/tracing/fastify/v3/instrumentation.js.map +1 -0
  16. package/build/cjs/integrations/tracing/fastify/v3/utils.js +135 -0
  17. package/build/cjs/integrations/tracing/fastify/v3/utils.js.map +1 -0
  18. package/build/cjs/integrations/tracing/index.js +11 -10
  19. package/build/cjs/integrations/tracing/index.js.map +1 -1
  20. package/build/cjs/sdk/initOtel.js +1 -1
  21. package/build/cjs/sdk/initOtel.js.map +1 -1
  22. package/build/esm/index.js +1 -1
  23. package/build/esm/integrations/anr/index.js +1 -1
  24. package/build/esm/integrations/anr/worker-script.js +2 -2
  25. package/build/esm/integrations/http/SentryHttpInstrumentation.js +62 -1
  26. package/build/esm/integrations/http/SentryHttpInstrumentation.js.map +1 -1
  27. package/build/esm/integrations/http/index.js +3 -0
  28. package/build/esm/integrations/http/index.js.map +1 -1
  29. package/build/esm/integrations/local-variables/local-variables-async.js +1 -1
  30. package/build/esm/integrations/local-variables/worker-script.js +2 -2
  31. package/build/esm/integrations/tracing/fastify/index.js +182 -0
  32. package/build/esm/integrations/tracing/fastify/index.js.map +1 -0
  33. package/build/esm/integrations/tracing/fastify/v3/constants.js +21 -0
  34. package/build/esm/integrations/tracing/fastify/v3/constants.js.map +1 -0
  35. package/build/esm/integrations/tracing/fastify/v3/enums/AttributeNames.js +37 -0
  36. package/build/esm/integrations/tracing/fastify/v3/enums/AttributeNames.js.map +1 -0
  37. package/build/esm/integrations/tracing/fastify/v3/instrumentation.js +301 -0
  38. package/build/esm/integrations/tracing/fastify/v3/instrumentation.js.map +1 -0
  39. package/build/esm/integrations/tracing/fastify/v3/utils.js +131 -0
  40. package/build/esm/integrations/tracing/fastify/v3/utils.js.map +1 -0
  41. package/build/esm/integrations/tracing/index.js +2 -1
  42. package/build/esm/integrations/tracing/index.js.map +1 -1
  43. package/build/esm/package.json +1 -1
  44. package/build/esm/sdk/initOtel.js +1 -1
  45. package/build/esm/sdk/initOtel.js.map +1 -1
  46. package/build/types/integrations/http/SentryHttpInstrumentation.d.ts +14 -0
  47. package/build/types/integrations/http/SentryHttpInstrumentation.d.ts.map +1 -1
  48. package/build/types/integrations/http/index.d.ts.map +1 -1
  49. package/build/{types-ts3.8/integrations/tracing/fastify.d.ts → types/integrations/tracing/fastify/index.d.ts} +83 -103
  50. package/build/types/integrations/tracing/fastify/index.d.ts.map +1 -0
  51. package/build/types/integrations/tracing/fastify/types.d.ts +25 -0
  52. package/build/types/integrations/tracing/fastify/types.d.ts.map +1 -0
  53. package/build/types/integrations/tracing/fastify/v3/constants.d.ts +3 -0
  54. package/build/types/integrations/tracing/fastify/v3/constants.d.ts.map +1 -0
  55. package/build/types/integrations/tracing/fastify/v3/enums/AttributeNames.d.ts +15 -0
  56. package/build/types/integrations/tracing/fastify/v3/enums/AttributeNames.d.ts.map +1 -0
  57. package/build/types/integrations/tracing/fastify/v3/instrumentation.d.ts +16 -0
  58. package/build/types/integrations/tracing/fastify/v3/instrumentation.d.ts.map +1 -0
  59. package/build/types/integrations/tracing/fastify/v3/internal-types.d.ts +7 -0
  60. package/build/types/integrations/tracing/fastify/v3/internal-types.d.ts.map +1 -0
  61. package/build/types/integrations/tracing/fastify/v3/types.d.ts +21 -0
  62. package/build/types/integrations/tracing/fastify/v3/types.d.ts.map +1 -0
  63. package/build/types/integrations/tracing/fastify/v3/utils.d.ts +28 -0
  64. package/build/types/integrations/tracing/fastify/v3/utils.d.ts.map +1 -0
  65. package/build/types/integrations/tracing/index.d.ts.map +1 -1
  66. package/build/types-ts3.8/integrations/http/SentryHttpInstrumentation.d.ts +14 -0
  67. package/build/{types/integrations/tracing/fastify.d.ts → types-ts3.8/integrations/tracing/fastify/index.d.ts} +83 -103
  68. package/build/types-ts3.8/integrations/tracing/fastify/types.d.ts +25 -0
  69. package/build/types-ts3.8/integrations/tracing/fastify/v3/constants.d.ts +3 -0
  70. package/build/types-ts3.8/integrations/tracing/fastify/v3/enums/AttributeNames.d.ts +15 -0
  71. package/build/types-ts3.8/integrations/tracing/fastify/v3/instrumentation.d.ts +16 -0
  72. package/build/types-ts3.8/integrations/tracing/fastify/v3/internal-types.d.ts +7 -0
  73. package/build/types-ts3.8/integrations/tracing/fastify/v3/types.d.ts +21 -0
  74. package/build/types-ts3.8/integrations/tracing/fastify/v3/utils.d.ts +28 -0
  75. package/package.json +5 -5
  76. package/build/cjs/integrations/tracing/fastify.js +0 -160
  77. package/build/cjs/integrations/tracing/fastify.js.map +0 -1
  78. package/build/esm/integrations/tracing/fastify.js +0 -156
  79. package/build/esm/integrations/tracing/fastify.js.map +0 -1
  80. package/build/types/integrations/tracing/fastify.d.ts.map +0 -1
@@ -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"}
@@ -19,6 +19,14 @@ export type SentryHttpInstrumentationOptions = InstrumentationConfig & {
19
19
  * @default `false`
20
20
  */
21
21
  extractIncomingTraceFromHeader?: boolean;
22
+ /**
23
+ * Whether to propagate Sentry trace headers in outgoing requests.
24
+ * By default this is done by the HttpInstrumentation, but if that is not added (e.g. because tracing is disabled)
25
+ * then this instrumentation can take over.
26
+ *
27
+ * @default `false`
28
+ */
29
+ propagateTraceInOutgoingRequests?: boolean;
22
30
  /**
23
31
  * Do not capture breadcrumbs for outgoing HTTP requests to URLs where the given callback returns `true`.
24
32
  * For the scope of this instrumentation, this callback only controls breadcrumb creation.
@@ -65,6 +73,7 @@ export type SentryHttpInstrumentationOptions = InstrumentationConfig & {
65
73
  * https://github.com/open-telemetry/opentelemetry-js/blob/f8ab5592ddea5cba0a3b33bf8d74f27872c0367f/experimental/packages/opentelemetry-instrumentation-http/src/http.ts
66
74
  */
67
75
  export declare class SentryHttpInstrumentation extends InstrumentationBase<SentryHttpInstrumentationOptions> {
76
+ private _propagationDecisionMap;
68
77
  constructor(config?: SentryHttpInstrumentationOptions);
69
78
  /** @inheritdoc */
70
79
  init(): [
@@ -76,6 +85,11 @@ export declare class SentryHttpInstrumentation extends InstrumentationBase<Sentr
76
85
  * It has access to the final request and response objects.
77
86
  */
78
87
  private _onOutgoingRequestFinish;
88
+ /**
89
+ * This is triggered when an outgoing request is created.
90
+ * It has access to the request object, and can mutate it before the request is sent.
91
+ */
92
+ private _onOutgoingRequestCreated;
79
93
  /**
80
94
  * Patch a server.emit function to handle process isolation for incoming requests.
81
95
  * This will only patch the emit function if it was not already patched.
@@ -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