@sentry/cloudflare 8.21.0 → 8.22.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/README.md +46 -7
- package/build/cjs/handler.js +4 -84
- package/build/cjs/handler.js.map +1 -1
- package/build/cjs/index.js +2 -0
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/pages-plugin.js +33 -0
- package/build/cjs/pages-plugin.js.map +1 -0
- package/build/cjs/request.js +108 -0
- package/build/cjs/request.js.map +1 -0
- package/build/cjs/sdk.js +8 -3
- package/build/cjs/sdk.js.map +1 -1
- package/build/esm/handler.js +3 -83
- package/build/esm/handler.js.map +1 -1
- package/build/esm/index.js +1 -0
- package/build/esm/index.js.map +1 -1
- package/build/esm/pages-plugin.js +31 -0
- package/build/esm/pages-plugin.js.map +1 -0
- package/build/esm/request.js +106 -0
- package/build/esm/request.js.map +1 -0
- package/build/esm/sdk.js +5 -3
- package/build/esm/sdk.js.map +1 -1
- package/build/types/handler.d.ts.map +1 -1
- package/build/types/index.d.ts +1 -0
- package/build/types/index.d.ts.map +1 -1
- package/build/types/pages-plugin.d.ts +23 -0
- package/build/types/pages-plugin.d.ts.map +1 -0
- package/build/types/request.d.ts +13 -0
- package/build/types/request.d.ts.map +1 -0
- package/build/types/sdk.d.ts +1 -1
- package/build/types/sdk.d.ts.map +1 -1
- package/build/types-ts3.8/index.d.ts +1 -0
- package/build/types-ts3.8/pages-plugin.d.ts +23 -0
- package/build/types-ts3.8/request.d.ts +13 -0
- package/build/types-ts3.8/sdk.d.ts +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
</a>
|
|
5
5
|
</p>
|
|
6
6
|
|
|
7
|
-
# Official Sentry SDK for Cloudflare
|
|
7
|
+
# Official Sentry SDK for Cloudflare
|
|
8
8
|
|
|
9
9
|
[](https://www.npmjs.com/package/@sentry/cloudflare)
|
|
10
10
|
[](https://www.npmjs.com/package/@sentry/cloudflare)
|
|
@@ -18,9 +18,7 @@
|
|
|
18
18
|
**Note: This SDK is unreleased. Please follow the
|
|
19
19
|
[tracking GH issue](https://github.com/getsentry/sentry-javascript/issues/12620) for updates.**
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
## Setup (Cloudflare Workers)
|
|
21
|
+
## Install
|
|
24
22
|
|
|
25
23
|
To get started, first install the `@sentry/cloudflare` package:
|
|
26
24
|
|
|
@@ -36,6 +34,46 @@ compatibility_flags = ["nodejs_compat"]
|
|
|
36
34
|
# compatibility_flags = ["nodejs_als"]
|
|
37
35
|
```
|
|
38
36
|
|
|
37
|
+
Then you can either setup up the SDK for [Cloudflare Pages](#setup-cloudflare-pages) or
|
|
38
|
+
[Cloudflare Workers](#setup-cloudflare-workers).
|
|
39
|
+
|
|
40
|
+
## Setup (Cloudflare Pages)
|
|
41
|
+
|
|
42
|
+
To use this SDK, add the `sentryPagesPlugin` as
|
|
43
|
+
[middleware to your Cloudflare Pages application](https://developers.cloudflare.com/pages/functions/middleware/).
|
|
44
|
+
|
|
45
|
+
We recommend adding a `functions/_middleware.js` for the middleware setup so that Sentry is initialized for your entire
|
|
46
|
+
app.
|
|
47
|
+
|
|
48
|
+
```javascript
|
|
49
|
+
// functions/_middleware.js
|
|
50
|
+
import * as Sentry from '@sentry/cloudflare';
|
|
51
|
+
|
|
52
|
+
export const onRequest = Sentry.sentryPagesPlugin({
|
|
53
|
+
dsn: process.env.SENTRY_DSN,
|
|
54
|
+
// Set tracesSampleRate to 1.0 to capture 100% of spans for tracing.
|
|
55
|
+
tracesSampleRate: 1.0,
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
If you need to to chain multiple middlewares, you can do so by exporting an array of middlewares. Make sure the Sentry
|
|
60
|
+
middleware is the first one in the array.
|
|
61
|
+
|
|
62
|
+
```javascript
|
|
63
|
+
import * as Sentry from '@sentry/cloudflare';
|
|
64
|
+
|
|
65
|
+
export const onRequest = [
|
|
66
|
+
// Make sure Sentry is the first middleware
|
|
67
|
+
Sentry.sentryPagesPlugin({
|
|
68
|
+
dsn: process.env.SENTRY_DSN,
|
|
69
|
+
tracesSampleRate: 1.0,
|
|
70
|
+
}),
|
|
71
|
+
// Add more middlewares here
|
|
72
|
+
];
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Setup (Cloudflare Workers)
|
|
76
|
+
|
|
39
77
|
To use this SDK, wrap your handler with the `withSentry` function. This will initialize the SDK and hook into the
|
|
40
78
|
environment. Note that you can turn off almost all side effects using the respective options.
|
|
41
79
|
|
|
@@ -58,7 +96,7 @@ export default withSentry(
|
|
|
58
96
|
);
|
|
59
97
|
```
|
|
60
98
|
|
|
61
|
-
### Sourcemaps
|
|
99
|
+
### Sourcemaps
|
|
62
100
|
|
|
63
101
|
Configure uploading sourcemaps via the Sentry Wizard:
|
|
64
102
|
|
|
@@ -68,10 +106,11 @@ npx @sentry/wizard@latest -i sourcemaps
|
|
|
68
106
|
|
|
69
107
|
See more details in our [docs](https://docs.sentry.io/platforms/javascript/sourcemaps/).
|
|
70
108
|
|
|
71
|
-
## Usage
|
|
109
|
+
## Usage
|
|
72
110
|
|
|
73
111
|
To set context information or send manual events, use the exported functions of `@sentry/cloudflare`. Note that these
|
|
74
|
-
functions will require
|
|
112
|
+
functions will require the usage of the Sentry helpers, either `withSentry` function for Cloudflare Workers or the
|
|
113
|
+
`sentryPagesPlugin` middleware for Cloudflare Pages.
|
|
75
114
|
|
|
76
115
|
```javascript
|
|
77
116
|
import * as Sentry from '@sentry/cloudflare';
|
package/build/cjs/handler.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
2
|
|
|
3
|
-
const core = require('@sentry/core');
|
|
4
|
-
const utils = require('@sentry/utils');
|
|
5
3
|
const async = require('./async.js');
|
|
6
|
-
const
|
|
4
|
+
const request = require('./request.js');
|
|
7
5
|
|
|
8
6
|
/**
|
|
9
7
|
* Extract environment generic from exported handler.
|
|
@@ -31,71 +29,9 @@ function withSentry(
|
|
|
31
29
|
if ('fetch' in handler && typeof handler.fetch === 'function' && !(handler.fetch ).__SENTRY_INSTRUMENTED__) {
|
|
32
30
|
handler.fetch = new Proxy(handler.fetch, {
|
|
33
31
|
apply(target, thisArg, args) {
|
|
34
|
-
const [request, env, context] = args;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const client = sdk.init(options);
|
|
38
|
-
isolationScope.setClient(client);
|
|
39
|
-
|
|
40
|
-
const attributes = {
|
|
41
|
-
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.cloudflare-worker',
|
|
42
|
-
[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',
|
|
43
|
-
[core.SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'http.server',
|
|
44
|
-
['http.request.method']: request.method,
|
|
45
|
-
['url.full']: request.url,
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const contentLength = request.headers.get('content-length');
|
|
49
|
-
if (contentLength) {
|
|
50
|
-
attributes['http.request.body.size'] = parseInt(contentLength, 10);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
let pathname = '';
|
|
54
|
-
try {
|
|
55
|
-
const url = new URL(request.url);
|
|
56
|
-
pathname = url.pathname;
|
|
57
|
-
attributes['server.address'] = url.hostname;
|
|
58
|
-
attributes['url.scheme'] = url.protocol.replace(':', '');
|
|
59
|
-
} catch (e2) {
|
|
60
|
-
// skip
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
addRequest(isolationScope, request);
|
|
64
|
-
addCloudResourceContext(isolationScope);
|
|
65
|
-
if (request.cf) {
|
|
66
|
-
addCultureContext(isolationScope, request.cf);
|
|
67
|
-
attributes['network.protocol.name'] = request.cf.httpProtocol;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const routeName = `${request.method} ${pathname ? utils.stripUrlQueryAndFragment(pathname) : '/'}`;
|
|
71
|
-
|
|
72
|
-
return core.continueTrace(
|
|
73
|
-
{ sentryTrace: request.headers.get('sentry-trace') || '', baggage: request.headers.get('baggage') },
|
|
74
|
-
() => {
|
|
75
|
-
// Note: This span will not have a duration unless I/O happens in the handler. This is
|
|
76
|
-
// because of how the cloudflare workers runtime works.
|
|
77
|
-
// See: https://developers.cloudflare.com/workers/runtime-apis/performance/
|
|
78
|
-
return core.startSpan(
|
|
79
|
-
{
|
|
80
|
-
name: routeName,
|
|
81
|
-
attributes,
|
|
82
|
-
},
|
|
83
|
-
async span => {
|
|
84
|
-
try {
|
|
85
|
-
const res = await (target.apply(thisArg, args) );
|
|
86
|
-
core.setHttpStatus(span, res.status);
|
|
87
|
-
return res;
|
|
88
|
-
} catch (e) {
|
|
89
|
-
core.captureException(e, { mechanism: { handled: false, type: 'cloudflare' } });
|
|
90
|
-
throw e;
|
|
91
|
-
} finally {
|
|
92
|
-
context.waitUntil(core.flush(2000));
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
);
|
|
96
|
-
},
|
|
97
|
-
);
|
|
98
|
-
});
|
|
32
|
+
const [request$1, env, context] = args;
|
|
33
|
+
const options = optionsCallback(env);
|
|
34
|
+
return request.wrapRequestHandler({ options, request: request$1, context }, () => target.apply(thisArg, args));
|
|
99
35
|
},
|
|
100
36
|
});
|
|
101
37
|
|
|
@@ -106,21 +42,5 @@ function withSentry(
|
|
|
106
42
|
return handler;
|
|
107
43
|
}
|
|
108
44
|
|
|
109
|
-
function addCloudResourceContext(isolationScope) {
|
|
110
|
-
isolationScope.setContext('cloud_resource', {
|
|
111
|
-
'cloud.provider': 'cloudflare',
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function addCultureContext(isolationScope, cf) {
|
|
116
|
-
isolationScope.setContext('culture', {
|
|
117
|
-
timezone: cf.timezone,
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function addRequest(isolationScope, request) {
|
|
122
|
-
isolationScope.setSDKProcessingMetadata({ request: utils.winterCGRequestToRequestData(request) });
|
|
123
|
-
}
|
|
124
|
-
|
|
125
45
|
exports.withSentry = withSentry;
|
|
126
46
|
//# sourceMappingURL=handler.js.map
|
package/build/cjs/handler.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.js","sources":["../../src/handler.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"handler.js","sources":["../../src/handler.ts"],"sourcesContent":["import type { ExportedHandler, ExportedHandlerFetchHandler } from '@cloudflare/workers-types';\nimport type { Options } from '@sentry/types';\nimport { setAsyncLocalStorageAsyncContextStrategy } from './async';\nimport { wrapRequestHandler } from './request';\n\n/**\n * Extract environment generic from exported handler.\n */\ntype ExtractEnv<P> = P extends ExportedHandler<infer Env> ? Env : never;\n\n/**\n * Wrapper for Cloudflare handlers.\n *\n * Initializes the SDK and wraps the handler with Sentry instrumentation.\n *\n * Automatically instruments the `fetch` method of the handler.\n *\n * @param optionsCallback Function that returns the options for the SDK initialization.\n * @param handler {ExportedHandler} The handler to wrap.\n * @returns The wrapped handler.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function withSentry<E extends ExportedHandler<any>>(\n optionsCallback: (env: ExtractEnv<E>) => Options,\n handler: E,\n): E {\n setAsyncLocalStorageAsyncContextStrategy();\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any\n if ('fetch' in handler && typeof handler.fetch === 'function' && !(handler.fetch as any).__SENTRY_INSTRUMENTED__) {\n handler.fetch = new Proxy(handler.fetch, {\n apply(target, thisArg, args: Parameters<ExportedHandlerFetchHandler<ExtractEnv<E>>>) {\n const [request, env, context] = args;\n const options = optionsCallback(env);\n return wrapRequestHandler({ options, request, context }, () => target.apply(thisArg, args));\n },\n });\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any\n (handler.fetch as any).__SENTRY_INSTRUMENTED__ = true;\n }\n\n return handler;\n}\n"],"names":["setAsyncLocalStorageAsyncContextStrategy","request","wrapRequestHandler"],"mappings":";;;;;AAKA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,UAAU;AAC1B,EAAE,eAAe;AACjB,EAAE,OAAO;AACT,EAAK;AACL,EAAEA,8CAAwC,EAAE,CAAA;AAC5C;AACA;AACA,EAAE,IAAI,OAAQ,IAAG,WAAW,OAAO,OAAO,CAAC,KAAA,KAAU,UAAW,IAAG,CAAC,CAAC,OAAO,CAAC,KAAM,GAAQ,uBAAuB,EAAE;AACpH,IAAI,OAAO,CAAC,KAAA,GAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE;AAC7C,MAAM,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAA0D;AAC3F,QAAQ,MAAM,CAACC,SAAO,EAAE,GAAG,EAAE,OAAO,CAAE,GAAE,IAAI,CAAA;AAC5C,QAAQ,MAAM,OAAQ,GAAE,eAAe,CAAC,GAAG,CAAC,CAAA;AAC5C,QAAQ,OAAOC,0BAAkB,CAAC,EAAE,OAAO,WAAED,SAAO,EAAE,OAAA,EAAS,EAAE,MAAM,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAA;AACnG,OAAO;AACP,KAAK,CAAC,CAAA;AACN;AACA;AACA,IAAI,CAAC,OAAO,CAAC,KAAA,GAAc,uBAAA,GAA0B,IAAI,CAAA;AACzD,GAAE;AACF;AACA,EAAE,OAAO,OAAO,CAAA;AAChB;;;;"}
|
package/build/cjs/index.js
CHANGED
|
@@ -2,6 +2,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
2
2
|
|
|
3
3
|
const core = require('@sentry/core');
|
|
4
4
|
const handler = require('./handler.js');
|
|
5
|
+
const pagesPlugin = require('./pages-plugin.js');
|
|
5
6
|
const client = require('./client.js');
|
|
6
7
|
const sdk = require('./sdk.js');
|
|
7
8
|
const fetch = require('./integrations/fetch.js');
|
|
@@ -70,6 +71,7 @@ exports.withMonitor = core.withMonitor;
|
|
|
70
71
|
exports.withScope = core.withScope;
|
|
71
72
|
exports.zodErrorsIntegration = core.zodErrorsIntegration;
|
|
72
73
|
exports.withSentry = handler.withSentry;
|
|
74
|
+
exports.sentryPagesPlugin = pagesPlugin.sentryPagesPlugin;
|
|
73
75
|
exports.CloudflareClient = client.CloudflareClient;
|
|
74
76
|
exports.getDefaultIntegrations = sdk.getDefaultIntegrations;
|
|
75
77
|
exports.fetchIntegration = fetch.fetchIntegration;
|
package/build/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
|
|
3
|
+
const async = require('./async.js');
|
|
4
|
+
const request = require('./request.js');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Plugin middleware for Cloudflare Pages.
|
|
8
|
+
*
|
|
9
|
+
* Initializes the SDK and wraps cloudflare pages requests with SDK instrumentation.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```javascript
|
|
13
|
+
* // functions/_middleware.js
|
|
14
|
+
* import * as Sentry from '@sentry/cloudflare';
|
|
15
|
+
*
|
|
16
|
+
* export const onRequest = Sentry.sentryPagesPlugin({
|
|
17
|
+
* dsn: process.env.SENTRY_DSN,
|
|
18
|
+
* tracesSampleRate: 1.0,
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @param _options
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
function sentryPagesPlugin
|
|
26
|
+
|
|
27
|
+
(options) {
|
|
28
|
+
async.setAsyncLocalStorageAsyncContextStrategy();
|
|
29
|
+
return context => request.wrapRequestHandler({ options, request: context.request, context }, () => context.next());
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
exports.sentryPagesPlugin = sentryPagesPlugin;
|
|
33
|
+
//# sourceMappingURL=pages-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pages-plugin.js","sources":["../../src/pages-plugin.ts"],"sourcesContent":["import { setAsyncLocalStorageAsyncContextStrategy } from './async';\nimport type { CloudflareOptions } from './client';\nimport { wrapRequestHandler } from './request';\n\n/**\n * Plugin middleware for Cloudflare Pages.\n *\n * Initializes the SDK and wraps cloudflare pages requests with SDK instrumentation.\n *\n * @example\n * ```javascript\n * // functions/_middleware.js\n * import * as Sentry from '@sentry/cloudflare';\n *\n * export const onRequest = Sentry.sentryPagesPlugin({\n * dsn: process.env.SENTRY_DSN,\n * tracesSampleRate: 1.0,\n * });\n * ```\n *\n * @param _options\n * @returns\n */\nexport function sentryPagesPlugin<\n Env = unknown,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n Params extends string = any,\n Data extends Record<string, unknown> = Record<string, unknown>,\n>(options: CloudflareOptions): PagesPluginFunction<Env, Params, Data, CloudflareOptions> {\n setAsyncLocalStorageAsyncContextStrategy();\n return context => wrapRequestHandler({ options, request: context.request, context }, () => context.next());\n}\n"],"names":["setAsyncLocalStorageAsyncContextStrategy","wrapRequestHandler"],"mappings":";;;;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,iBAAiB;;AAKjC,CAAE,OAAO,EAAgF;AACzF,EAAEA,8CAAwC,EAAE,CAAA;AAC5C,EAAE,OAAO,OAAQ,IAAGC,0BAAkB,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,OAAA,EAAS,EAAE,MAAM,OAAO,CAAC,IAAI,EAAE,CAAC,CAAA;AAC5G;;;;"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
|
|
3
|
+
const core = require('@sentry/core');
|
|
4
|
+
const utils = require('@sentry/utils');
|
|
5
|
+
const sdk = require('./sdk.js');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Wraps a cloudflare request handler in Sentry instrumentation
|
|
9
|
+
*/
|
|
10
|
+
function wrapRequestHandler(
|
|
11
|
+
wrapperOptions,
|
|
12
|
+
handler,
|
|
13
|
+
) {
|
|
14
|
+
return core.withIsolationScope(async isolationScope => {
|
|
15
|
+
const { options, request, context } = wrapperOptions;
|
|
16
|
+
const client = sdk.init(options);
|
|
17
|
+
isolationScope.setClient(client);
|
|
18
|
+
|
|
19
|
+
const attributes = {
|
|
20
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.cloudflare',
|
|
21
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',
|
|
22
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'http.server',
|
|
23
|
+
['http.request.method']: request.method,
|
|
24
|
+
['url.full']: request.url,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const contentLength = request.headers.get('content-length');
|
|
28
|
+
if (contentLength) {
|
|
29
|
+
attributes['http.request.body.size'] = parseInt(contentLength, 10);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let pathname = '';
|
|
33
|
+
try {
|
|
34
|
+
const url = new URL(request.url);
|
|
35
|
+
pathname = url.pathname;
|
|
36
|
+
attributes['server.address'] = url.hostname;
|
|
37
|
+
attributes['url.scheme'] = url.protocol.replace(':', '');
|
|
38
|
+
} catch (e2) {
|
|
39
|
+
// skip
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
addCloudResourceContext(isolationScope);
|
|
43
|
+
if (request) {
|
|
44
|
+
addRequest(isolationScope, request);
|
|
45
|
+
if (request.cf) {
|
|
46
|
+
addCultureContext(isolationScope, request.cf);
|
|
47
|
+
attributes['network.protocol.name'] = request.cf.httpProtocol;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const routeName = `${request.method} ${pathname ? utils.stripUrlQueryAndFragment(pathname) : '/'}`;
|
|
52
|
+
|
|
53
|
+
return core.continueTrace(
|
|
54
|
+
{ sentryTrace: request.headers.get('sentry-trace') || '', baggage: request.headers.get('baggage') },
|
|
55
|
+
() => {
|
|
56
|
+
// Note: This span will not have a duration unless I/O happens in the handler. This is
|
|
57
|
+
// because of how the cloudflare workers runtime works.
|
|
58
|
+
// See: https://developers.cloudflare.com/workers/runtime-apis/performance/
|
|
59
|
+
return core.startSpan(
|
|
60
|
+
{
|
|
61
|
+
name: routeName,
|
|
62
|
+
attributes,
|
|
63
|
+
},
|
|
64
|
+
async span => {
|
|
65
|
+
try {
|
|
66
|
+
const res = await handler();
|
|
67
|
+
core.setHttpStatus(span, res.status);
|
|
68
|
+
return res;
|
|
69
|
+
} catch (e) {
|
|
70
|
+
core.captureException(e, { mechanism: { handled: false, type: 'cloudflare' } });
|
|
71
|
+
throw e;
|
|
72
|
+
} finally {
|
|
73
|
+
context.waitUntil(core.flush(2000));
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
);
|
|
77
|
+
},
|
|
78
|
+
);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Set cloud resource context on scope.
|
|
84
|
+
*/
|
|
85
|
+
function addCloudResourceContext(scope) {
|
|
86
|
+
scope.setContext('cloud_resource', {
|
|
87
|
+
'cloud.provider': 'cloudflare',
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Set culture context on scope
|
|
93
|
+
*/
|
|
94
|
+
function addCultureContext(scope, cf) {
|
|
95
|
+
scope.setContext('culture', {
|
|
96
|
+
timezone: cf.timezone,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Set request data on scope
|
|
102
|
+
*/
|
|
103
|
+
function addRequest(scope, request) {
|
|
104
|
+
scope.setSDKProcessingMetadata({ request: utils.winterCGRequestToRequestData(request) });
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
exports.wrapRequestHandler = wrapRequestHandler;
|
|
108
|
+
//# sourceMappingURL=request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.js","sources":["../../src/request.ts"],"sourcesContent":["import type { ExecutionContext, IncomingRequestCfProperties } from '@cloudflare/workers-types';\n\nimport {\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n captureException,\n continueTrace,\n flush,\n setHttpStatus,\n startSpan,\n withIsolationScope,\n} from '@sentry/core';\nimport type { Scope, SpanAttributes } from '@sentry/types';\nimport { stripUrlQueryAndFragment, winterCGRequestToRequestData } from '@sentry/utils';\nimport type { CloudflareOptions } from './client';\nimport { init } from './sdk';\n\ninterface RequestHandlerWrapperOptions {\n options: CloudflareOptions;\n request: Request<unknown, IncomingRequestCfProperties<unknown>>;\n context: ExecutionContext;\n}\n\n/**\n * Wraps a cloudflare request handler in Sentry instrumentation\n */\nexport function wrapRequestHandler(\n wrapperOptions: RequestHandlerWrapperOptions,\n handler: (...args: unknown[]) => Response | Promise<Response>,\n): Promise<Response> {\n return withIsolationScope(async isolationScope => {\n const { options, request, context } = wrapperOptions;\n const client = init(options);\n isolationScope.setClient(client);\n\n const attributes: SpanAttributes = {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.cloudflare',\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'http.server',\n ['http.request.method']: request.method,\n ['url.full']: request.url,\n };\n\n const contentLength = request.headers.get('content-length');\n if (contentLength) {\n attributes['http.request.body.size'] = parseInt(contentLength, 10);\n }\n\n let pathname = '';\n try {\n const url = new URL(request.url);\n pathname = url.pathname;\n attributes['server.address'] = url.hostname;\n attributes['url.scheme'] = url.protocol.replace(':', '');\n } catch {\n // skip\n }\n\n addCloudResourceContext(isolationScope);\n if (request) {\n addRequest(isolationScope, request);\n if (request.cf) {\n addCultureContext(isolationScope, request.cf);\n attributes['network.protocol.name'] = request.cf.httpProtocol;\n }\n }\n\n const routeName = `${request.method} ${pathname ? stripUrlQueryAndFragment(pathname) : '/'}`;\n\n return continueTrace(\n { sentryTrace: request.headers.get('sentry-trace') || '', baggage: request.headers.get('baggage') },\n () => {\n // Note: This span will not have a duration unless I/O happens in the handler. This is\n // because of how the cloudflare workers runtime works.\n // See: https://developers.cloudflare.com/workers/runtime-apis/performance/\n return startSpan(\n {\n name: routeName,\n attributes,\n },\n async span => {\n try {\n const res = await handler();\n setHttpStatus(span, res.status);\n return res;\n } catch (e) {\n captureException(e, { mechanism: { handled: false, type: 'cloudflare' } });\n throw e;\n } finally {\n context.waitUntil(flush(2000));\n }\n },\n );\n },\n );\n });\n}\n\n/**\n * Set cloud resource context on scope.\n */\nfunction addCloudResourceContext(scope: Scope): void {\n scope.setContext('cloud_resource', {\n 'cloud.provider': 'cloudflare',\n });\n}\n\n/**\n * Set culture context on scope\n */\nfunction addCultureContext(scope: Scope, cf: IncomingRequestCfProperties): void {\n scope.setContext('culture', {\n timezone: cf.timezone,\n });\n}\n\n/**\n * Set request data on scope\n */\nfunction addRequest(scope: Scope, request: Request): void {\n scope.setSDKProcessingMetadata({ request: winterCGRequestToRequestData(request) });\n}\n"],"names":["withIsolationScope","init","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","SEMANTIC_ATTRIBUTE_SENTRY_SOURCE","SEMANTIC_ATTRIBUTE_SENTRY_OP","stripUrlQueryAndFragment","continueTrace","startSpan","setHttpStatus","captureException","flush","winterCGRequestToRequestData"],"mappings":";;;;;;AAwBA;AACA;AACA;AACO,SAAS,kBAAkB;AAClC,EAAE,cAAc;AAChB,EAAE,OAAO;AACT,EAAqB;AACrB,EAAE,OAAOA,uBAAkB,CAAC,MAAM,kBAAkB;AACpD,IAAI,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAA,EAAU,GAAE,cAAc,CAAA;AACxD,IAAI,MAAM,MAAO,GAAEC,QAAI,CAAC,OAAO,CAAC,CAAA;AAChC,IAAI,cAAc,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;AACpC;AACA,IAAI,MAAM,UAAU,GAAmB;AACvC,MAAM,CAACC,qCAAgC,GAAG,sBAAsB;AAChE,MAAM,CAACC,qCAAgC,GAAG,KAAK;AAC/C,MAAM,CAACC,iCAA4B,GAAG,aAAa;AACnD,MAAM,CAAC,qBAAqB,GAAG,OAAO,CAAC,MAAM;AAC7C,MAAM,CAAC,UAAU,GAAG,OAAO,CAAC,GAAG;AAC/B,KAAK,CAAA;AACL;AACA,IAAI,MAAM,aAAc,GAAE,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAA;AAC/D,IAAI,IAAI,aAAa,EAAE;AACvB,MAAM,UAAU,CAAC,wBAAwB,CAAE,GAAE,QAAQ,CAAC,aAAa,EAAE,EAAE,CAAC,CAAA;AACxE,KAAI;AACJ;AACA,IAAI,IAAI,QAAS,GAAE,EAAE,CAAA;AACrB,IAAI,IAAI;AACR,MAAM,MAAM,MAAM,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;AACtC,MAAM,QAAS,GAAE,GAAG,CAAC,QAAQ,CAAA;AAC7B,MAAM,UAAU,CAAC,gBAAgB,IAAI,GAAG,CAAC,QAAQ,CAAA;AACjD,MAAM,UAAU,CAAC,YAAY,CAAA,GAAI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AAA,KAAA,EAAA,IAAA,EAAA,YAAA,EAAA,EAAA,CAAA,CAAA;AACA,cAAA,MAAA,CAAA,CAAA;AACA,aAAA,SAAA;AACA,cAAA,OAAA,CAAA,SAAA,CAAAC,UAAA,CAAA,IAAA,CAAA,CAAA,CAAA;AACA,aAAA;AACA,WAAA;AACA,SAAA,CAAA;AACA,OAAA;AACA,KAAA,CAAA;AACA,GAAA,CAAA,CAAA;AACA,CAAA;AACA;AACA;AACA;AACA;AACA,SAAA,uBAAA,CAAA,KAAA,EAAA;AACA,EAAA,KAAA,CAAA,UAAA,CAAA,gBAAA,EAAA;AACA,IAAA,gBAAA,EAAA,YAAA;AACA,GAAA,CAAA,CAAA;AACA,CAAA;AACA;AACA;AACA;AACA;AACA,SAAA,iBAAA,CAAA,KAAA,EAAA,EAAA,EAAA;AACA,EAAA,KAAA,CAAA,UAAA,CAAA,SAAA,EAAA;AACA,IAAA,QAAA,EAAA,EAAA,CAAA,QAAA;AACA,GAAA,CAAA,CAAA;AACA,CAAA;AACA;AACA;AACA;AACA;AACA,SAAA,UAAA,CAAA,KAAA,EAAA,OAAA,EAAA;AACA,EAAA,KAAA,CAAA,wBAAA,CAAA,EAAA,OAAA,EAAAC,kCAAA,CAAA,OAAA,CAAA,EAAA,CAAA,CAAA;AACA;;;;"}
|
package/build/cjs/sdk.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
var {
|
|
2
|
+
_nullishCoalesce
|
|
3
|
+
} = require('@sentry/utils');
|
|
4
|
+
|
|
1
5
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
6
|
|
|
3
7
|
const core = require('@sentry/core');
|
|
@@ -8,14 +12,15 @@ const transport = require('./transport.js');
|
|
|
8
12
|
const stacktrace = require('./vendor/stacktrace.js');
|
|
9
13
|
|
|
10
14
|
/** Get the default integrations for the Cloudflare SDK. */
|
|
11
|
-
function getDefaultIntegrations(
|
|
15
|
+
function getDefaultIntegrations(options) {
|
|
16
|
+
const sendDefaultPii = _nullishCoalesce(options.sendDefaultPii, () => ( false));
|
|
12
17
|
return [
|
|
13
18
|
core.dedupeIntegration(),
|
|
14
19
|
core.inboundFiltersIntegration(),
|
|
15
20
|
core.functionToStringIntegration(),
|
|
16
21
|
core.linkedErrorsIntegration(),
|
|
17
22
|
fetch.fetchIntegration(),
|
|
18
|
-
core.requestDataIntegration(),
|
|
23
|
+
core.requestDataIntegration(sendDefaultPii ? undefined : { include: { cookies: false } }),
|
|
19
24
|
];
|
|
20
25
|
}
|
|
21
26
|
|
|
@@ -24,7 +29,7 @@ function getDefaultIntegrations(_options) {
|
|
|
24
29
|
*/
|
|
25
30
|
function init(options) {
|
|
26
31
|
if (options.defaultIntegrations === undefined) {
|
|
27
|
-
options.defaultIntegrations = getDefaultIntegrations();
|
|
32
|
+
options.defaultIntegrations = getDefaultIntegrations(options);
|
|
28
33
|
}
|
|
29
34
|
|
|
30
35
|
const clientOptions = {
|
package/build/cjs/sdk.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk.js","sources":["../../src/sdk.ts"],"sourcesContent":["import {\n dedupeIntegration,\n functionToStringIntegration,\n getIntegrationsToSetup,\n inboundFiltersIntegration,\n initAndBind,\n linkedErrorsIntegration,\n requestDataIntegration,\n} from '@sentry/core';\nimport type { Integration, Options } from '@sentry/types';\nimport { stackParserFromStackParserOptions } from '@sentry/utils';\nimport type { CloudflareClientOptions } from './client';\nimport { CloudflareClient } from './client';\n\nimport { fetchIntegration } from './integrations/fetch';\nimport { makeCloudflareTransport } from './transport';\nimport { defaultStackParser } from './vendor/stacktrace';\n\n/** Get the default integrations for the Cloudflare SDK. */\nexport function getDefaultIntegrations(
|
|
1
|
+
{"version":3,"file":"sdk.js","sources":["../../src/sdk.ts"],"sourcesContent":["import {\n dedupeIntegration,\n functionToStringIntegration,\n getIntegrationsToSetup,\n inboundFiltersIntegration,\n initAndBind,\n linkedErrorsIntegration,\n requestDataIntegration,\n} from '@sentry/core';\nimport type { Integration, Options } from '@sentry/types';\nimport { stackParserFromStackParserOptions } from '@sentry/utils';\nimport type { CloudflareClientOptions } from './client';\nimport { CloudflareClient } from './client';\n\nimport { fetchIntegration } from './integrations/fetch';\nimport { makeCloudflareTransport } from './transport';\nimport { defaultStackParser } from './vendor/stacktrace';\n\n/** Get the default integrations for the Cloudflare SDK. */\nexport function getDefaultIntegrations(options: Options): Integration[] {\n const sendDefaultPii = options.sendDefaultPii ?? false;\n return [\n dedupeIntegration(),\n inboundFiltersIntegration(),\n functionToStringIntegration(),\n linkedErrorsIntegration(),\n fetchIntegration(),\n requestDataIntegration(sendDefaultPii ? undefined : { include: { cookies: false } }),\n ];\n}\n\n/**\n * Initializes the cloudflare SDK.\n */\nexport function init(options: Options): CloudflareClient | undefined {\n if (options.defaultIntegrations === undefined) {\n options.defaultIntegrations = getDefaultIntegrations(options);\n }\n\n const clientOptions: CloudflareClientOptions = {\n ...options,\n stackParser: stackParserFromStackParserOptions(options.stackParser || defaultStackParser),\n integrations: getIntegrationsToSetup(options),\n transport: options.transport || makeCloudflareTransport,\n };\n\n return initAndBind(CloudflareClient, clientOptions) as CloudflareClient;\n}\n"],"names":["dedupeIntegration","inboundFiltersIntegration","functionToStringIntegration","linkedErrorsIntegration","fetchIntegration","requestDataIntegration","stackParserFromStackParserOptions","defaultStackParser","getIntegrationsToSetup","makeCloudflareTransport","initAndBind","CloudflareClient"],"mappings":";;;;;;;;;;;;;AAkBA,CAAA,CAAA,EAAA,CAAA,CAAA,EAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,EAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,EAAA,CAAA;AACO,CAAS,CAAA,CAAA,CAAA,CAAA,CA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ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, SEMANTIC_ATTRIBUTE_SENTRY_OP, continueTrace, startSpan, setHttpStatus, captureException, flush } from '@sentry/core';
|
|
2
|
-
import { stripUrlQueryAndFragment, winterCGRequestToRequestData } from '@sentry/utils';
|
|
3
1
|
import { setAsyncLocalStorageAsyncContextStrategy } from './async.js';
|
|
4
|
-
import {
|
|
2
|
+
import { wrapRequestHandler } from './request.js';
|
|
5
3
|
|
|
6
4
|
/**
|
|
7
5
|
* Extract environment generic from exported handler.
|
|
@@ -30,70 +28,8 @@ function withSentry(
|
|
|
30
28
|
handler.fetch = new Proxy(handler.fetch, {
|
|
31
29
|
apply(target, thisArg, args) {
|
|
32
30
|
const [request, env, context] = args;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const client = init(options);
|
|
36
|
-
isolationScope.setClient(client);
|
|
37
|
-
|
|
38
|
-
const attributes = {
|
|
39
|
-
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.cloudflare-worker',
|
|
40
|
-
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',
|
|
41
|
-
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'http.server',
|
|
42
|
-
['http.request.method']: request.method,
|
|
43
|
-
['url.full']: request.url,
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const contentLength = request.headers.get('content-length');
|
|
47
|
-
if (contentLength) {
|
|
48
|
-
attributes['http.request.body.size'] = parseInt(contentLength, 10);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
let pathname = '';
|
|
52
|
-
try {
|
|
53
|
-
const url = new URL(request.url);
|
|
54
|
-
pathname = url.pathname;
|
|
55
|
-
attributes['server.address'] = url.hostname;
|
|
56
|
-
attributes['url.scheme'] = url.protocol.replace(':', '');
|
|
57
|
-
} catch (e2) {
|
|
58
|
-
// skip
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
addRequest(isolationScope, request);
|
|
62
|
-
addCloudResourceContext(isolationScope);
|
|
63
|
-
if (request.cf) {
|
|
64
|
-
addCultureContext(isolationScope, request.cf);
|
|
65
|
-
attributes['network.protocol.name'] = request.cf.httpProtocol;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const routeName = `${request.method} ${pathname ? stripUrlQueryAndFragment(pathname) : '/'}`;
|
|
69
|
-
|
|
70
|
-
return continueTrace(
|
|
71
|
-
{ sentryTrace: request.headers.get('sentry-trace') || '', baggage: request.headers.get('baggage') },
|
|
72
|
-
() => {
|
|
73
|
-
// Note: This span will not have a duration unless I/O happens in the handler. This is
|
|
74
|
-
// because of how the cloudflare workers runtime works.
|
|
75
|
-
// See: https://developers.cloudflare.com/workers/runtime-apis/performance/
|
|
76
|
-
return startSpan(
|
|
77
|
-
{
|
|
78
|
-
name: routeName,
|
|
79
|
-
attributes,
|
|
80
|
-
},
|
|
81
|
-
async span => {
|
|
82
|
-
try {
|
|
83
|
-
const res = await (target.apply(thisArg, args) );
|
|
84
|
-
setHttpStatus(span, res.status);
|
|
85
|
-
return res;
|
|
86
|
-
} catch (e) {
|
|
87
|
-
captureException(e, { mechanism: { handled: false, type: 'cloudflare' } });
|
|
88
|
-
throw e;
|
|
89
|
-
} finally {
|
|
90
|
-
context.waitUntil(flush(2000));
|
|
91
|
-
}
|
|
92
|
-
},
|
|
93
|
-
);
|
|
94
|
-
},
|
|
95
|
-
);
|
|
96
|
-
});
|
|
31
|
+
const options = optionsCallback(env);
|
|
32
|
+
return wrapRequestHandler({ options, request, context }, () => target.apply(thisArg, args));
|
|
97
33
|
},
|
|
98
34
|
});
|
|
99
35
|
|
|
@@ -104,21 +40,5 @@ function withSentry(
|
|
|
104
40
|
return handler;
|
|
105
41
|
}
|
|
106
42
|
|
|
107
|
-
function addCloudResourceContext(isolationScope) {
|
|
108
|
-
isolationScope.setContext('cloud_resource', {
|
|
109
|
-
'cloud.provider': 'cloudflare',
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function addCultureContext(isolationScope, cf) {
|
|
114
|
-
isolationScope.setContext('culture', {
|
|
115
|
-
timezone: cf.timezone,
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function addRequest(isolationScope, request) {
|
|
120
|
-
isolationScope.setSDKProcessingMetadata({ request: winterCGRequestToRequestData(request) });
|
|
121
|
-
}
|
|
122
|
-
|
|
123
43
|
export { withSentry };
|
|
124
44
|
//# sourceMappingURL=handler.js.map
|
package/build/esm/handler.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.js","sources":["../../src/handler.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"handler.js","sources":["../../src/handler.ts"],"sourcesContent":["import type { ExportedHandler, ExportedHandlerFetchHandler } from '@cloudflare/workers-types';\nimport type { Options } from '@sentry/types';\nimport { setAsyncLocalStorageAsyncContextStrategy } from './async';\nimport { wrapRequestHandler } from './request';\n\n/**\n * Extract environment generic from exported handler.\n */\ntype ExtractEnv<P> = P extends ExportedHandler<infer Env> ? Env : never;\n\n/**\n * Wrapper for Cloudflare handlers.\n *\n * Initializes the SDK and wraps the handler with Sentry instrumentation.\n *\n * Automatically instruments the `fetch` method of the handler.\n *\n * @param optionsCallback Function that returns the options for the SDK initialization.\n * @param handler {ExportedHandler} The handler to wrap.\n * @returns The wrapped handler.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function withSentry<E extends ExportedHandler<any>>(\n optionsCallback: (env: ExtractEnv<E>) => Options,\n handler: E,\n): E {\n setAsyncLocalStorageAsyncContextStrategy();\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any\n if ('fetch' in handler && typeof handler.fetch === 'function' && !(handler.fetch as any).__SENTRY_INSTRUMENTED__) {\n handler.fetch = new Proxy(handler.fetch, {\n apply(target, thisArg, args: Parameters<ExportedHandlerFetchHandler<ExtractEnv<E>>>) {\n const [request, env, context] = args;\n const options = optionsCallback(env);\n return wrapRequestHandler({ options, request, context }, () => target.apply(thisArg, args));\n },\n });\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any\n (handler.fetch as any).__SENTRY_INSTRUMENTED__ = true;\n }\n\n return handler;\n}\n"],"names":[],"mappings":";;;AAKA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,UAAU;AAC1B,EAAE,eAAe;AACjB,EAAE,OAAO;AACT,EAAK;AACL,EAAE,wCAAwC,EAAE,CAAA;AAC5C;AACA;AACA,EAAE,IAAI,OAAQ,IAAG,WAAW,OAAO,OAAO,CAAC,KAAA,KAAU,UAAW,IAAG,CAAC,CAAC,OAAO,CAAC,KAAM,GAAQ,uBAAuB,EAAE;AACpH,IAAI,OAAO,CAAC,KAAA,GAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE;AAC7C,MAAM,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAA0D;AAC3F,QAAQ,MAAM,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAE,GAAE,IAAI,CAAA;AAC5C,QAAQ,MAAM,OAAQ,GAAE,eAAe,CAAC,GAAG,CAAC,CAAA;AAC5C,QAAQ,OAAO,kBAAkB,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,OAAA,EAAS,EAAE,MAAM,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAA;AACnG,OAAO;AACP,KAAK,CAAC,CAAA;AACN;AACA;AACA,IAAI,CAAC,OAAO,CAAC,KAAA,GAAc,uBAAA,GAA0B,IAAI,CAAA;AACzD,GAAE;AACF;AACA,EAAE,OAAO,OAAO,CAAA;AAChB;;;;"}
|
package/build/esm/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { SDK_VERSION, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, Scope, addBreadcrumb, addEventProcessor, addIntegration, captureCheckIn, captureConsoleIntegration, captureEvent, captureException, captureFeedback, captureMessage, close, continueTrace, createTransport, debugIntegration, dedupeIntegration, extraErrorDataIntegration, flush, functionToStringIntegration, getActiveSpan, getClient, getCurrentScope, getGlobalScope, getIsolationScope, getRootSpan, getSpanDescendants, getSpanStatusFromHttpCode, inboundFiltersIntegration, isInitialized, lastEventId, linkedErrorsIntegration, metrics, moduleMetadataIntegration, requestDataIntegration, rewriteFramesIntegration, setContext, setCurrentClient, setExtra, setExtras, setHttpStatus, setMeasurement, setTag, setTags, setUser, spanToBaggageHeader, spanToJSON, spanToTraceHeader, startInactiveSpan, startNewTrace, startSpan, startSpanManual, trpcMiddleware, withActiveSpan, withIsolationScope, withMonitor, withScope, zodErrorsIntegration } from '@sentry/core';
|
|
2
2
|
export { withSentry } from './handler.js';
|
|
3
|
+
export { sentryPagesPlugin } from './pages-plugin.js';
|
|
3
4
|
export { CloudflareClient } from './client.js';
|
|
4
5
|
export { getDefaultIntegrations } from './sdk.js';
|
|
5
6
|
export { fetchIntegration } from './integrations/fetch.js';
|
package/build/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { setAsyncLocalStorageAsyncContextStrategy } from './async.js';
|
|
2
|
+
import { wrapRequestHandler } from './request.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Plugin middleware for Cloudflare Pages.
|
|
6
|
+
*
|
|
7
|
+
* Initializes the SDK and wraps cloudflare pages requests with SDK instrumentation.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```javascript
|
|
11
|
+
* // functions/_middleware.js
|
|
12
|
+
* import * as Sentry from '@sentry/cloudflare';
|
|
13
|
+
*
|
|
14
|
+
* export const onRequest = Sentry.sentryPagesPlugin({
|
|
15
|
+
* dsn: process.env.SENTRY_DSN,
|
|
16
|
+
* tracesSampleRate: 1.0,
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @param _options
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
function sentryPagesPlugin
|
|
24
|
+
|
|
25
|
+
(options) {
|
|
26
|
+
setAsyncLocalStorageAsyncContextStrategy();
|
|
27
|
+
return context => wrapRequestHandler({ options, request: context.request, context }, () => context.next());
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { sentryPagesPlugin };
|
|
31
|
+
//# sourceMappingURL=pages-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pages-plugin.js","sources":["../../src/pages-plugin.ts"],"sourcesContent":["import { setAsyncLocalStorageAsyncContextStrategy } from './async';\nimport type { CloudflareOptions } from './client';\nimport { wrapRequestHandler } from './request';\n\n/**\n * Plugin middleware for Cloudflare Pages.\n *\n * Initializes the SDK and wraps cloudflare pages requests with SDK instrumentation.\n *\n * @example\n * ```javascript\n * // functions/_middleware.js\n * import * as Sentry from '@sentry/cloudflare';\n *\n * export const onRequest = Sentry.sentryPagesPlugin({\n * dsn: process.env.SENTRY_DSN,\n * tracesSampleRate: 1.0,\n * });\n * ```\n *\n * @param _options\n * @returns\n */\nexport function sentryPagesPlugin<\n Env = unknown,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n Params extends string = any,\n Data extends Record<string, unknown> = Record<string, unknown>,\n>(options: CloudflareOptions): PagesPluginFunction<Env, Params, Data, CloudflareOptions> {\n setAsyncLocalStorageAsyncContextStrategy();\n return context => wrapRequestHandler({ options, request: context.request, context }, () => context.next());\n}\n"],"names":[],"mappings":";;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,iBAAiB;;AAKjC,CAAE,OAAO,EAAgF;AACzF,EAAE,wCAAwC,EAAE,CAAA;AAC5C,EAAE,OAAO,OAAQ,IAAG,kBAAkB,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,OAAA,EAAS,EAAE,MAAM,OAAO,CAAC,IAAI,EAAE,CAAC,CAAA;AAC5G;;;;"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { withIsolationScope, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, SEMANTIC_ATTRIBUTE_SENTRY_OP, continueTrace, startSpan, setHttpStatus, captureException, flush } from '@sentry/core';
|
|
2
|
+
import { stripUrlQueryAndFragment, winterCGRequestToRequestData } from '@sentry/utils';
|
|
3
|
+
import { init } from './sdk.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Wraps a cloudflare request handler in Sentry instrumentation
|
|
7
|
+
*/
|
|
8
|
+
function wrapRequestHandler(
|
|
9
|
+
wrapperOptions,
|
|
10
|
+
handler,
|
|
11
|
+
) {
|
|
12
|
+
return withIsolationScope(async isolationScope => {
|
|
13
|
+
const { options, request, context } = wrapperOptions;
|
|
14
|
+
const client = init(options);
|
|
15
|
+
isolationScope.setClient(client);
|
|
16
|
+
|
|
17
|
+
const attributes = {
|
|
18
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.cloudflare',
|
|
19
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',
|
|
20
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'http.server',
|
|
21
|
+
['http.request.method']: request.method,
|
|
22
|
+
['url.full']: request.url,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const contentLength = request.headers.get('content-length');
|
|
26
|
+
if (contentLength) {
|
|
27
|
+
attributes['http.request.body.size'] = parseInt(contentLength, 10);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let pathname = '';
|
|
31
|
+
try {
|
|
32
|
+
const url = new URL(request.url);
|
|
33
|
+
pathname = url.pathname;
|
|
34
|
+
attributes['server.address'] = url.hostname;
|
|
35
|
+
attributes['url.scheme'] = url.protocol.replace(':', '');
|
|
36
|
+
} catch (e2) {
|
|
37
|
+
// skip
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
addCloudResourceContext(isolationScope);
|
|
41
|
+
if (request) {
|
|
42
|
+
addRequest(isolationScope, request);
|
|
43
|
+
if (request.cf) {
|
|
44
|
+
addCultureContext(isolationScope, request.cf);
|
|
45
|
+
attributes['network.protocol.name'] = request.cf.httpProtocol;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const routeName = `${request.method} ${pathname ? stripUrlQueryAndFragment(pathname) : '/'}`;
|
|
50
|
+
|
|
51
|
+
return continueTrace(
|
|
52
|
+
{ sentryTrace: request.headers.get('sentry-trace') || '', baggage: request.headers.get('baggage') },
|
|
53
|
+
() => {
|
|
54
|
+
// Note: This span will not have a duration unless I/O happens in the handler. This is
|
|
55
|
+
// because of how the cloudflare workers runtime works.
|
|
56
|
+
// See: https://developers.cloudflare.com/workers/runtime-apis/performance/
|
|
57
|
+
return startSpan(
|
|
58
|
+
{
|
|
59
|
+
name: routeName,
|
|
60
|
+
attributes,
|
|
61
|
+
},
|
|
62
|
+
async span => {
|
|
63
|
+
try {
|
|
64
|
+
const res = await handler();
|
|
65
|
+
setHttpStatus(span, res.status);
|
|
66
|
+
return res;
|
|
67
|
+
} catch (e) {
|
|
68
|
+
captureException(e, { mechanism: { handled: false, type: 'cloudflare' } });
|
|
69
|
+
throw e;
|
|
70
|
+
} finally {
|
|
71
|
+
context.waitUntil(flush(2000));
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
);
|
|
75
|
+
},
|
|
76
|
+
);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Set cloud resource context on scope.
|
|
82
|
+
*/
|
|
83
|
+
function addCloudResourceContext(scope) {
|
|
84
|
+
scope.setContext('cloud_resource', {
|
|
85
|
+
'cloud.provider': 'cloudflare',
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Set culture context on scope
|
|
91
|
+
*/
|
|
92
|
+
function addCultureContext(scope, cf) {
|
|
93
|
+
scope.setContext('culture', {
|
|
94
|
+
timezone: cf.timezone,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Set request data on scope
|
|
100
|
+
*/
|
|
101
|
+
function addRequest(scope, request) {
|
|
102
|
+
scope.setSDKProcessingMetadata({ request: winterCGRequestToRequestData(request) });
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export { wrapRequestHandler };
|
|
106
|
+
//# sourceMappingURL=request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.js","sources":["../../src/request.ts"],"sourcesContent":["import type { ExecutionContext, IncomingRequestCfProperties } from '@cloudflare/workers-types';\n\nimport {\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n captureException,\n continueTrace,\n flush,\n setHttpStatus,\n startSpan,\n withIsolationScope,\n} from '@sentry/core';\nimport type { Scope, SpanAttributes } from '@sentry/types';\nimport { stripUrlQueryAndFragment, winterCGRequestToRequestData } from '@sentry/utils';\nimport type { CloudflareOptions } from './client';\nimport { init } from './sdk';\n\ninterface RequestHandlerWrapperOptions {\n options: CloudflareOptions;\n request: Request<unknown, IncomingRequestCfProperties<unknown>>;\n context: ExecutionContext;\n}\n\n/**\n * Wraps a cloudflare request handler in Sentry instrumentation\n */\nexport function wrapRequestHandler(\n wrapperOptions: RequestHandlerWrapperOptions,\n handler: (...args: unknown[]) => Response | Promise<Response>,\n): Promise<Response> {\n return withIsolationScope(async isolationScope => {\n const { options, request, context } = wrapperOptions;\n const client = init(options);\n isolationScope.setClient(client);\n\n const attributes: SpanAttributes = {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.cloudflare',\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'http.server',\n ['http.request.method']: request.method,\n ['url.full']: request.url,\n };\n\n const contentLength = request.headers.get('content-length');\n if (contentLength) {\n attributes['http.request.body.size'] = parseInt(contentLength, 10);\n }\n\n let pathname = '';\n try {\n const url = new URL(request.url);\n pathname = url.pathname;\n attributes['server.address'] = url.hostname;\n attributes['url.scheme'] = url.protocol.replace(':', '');\n } catch {\n // skip\n }\n\n addCloudResourceContext(isolationScope);\n if (request) {\n addRequest(isolationScope, request);\n if (request.cf) {\n addCultureContext(isolationScope, request.cf);\n attributes['network.protocol.name'] = request.cf.httpProtocol;\n }\n }\n\n const routeName = `${request.method} ${pathname ? stripUrlQueryAndFragment(pathname) : '/'}`;\n\n return continueTrace(\n { sentryTrace: request.headers.get('sentry-trace') || '', baggage: request.headers.get('baggage') },\n () => {\n // Note: This span will not have a duration unless I/O happens in the handler. This is\n // because of how the cloudflare workers runtime works.\n // See: https://developers.cloudflare.com/workers/runtime-apis/performance/\n return startSpan(\n {\n name: routeName,\n attributes,\n },\n async span => {\n try {\n const res = await handler();\n setHttpStatus(span, res.status);\n return res;\n } catch (e) {\n captureException(e, { mechanism: { handled: false, type: 'cloudflare' } });\n throw e;\n } finally {\n context.waitUntil(flush(2000));\n }\n },\n );\n },\n );\n });\n}\n\n/**\n * Set cloud resource context on scope.\n */\nfunction addCloudResourceContext(scope: Scope): void {\n scope.setContext('cloud_resource', {\n 'cloud.provider': 'cloudflare',\n });\n}\n\n/**\n * Set culture context on scope\n */\nfunction addCultureContext(scope: Scope, cf: IncomingRequestCfProperties): void {\n scope.setContext('culture', {\n timezone: cf.timezone,\n });\n}\n\n/**\n * Set request data on scope\n */\nfunction addRequest(scope: Scope, request: Request): void {\n scope.setSDKProcessingMetadata({ request: winterCGRequestToRequestData(request) });\n}\n"],"names":[],"mappings":";;;;AAwBA;AACA;AACA;AACO,SAAS,kBAAkB;AAClC,EAAE,cAAc;AAChB,EAAE,OAAO;AACT,EAAqB;AACrB,EAAE,OAAO,kBAAkB,CAAC,MAAM,kBAAkB;AACpD,IAAI,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAA,EAAU,GAAE,cAAc,CAAA;AACxD,IAAI,MAAM,MAAO,GAAE,IAAI,CAAC,OAAO,CAAC,CAAA;AAChC,IAAI,cAAc,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;AACpC;AACA,IAAI,MAAM,UAAU,GAAmB;AACvC,MAAM,CAAC,gCAAgC,GAAG,sBAAsB;AAChE,MAAM,CAAC,gCAAgC,GAAG,KAAK;AAC/C,MAAM,CAAC,4BAA4B,GAAG,aAAa;AACnD,MAAM,CAAC,qBAAqB,GAAG,OAAO,CAAC,MAAM;AAC7C,MAAM,CAAC,UAAU,GAAG,OAAO,CAAC,GAAG;AAC/B,KAAK,CAAA;AACL;AACA,IAAI,MAAM,aAAc,GAAE,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAA;AAC/D,IAAI,IAAI,aAAa,EAAE;AACvB,MAAM,UAAU,CAAC,wBAAwB,CAAE,GAAE,QAAQ,CAAC,aAAa,EAAE,EAAE,CAAC,CAAA;AACxE,KAAI;AACJ;AACA,IAAI,IAAI,QAAS,GAAE,EAAE,CAAA;AACrB,IAAI,IAAI;AACR,MAAM,MAAM,MAAM,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;AACtC,MAAM,QAAS,GAA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AAA,OAAA,GAAA,CAAA;AACA,aAAA,CAAA,OAAA,CAAA,EAAA;AACA,cAAA,gBAAA,CAAA,CAAA,EAAA,EAAA,SAAA,EAAA,EAAA,OAAA,EAAA,KAAA,EAAA,IAAA,EAAA,YAAA,EAAA,EAAA,CAAA,CAAA;AACA,cAAA,MAAA,CAAA,CAAA;AACA,aAAA,SAAA;AACA,cAAA,OAAA,CAAA,SAAA,CAAA,KAAA,CAAA,IAAA,CAAA,CAAA,CAAA;AACA,aAAA;AACA,WAAA;AACA,SAAA,CAAA;AACA,OAAA;AACA,KAAA,CAAA;AACA,GAAA,CAAA,CAAA;AACA,CAAA;AACA;AACA;AACA;AACA;AACA,SAAA,uBAAA,CAAA,KAAA,EAAA;AACA,EAAA,KAAA,CAAA,UAAA,CAAA,gBAAA,EAAA;AACA,IAAA,gBAAA,EAAA,YAAA;AACA,GAAA,CAAA,CAAA;AACA,CAAA;AACA;AACA;AACA;AACA;AACA,SAAA,iBAAA,CAAA,KAAA,EAAA,EAAA,EAAA;AACA,EAAA,KAAA,CAAA,UAAA,CAAA,SAAA,EAAA;AACA,IAAA,QAAA,EAAA,EAAA,CAAA,QAAA;AACA,GAAA,CAAA,CAAA;AACA,CAAA;AACA;AACA;AACA;AACA;AACA,SAAA,UAAA,CAAA,KAAA,EAAA,OAAA,EAAA;AACA,EAAA,KAAA,CAAA,wBAAA,CAAA,EAAA,OAAA,EAAA,4BAAA,CAAA,OAAA,CAAA,EAAA,CAAA,CAAA;AACA;;;;"}
|
package/build/esm/sdk.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { _nullishCoalesce } from '@sentry/utils';
|
|
1
2
|
import { dedupeIntegration, inboundFiltersIntegration, functionToStringIntegration, linkedErrorsIntegration, requestDataIntegration, getIntegrationsToSetup, initAndBind } from '@sentry/core';
|
|
2
3
|
import { stackParserFromStackParserOptions } from '@sentry/utils';
|
|
3
4
|
import { CloudflareClient } from './client.js';
|
|
@@ -6,14 +7,15 @@ import { makeCloudflareTransport } from './transport.js';
|
|
|
6
7
|
import { defaultStackParser } from './vendor/stacktrace.js';
|
|
7
8
|
|
|
8
9
|
/** Get the default integrations for the Cloudflare SDK. */
|
|
9
|
-
function getDefaultIntegrations(
|
|
10
|
+
function getDefaultIntegrations(options) {
|
|
11
|
+
const sendDefaultPii = _nullishCoalesce(options.sendDefaultPii, () => ( false));
|
|
10
12
|
return [
|
|
11
13
|
dedupeIntegration(),
|
|
12
14
|
inboundFiltersIntegration(),
|
|
13
15
|
functionToStringIntegration(),
|
|
14
16
|
linkedErrorsIntegration(),
|
|
15
17
|
fetchIntegration(),
|
|
16
|
-
requestDataIntegration(),
|
|
18
|
+
requestDataIntegration(sendDefaultPii ? undefined : { include: { cookies: false } }),
|
|
17
19
|
];
|
|
18
20
|
}
|
|
19
21
|
|
|
@@ -22,7 +24,7 @@ function getDefaultIntegrations(_options) {
|
|
|
22
24
|
*/
|
|
23
25
|
function init(options) {
|
|
24
26
|
if (options.defaultIntegrations === undefined) {
|
|
25
|
-
options.defaultIntegrations = getDefaultIntegrations();
|
|
27
|
+
options.defaultIntegrations = getDefaultIntegrations(options);
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
const clientOptions = {
|
package/build/esm/sdk.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk.js","sources":["../../src/sdk.ts"],"sourcesContent":["import {\n dedupeIntegration,\n functionToStringIntegration,\n getIntegrationsToSetup,\n inboundFiltersIntegration,\n initAndBind,\n linkedErrorsIntegration,\n requestDataIntegration,\n} from '@sentry/core';\nimport type { Integration, Options } from '@sentry/types';\nimport { stackParserFromStackParserOptions } from '@sentry/utils';\nimport type { CloudflareClientOptions } from './client';\nimport { CloudflareClient } from './client';\n\nimport { fetchIntegration } from './integrations/fetch';\nimport { makeCloudflareTransport } from './transport';\nimport { defaultStackParser } from './vendor/stacktrace';\n\n/** Get the default integrations for the Cloudflare SDK. */\nexport function getDefaultIntegrations(
|
|
1
|
+
{"version":3,"file":"sdk.js","sources":["../../src/sdk.ts"],"sourcesContent":["import {\n dedupeIntegration,\n functionToStringIntegration,\n getIntegrationsToSetup,\n inboundFiltersIntegration,\n initAndBind,\n linkedErrorsIntegration,\n requestDataIntegration,\n} from '@sentry/core';\nimport type { Integration, Options } from '@sentry/types';\nimport { stackParserFromStackParserOptions } from '@sentry/utils';\nimport type { CloudflareClientOptions } from './client';\nimport { CloudflareClient } from './client';\n\nimport { fetchIntegration } from './integrations/fetch';\nimport { makeCloudflareTransport } from './transport';\nimport { defaultStackParser } from './vendor/stacktrace';\n\n/** Get the default integrations for the Cloudflare SDK. */\nexport function getDefaultIntegrations(options: Options): Integration[] {\n const sendDefaultPii = options.sendDefaultPii ?? false;\n return [\n dedupeIntegration(),\n inboundFiltersIntegration(),\n functionToStringIntegration(),\n linkedErrorsIntegration(),\n fetchIntegration(),\n requestDataIntegration(sendDefaultPii ? undefined : { include: { cookies: false } }),\n ];\n}\n\n/**\n * Initializes the cloudflare SDK.\n */\nexport function init(options: Options): CloudflareClient | undefined {\n if (options.defaultIntegrations === undefined) {\n options.defaultIntegrations = getDefaultIntegrations(options);\n }\n\n const clientOptions: CloudflareClientOptions = {\n ...options,\n stackParser: stackParserFromStackParserOptions(options.stackParser || defaultStackParser),\n integrations: getIntegrationsToSetup(options),\n transport: options.transport || makeCloudflareTransport,\n };\n\n return initAndBind(CloudflareClient, clientOptions) as CloudflareClient;\n}\n"],"names":[],"mappings":";;;;;;;;AAkBA,CAAA,CAAA,EAAA,CAAA,CAAA,EAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,EAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,EAAA,CAAA;AACO,C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A,CAAA,CAAA,CAAA,EAAe,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAkB,CAAC;IACzF,CAAY,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAE,CAAsB,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAC,OAAO,CAAC;IAC7C,SAAS,EAAE,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAO,CAAC,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,KAAa,CAAuB,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;EAC3D,CAAG;;EAED,OAAO,CAAW,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAC,gBAAgB,EAAE,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAa,EAAE;AACtD;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../src/handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../src/handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAA+B,MAAM,2BAA2B,CAAC;AAC9F,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAI7C;;GAEG;AACH,KAAK,UAAU,CAAC,CAAC,IAAI,CAAC,SAAS,eAAe,CAAC,MAAM,GAAG,CAAC,GAAG,GAAG,GAAG,KAAK,CAAC;AAExE;;;;;;;;;;GAUG;AAEH,wBAAgB,UAAU,CAAC,CAAC,SAAS,eAAe,CAAC,GAAG,CAAC,EACvD,eAAe,EAAE,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,OAAO,EAChD,OAAO,EAAE,CAAC,GACT,CAAC,CAkBH"}
|
package/build/types/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export type { AddRequestDataToEventOptions } from '@sentry/utils';
|
|
|
3
3
|
export type { CloudflareOptions } from './client';
|
|
4
4
|
export { addEventProcessor, addBreadcrumb, addIntegration, captureException, captureEvent, captureMessage, captureFeedback, close, createTransport, lastEventId, flush, getClient, isInitialized, getCurrentScope, getGlobalScope, getIsolationScope, setCurrentClient, Scope, SDK_VERSION, setContext, setExtra, setExtras, setTag, setTags, setUser, getSpanStatusFromHttpCode, setHttpStatus, withScope, withIsolationScope, captureCheckIn, withMonitor, setMeasurement, getActiveSpan, getRootSpan, startSpan, startInactiveSpan, startSpanManual, startNewTrace, withActiveSpan, getSpanDescendants, continueTrace, metrics, functionToStringIntegration, inboundFiltersIntegration, linkedErrorsIntegration, requestDataIntegration, extraErrorDataIntegration, debugIntegration, dedupeIntegration, rewriteFramesIntegration, captureConsoleIntegration, moduleMetadataIntegration, zodErrorsIntegration, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, trpcMiddleware, spanToJSON, spanToTraceHeader, spanToBaggageHeader, } from '@sentry/core';
|
|
5
5
|
export { withSentry } from './handler';
|
|
6
|
+
export { sentryPagesPlugin } from './pages-plugin';
|
|
6
7
|
export { CloudflareClient } from './client';
|
|
7
8
|
export { getDefaultIntegrations } from './sdk';
|
|
8
9
|
export { fetchIntegration } from './integrations/fetch';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,UAAU,EACV,cAAc,EACd,kBAAkB,EAClB,OAAO,EACP,OAAO,EACP,KAAK,EACL,SAAS,EACT,UAAU,EACV,SAAS,EACT,OAAO,EACP,aAAa,EACb,IAAI,EACJ,UAAU,EACV,UAAU,EACV,MAAM,EACN,IAAI,GACL,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,4BAA4B,EAAE,MAAM,eAAe,CAAC;AAElE,YAAY,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAElD,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,cAAc,EACd,eAAe,EACf,KAAK,EACL,eAAe,EACf,WAAW,EACX,KAAK,EACL,SAAS,EACT,aAAa,EACb,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,KAAK,EACL,WAAW,EACX,UAAU,EACV,QAAQ,EACR,SAAS,EACT,MAAM,EACN,OAAO,EACP,OAAO,EACP,yBAAyB,EACzB,aAAa,EACb,SAAS,EACT,kBAAkB,EAClB,cAAc,EACd,WAAW,EACX,cAAc,EACd,aAAa,EACb,WAAW,EACX,SAAS,EACT,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,cAAc,EACd,kBAAkB,EAClB,aAAa,EACb,OAAO,EACP,2BAA2B,EAC3B,yBAAyB,EACzB,uBAAuB,EACvB,sBAAsB,EACtB,yBAAyB,EACzB,gBAAgB,EAChB,iBAAiB,EACjB,wBAAwB,EACxB,yBAAyB,EACzB,yBAAyB,EACzB,oBAAoB,EACpB,4BAA4B,EAC5B,gCAAgC,EAChC,gCAAgC,EAChC,qCAAqC,EACrC,cAAc,EACd,UAAU,EACV,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,UAAU,EACV,cAAc,EACd,kBAAkB,EAClB,OAAO,EACP,OAAO,EACP,KAAK,EACL,SAAS,EACT,UAAU,EACV,SAAS,EACT,OAAO,EACP,aAAa,EACb,IAAI,EACJ,UAAU,EACV,UAAU,EACV,MAAM,EACN,IAAI,GACL,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,4BAA4B,EAAE,MAAM,eAAe,CAAC;AAElE,YAAY,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAElD,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,cAAc,EACd,eAAe,EACf,KAAK,EACL,eAAe,EACf,WAAW,EACX,KAAK,EACL,SAAS,EACT,aAAa,EACb,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,KAAK,EACL,WAAW,EACX,UAAU,EACV,QAAQ,EACR,SAAS,EACT,MAAM,EACN,OAAO,EACP,OAAO,EACP,yBAAyB,EACzB,aAAa,EACb,SAAS,EACT,kBAAkB,EAClB,cAAc,EACd,WAAW,EACX,cAAc,EACd,aAAa,EACb,WAAW,EACX,SAAS,EACT,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,cAAc,EACd,kBAAkB,EAClB,aAAa,EACb,OAAO,EACP,2BAA2B,EAC3B,yBAAyB,EACzB,uBAAuB,EACvB,sBAAsB,EACtB,yBAAyB,EACzB,gBAAgB,EAChB,iBAAiB,EACjB,wBAAwB,EACxB,yBAAyB,EACzB,yBAAyB,EACzB,oBAAoB,EACpB,4BAA4B,EAC5B,gCAAgC,EAChC,gCAAgC,EAChC,qCAAqC,EACrC,cAAc,EACd,UAAU,EACV,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,sBAAsB,EAAE,MAAM,OAAO,CAAC;AAE/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/// <reference types="@cloudflare/workers-types" />
|
|
2
|
+
import type { CloudflareOptions } from './client';
|
|
3
|
+
/**
|
|
4
|
+
* Plugin middleware for Cloudflare Pages.
|
|
5
|
+
*
|
|
6
|
+
* Initializes the SDK and wraps cloudflare pages requests with SDK instrumentation.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```javascript
|
|
10
|
+
* // functions/_middleware.js
|
|
11
|
+
* import * as Sentry from '@sentry/cloudflare';
|
|
12
|
+
*
|
|
13
|
+
* export const onRequest = Sentry.sentryPagesPlugin({
|
|
14
|
+
* dsn: process.env.SENTRY_DSN,
|
|
15
|
+
* tracesSampleRate: 1.0,
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @param _options
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
export declare function sentryPagesPlugin<Env = unknown, Params extends string = any, Data extends Record<string, unknown> = Record<string, unknown>>(options: CloudflareOptions): PagesPluginFunction<Env, Params, Data, CloudflareOptions>;
|
|
23
|
+
//# sourceMappingURL=pages-plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pages-plugin.d.ts","sourceRoot":"","sources":["../../src/pages-plugin.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAGlD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,iBAAiB,CAC/B,GAAG,GAAG,OAAO,EAEb,MAAM,SAAS,MAAM,GAAG,GAAG,EAC3B,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9D,OAAO,EAAE,iBAAiB,GAAG,mBAAmB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,iBAAiB,CAAC,CAGvF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ExecutionContext, IncomingRequestCfProperties } from '@cloudflare/workers-types';
|
|
2
|
+
import type { CloudflareOptions } from './client';
|
|
3
|
+
interface RequestHandlerWrapperOptions {
|
|
4
|
+
options: CloudflareOptions;
|
|
5
|
+
request: Request<unknown, IncomingRequestCfProperties<unknown>>;
|
|
6
|
+
context: ExecutionContext;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Wraps a cloudflare request handler in Sentry instrumentation
|
|
10
|
+
*/
|
|
11
|
+
export declare function wrapRequestHandler(wrapperOptions: RequestHandlerWrapperOptions, handler: (...args: unknown[]) => Response | Promise<Response>): Promise<Response>;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=request.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,2BAA2B,EAAE,MAAM,2BAA2B,CAAC;AAe/F,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAGlD,UAAU,4BAA4B;IACpC,OAAO,EAAE,iBAAiB,CAAC;IAC3B,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,2BAA2B,CAAC,OAAO,CAAC,CAAC,CAAC;IAChE,OAAO,EAAE,gBAAgB,CAAC;CAC3B;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,cAAc,EAAE,4BAA4B,EAC5C,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,GAC5D,OAAO,CAAC,QAAQ,CAAC,CAmEnB"}
|
package/build/types/sdk.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Integration, Options } from '@sentry/types';
|
|
2
2
|
import { CloudflareClient } from './client';
|
|
3
3
|
/** Get the default integrations for the Cloudflare SDK. */
|
|
4
|
-
export declare function getDefaultIntegrations(
|
|
4
|
+
export declare function getDefaultIntegrations(options: Options): Integration[];
|
|
5
5
|
/**
|
|
6
6
|
* Initializes the cloudflare SDK.
|
|
7
7
|
*/
|
package/build/types/sdk.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../../src/sdk.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAG1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAM5C,2DAA2D;AAC3D,wBAAgB,sBAAsB,CAAC,
|
|
1
|
+
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../../src/sdk.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAG1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAM5C,2DAA2D;AAC3D,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,GAAG,WAAW,EAAE,CAUtE;AAED;;GAEG;AACH,wBAAgB,IAAI,CAAC,OAAO,EAAE,OAAO,GAAG,gBAAgB,GAAG,SAAS,CAanE"}
|
|
@@ -3,6 +3,7 @@ export { AddRequestDataToEventOptions } from '@sentry/utils';
|
|
|
3
3
|
export { CloudflareOptions } from './client';
|
|
4
4
|
export { addEventProcessor, addBreadcrumb, addIntegration, captureException, captureEvent, captureMessage, captureFeedback, close, createTransport, lastEventId, flush, getClient, isInitialized, getCurrentScope, getGlobalScope, getIsolationScope, setCurrentClient, Scope, SDK_VERSION, setContext, setExtra, setExtras, setTag, setTags, setUser, getSpanStatusFromHttpCode, setHttpStatus, withScope, withIsolationScope, captureCheckIn, withMonitor, setMeasurement, getActiveSpan, getRootSpan, startSpan, startInactiveSpan, startSpanManual, startNewTrace, withActiveSpan, getSpanDescendants, continueTrace, metrics, functionToStringIntegration, inboundFiltersIntegration, linkedErrorsIntegration, requestDataIntegration, extraErrorDataIntegration, debugIntegration, dedupeIntegration, rewriteFramesIntegration, captureConsoleIntegration, moduleMetadataIntegration, zodErrorsIntegration, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, trpcMiddleware, spanToJSON, spanToTraceHeader, spanToBaggageHeader, } from '@sentry/core';
|
|
5
5
|
export { withSentry } from './handler';
|
|
6
|
+
export { sentryPagesPlugin } from './pages-plugin';
|
|
6
7
|
export { CloudflareClient } from './client';
|
|
7
8
|
export { getDefaultIntegrations } from './sdk';
|
|
8
9
|
export { fetchIntegration } from './integrations/fetch';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/// <reference types="@cloudflare/workers-types" />
|
|
2
|
+
import { CloudflareOptions } from './client';
|
|
3
|
+
/**
|
|
4
|
+
* Plugin middleware for Cloudflare Pages.
|
|
5
|
+
*
|
|
6
|
+
* Initializes the SDK and wraps cloudflare pages requests with SDK instrumentation.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```javascript
|
|
10
|
+
* // functions/_middleware.js
|
|
11
|
+
* import * as Sentry from '@sentry/cloudflare';
|
|
12
|
+
*
|
|
13
|
+
* export const onRequest = Sentry.sentryPagesPlugin({
|
|
14
|
+
* dsn: process.env.SENTRY_DSN,
|
|
15
|
+
* tracesSampleRate: 1.0,
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @param _options
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
export declare function sentryPagesPlugin<Env = unknown, Params extends string = any, Data extends Record<string, unknown> = Record<string, unknown>>(options: CloudflareOptions): PagesPluginFunction<Env, Params, Data, CloudflareOptions>;
|
|
23
|
+
//# sourceMappingURL=pages-plugin.d.ts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ExecutionContext, IncomingRequestCfProperties } from '@cloudflare/workers-types';
|
|
2
|
+
import { CloudflareOptions } from './client';
|
|
3
|
+
interface RequestHandlerWrapperOptions {
|
|
4
|
+
options: CloudflareOptions;
|
|
5
|
+
request: Request<unknown, IncomingRequestCfProperties<unknown>>;
|
|
6
|
+
context: ExecutionContext;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Wraps a cloudflare request handler in Sentry instrumentation
|
|
10
|
+
*/
|
|
11
|
+
export declare function wrapRequestHandler(wrapperOptions: RequestHandlerWrapperOptions, handler: (...args: unknown[]) => Response | Promise<Response>): Promise<Response>;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=request.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Integration, Options } from '@sentry/types';
|
|
2
2
|
import { CloudflareClient } from './client';
|
|
3
3
|
/** Get the default integrations for the Cloudflare SDK. */
|
|
4
|
-
export declare function getDefaultIntegrations(
|
|
4
|
+
export declare function getDefaultIntegrations(options: Options): Integration[];
|
|
5
5
|
/**
|
|
6
6
|
* Initializes the cloudflare SDK.
|
|
7
7
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentry/cloudflare",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.22.0",
|
|
4
4
|
"description": "Offical Sentry SDK for Cloudflare Workers and Pages",
|
|
5
5
|
"repository": "git://github.com/getsentry/sentry-javascript.git",
|
|
6
6
|
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/cloudflare",
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
"access": "public"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@sentry/core": "8.
|
|
43
|
-
"@sentry/types": "8.
|
|
44
|
-
"@sentry/utils": "8.
|
|
42
|
+
"@sentry/core": "8.22.0",
|
|
43
|
+
"@sentry/types": "8.22.0",
|
|
44
|
+
"@sentry/utils": "8.22.0"
|
|
45
45
|
},
|
|
46
46
|
"optionalDependencies": {
|
|
47
47
|
"@cloudflare/workers-types": "^4.x"
|