@@ -7,22 +7,38 @@ import { wrapRequestHandler } from './request';
7
7
*
8
8
* Initializes the SDK and wraps cloudflare pages requests with SDK instrumentation.
9
9
*
10
- * @example
10
+ * @example Simple usage
11
+ *
11
12
* ```javascript
12
13
* // functions/_middleware.js
13
14
* import * as Sentry from '@sentry/cloudflare';
14
15
*
15
16
* export const onRequest = Sentry.sentryPagesPlugin({
16
- * dsn: process.env.SENTRY_DSN,
17
- * tracesSampleRate: 1.0,
17
+ * dsn: process.env.SENTRY_DSN,
18
+ * tracesSampleRate: 1.0,
18
19
* });
19
20
* ```
21
+ *
22
+ * @example Usage with handler function to access context for environmental variables
23
+ *
24
+ * ```javascript
25
+ * import * as Sentry from '@sentry/cloudflare';
26
+ *
27
+ * const const onRequest = Sentry.sentryPagesPlugin((context) => ({
28
+ * dsn: context.env.SENTRY_DSN,
29
+ * tracesSampleRate: 1.0,
30
+ * })
31
+ * ```
32
+ *
33
+ * @param handlerOrOptions Configuration options or a function that returns configuration options.
34
+ * @returns A plugin function that can be used in Cloudflare Pages.
20
35
*/
21
36
export function sentryPagesPlugin <
22
37
Env = unknown ,
23
38
// eslint-disable-next-line @typescript-eslint/no-explicit-any
24
39
Params extends string = any ,
25
40
Data extends Record < string , unknown > = Record < string , unknown > ,
41
+ // Although it is not ideal to use `any` here, it makes usage more flexible for different setups.
26
42
// eslint-disable-next-line @typescript-eslint/no-explicit-any
27
43
PluginParams = any ,
28
44
> (
0 commit comments