@sentry/cloudflare 8.21.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/LICENSE +21 -0
- package/README.md +99 -0
- package/build/cjs/async.js +73 -0
- package/build/cjs/async.js.map +1 -0
- package/build/cjs/client.js +35 -0
- package/build/cjs/client.js.map +1 -0
- package/build/cjs/handler.js +126 -0
- package/build/cjs/handler.js.map +1 -0
- package/build/cjs/index.js +76 -0
- package/build/cjs/index.js.map +1 -0
- package/build/cjs/integrations/fetch.js +139 -0
- package/build/cjs/integrations/fetch.js.map +1 -0
- package/build/cjs/sdk.js +42 -0
- package/build/cjs/sdk.js.map +1 -0
- package/build/cjs/transport.js +97 -0
- package/build/cjs/transport.js.map +1 -0
- package/build/cjs/vendor/stacktrace.js +49 -0
- package/build/cjs/vendor/stacktrace.js.map +1 -0
- package/build/esm/async.js +71 -0
- package/build/esm/async.js.map +1 -0
- package/build/esm/client.js +33 -0
- package/build/esm/client.js.map +1 -0
- package/build/esm/handler.js +124 -0
- package/build/esm/handler.js.map +1 -0
- package/build/esm/index.js +6 -0
- package/build/esm/index.js.map +1 -0
- package/build/esm/integrations/fetch.js +137 -0
- package/build/esm/integrations/fetch.js.map +1 -0
- package/build/esm/package.json +1 -0
- package/build/esm/sdk.js +39 -0
- package/build/esm/sdk.js.map +1 -0
- package/build/esm/transport.js +94 -0
- package/build/esm/transport.js.map +1 -0
- package/build/esm/vendor/stacktrace.js +46 -0
- package/build/esm/vendor/stacktrace.js.map +1 -0
- package/build/types/async.d.ts +8 -0
- package/build/types/async.d.ts.map +1 -0
- package/build/types/client.d.ts +34 -0
- package/build/types/client.d.ts.map +1 -0
- package/build/types/debug-build.d.ts +7 -0
- package/build/types/debug-build.d.ts.map +1 -0
- package/build/types/handler.d.ts +20 -0
- package/build/types/handler.d.ts.map +1 -0
- package/build/types/index.d.ts +9 -0
- package/build/types/index.d.ts.map +1 -0
- package/build/types/integrations/fetch.d.ts +17 -0
- package/build/types/integrations/fetch.d.ts.map +1 -0
- package/build/types/sdk.d.ts +9 -0
- package/build/types/sdk.d.ts.map +1 -0
- package/build/types/transport.d.ts +37 -0
- package/build/types/transport.d.ts.map +1 -0
- package/build/types/vendor/stacktrace.d.ts +11 -0
- package/build/types/vendor/stacktrace.d.ts.map +1 -0
- package/build/types-ts3.8/async.d.ts +8 -0
- package/build/types-ts3.8/client.d.ts +34 -0
- package/build/types-ts3.8/debug-build.d.ts +7 -0
- package/build/types-ts3.8/handler.d.ts +20 -0
- package/build/types-ts3.8/index.d.ts +9 -0
- package/build/types-ts3.8/integrations/fetch.d.ts +17 -0
- package/build/types-ts3.8/sdk.d.ts +9 -0
- package/build/types-ts3.8/transport.d.ts +37 -0
- package/build/types-ts3.8/vendor/stacktrace.d.ts +11 -0
- package/package.json +80 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Functional Software, Inc. dba Sentry
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
9
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
10
|
+
so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://sentry.io/?utm_source=github&utm_medium=logo" target="_blank">
|
|
3
|
+
<img src="https://sentry-brand.storage.googleapis.com/sentry-wordmark-dark-280x84.png" alt="Sentry" width="280" height="84">
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
# Official Sentry SDK for Cloudflare [UNRELEASED]
|
|
8
|
+
|
|
9
|
+
[](https://www.npmjs.com/package/@sentry/cloudflare)
|
|
10
|
+
[](https://www.npmjs.com/package/@sentry/cloudflare)
|
|
11
|
+
[](https://www.npmjs.com/package/@sentry/cloudflare)
|
|
12
|
+
|
|
13
|
+
## Links
|
|
14
|
+
|
|
15
|
+
- [Official SDK Docs](https://docs.sentry.io/quickstart/)
|
|
16
|
+
- [TypeDoc](http://getsentry.github.io/sentry-javascript/)
|
|
17
|
+
|
|
18
|
+
**Note: This SDK is unreleased. Please follow the
|
|
19
|
+
[tracking GH issue](https://github.com/getsentry/sentry-javascript/issues/12620) for updates.**
|
|
20
|
+
|
|
21
|
+
Below details the setup for the Cloudflare Workers. Cloudflare Pages support is in active development.
|
|
22
|
+
|
|
23
|
+
## Setup (Cloudflare Workers)
|
|
24
|
+
|
|
25
|
+
To get started, first install the `@sentry/cloudflare` package:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm install @sentry/cloudflare
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Then set either the `nodejs_compat` or `nodejs_als` compatibility flags in your `wrangler.toml`. This is because the SDK
|
|
32
|
+
needs access to the `AsyncLocalStorage` API to work correctly.
|
|
33
|
+
|
|
34
|
+
```toml
|
|
35
|
+
compatibility_flags = ["nodejs_compat"]
|
|
36
|
+
# compatibility_flags = ["nodejs_als"]
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
To use this SDK, wrap your handler with the `withSentry` function. This will initialize the SDK and hook into the
|
|
40
|
+
environment. Note that you can turn off almost all side effects using the respective options.
|
|
41
|
+
|
|
42
|
+
Currently only ESM handlers are supported.
|
|
43
|
+
|
|
44
|
+
```javascript
|
|
45
|
+
import * as Sentry from '@sentry/cloudflare';
|
|
46
|
+
|
|
47
|
+
export default withSentry(
|
|
48
|
+
(env) => ({
|
|
49
|
+
dsn: env.SENTRY_DSN,
|
|
50
|
+
// Set tracesSampleRate to 1.0 to capture 100% of spans for tracing.
|
|
51
|
+
tracesSampleRate: 1.0,
|
|
52
|
+
}),
|
|
53
|
+
{
|
|
54
|
+
async fetch(request, env, ctx) {
|
|
55
|
+
return new Response('Hello World!');
|
|
56
|
+
},
|
|
57
|
+
} satisfies ExportedHandler<Env>
|
|
58
|
+
);
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Sourcemaps (Cloudflare Workers)
|
|
62
|
+
|
|
63
|
+
Configure uploading sourcemaps via the Sentry Wizard:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
npx @sentry/wizard@latest -i sourcemaps
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
See more details in our [docs](https://docs.sentry.io/platforms/javascript/sourcemaps/).
|
|
70
|
+
|
|
71
|
+
## Usage (Cloudflare Workers)
|
|
72
|
+
|
|
73
|
+
To set context information or send manual events, use the exported functions of `@sentry/cloudflare`. Note that these
|
|
74
|
+
functions will require your exported handler to be wrapped in `withSentry`.
|
|
75
|
+
|
|
76
|
+
```javascript
|
|
77
|
+
import * as Sentry from '@sentry/cloudflare';
|
|
78
|
+
|
|
79
|
+
// Set user information, as well as tags and further extras
|
|
80
|
+
Sentry.setExtra('battery', 0.7);
|
|
81
|
+
Sentry.setTag('user_mode', 'admin');
|
|
82
|
+
Sentry.setUser({ id: '4711' });
|
|
83
|
+
|
|
84
|
+
// Add a breadcrumb for future events
|
|
85
|
+
Sentry.addBreadcrumb({
|
|
86
|
+
message: 'My Breadcrumb',
|
|
87
|
+
// ...
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// Capture exceptions, messages or manual events
|
|
91
|
+
Sentry.captureMessage('Hello, world!');
|
|
92
|
+
Sentry.captureException(new Error('Good bye'));
|
|
93
|
+
Sentry.captureEvent({
|
|
94
|
+
message: 'Manual',
|
|
95
|
+
stacktrace: [
|
|
96
|
+
// ...
|
|
97
|
+
],
|
|
98
|
+
});
|
|
99
|
+
```
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
|
|
3
|
+
const core = require('@sentry/core');
|
|
4
|
+
const node_async_hooks = require('node:async_hooks');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Sets the async context strategy to use AsyncLocalStorage.
|
|
8
|
+
*
|
|
9
|
+
* AsyncLocalStorage is only avalaible in the cloudflare workers runtime if you set
|
|
10
|
+
* compatibility_flags = ["nodejs_compat"] or compatibility_flags = ["nodejs_als"]
|
|
11
|
+
*/
|
|
12
|
+
function setAsyncLocalStorageAsyncContextStrategy() {
|
|
13
|
+
const asyncStorage = new node_async_hooks.AsyncLocalStorage
|
|
14
|
+
|
|
15
|
+
();
|
|
16
|
+
|
|
17
|
+
function getScopes() {
|
|
18
|
+
const scopes = asyncStorage.getStore();
|
|
19
|
+
|
|
20
|
+
if (scopes) {
|
|
21
|
+
return scopes;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// fallback behavior:
|
|
25
|
+
// if, for whatever reason, we can't find scopes on the context here, we have to fix this somehow
|
|
26
|
+
return {
|
|
27
|
+
scope: core.getDefaultCurrentScope(),
|
|
28
|
+
isolationScope: core.getDefaultIsolationScope(),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function withScope(callback) {
|
|
33
|
+
const scope = getScopes().scope.clone();
|
|
34
|
+
const isolationScope = getScopes().isolationScope;
|
|
35
|
+
return asyncStorage.run({ scope, isolationScope }, () => {
|
|
36
|
+
return callback(scope);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function withSetScope(scope, callback) {
|
|
41
|
+
const isolationScope = getScopes().isolationScope.clone();
|
|
42
|
+
return asyncStorage.run({ scope, isolationScope }, () => {
|
|
43
|
+
return callback(scope);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function withIsolationScope(callback) {
|
|
48
|
+
const scope = getScopes().scope;
|
|
49
|
+
const isolationScope = getScopes().isolationScope.clone();
|
|
50
|
+
return asyncStorage.run({ scope, isolationScope }, () => {
|
|
51
|
+
return callback(isolationScope);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function withSetIsolationScope(isolationScope, callback) {
|
|
56
|
+
const scope = getScopes().scope;
|
|
57
|
+
return asyncStorage.run({ scope, isolationScope }, () => {
|
|
58
|
+
return callback(isolationScope);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
core.setAsyncContextStrategy({
|
|
63
|
+
withScope,
|
|
64
|
+
withSetScope,
|
|
65
|
+
withIsolationScope,
|
|
66
|
+
withSetIsolationScope,
|
|
67
|
+
getCurrentScope: () => getScopes().scope,
|
|
68
|
+
getIsolationScope: () => getScopes().isolationScope,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
exports.setAsyncLocalStorageAsyncContextStrategy = setAsyncLocalStorageAsyncContextStrategy;
|
|
73
|
+
//# sourceMappingURL=async.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async.js","sources":["../../src/async.ts"],"sourcesContent":["import { getDefaultCurrentScope, getDefaultIsolationScope, setAsyncContextStrategy } from '@sentry/core';\nimport type { Scope } from '@sentry/types';\n\n// Need to use node: prefix for cloudflare workers compatibility\n// Note: Because we are using node:async_hooks, we need to set `node_compat` in the wrangler.toml\nimport { AsyncLocalStorage } from 'node:async_hooks';\n\n/**\n * Sets the async context strategy to use AsyncLocalStorage.\n *\n * AsyncLocalStorage is only avalaible in the cloudflare workers runtime if you set\n * compatibility_flags = [\"nodejs_compat\"] or compatibility_flags = [\"nodejs_als\"]\n */\nexport function setAsyncLocalStorageAsyncContextStrategy(): void {\n const asyncStorage = new AsyncLocalStorage<{\n scope: Scope;\n isolationScope: Scope;\n }>();\n\n function getScopes(): { scope: Scope; isolationScope: Scope } {\n const scopes = asyncStorage.getStore();\n\n if (scopes) {\n return scopes;\n }\n\n // fallback behavior:\n // if, for whatever reason, we can't find scopes on the context here, we have to fix this somehow\n return {\n scope: getDefaultCurrentScope(),\n isolationScope: getDefaultIsolationScope(),\n };\n }\n\n function withScope<T>(callback: (scope: Scope) => T): T {\n const scope = getScopes().scope.clone();\n const isolationScope = getScopes().isolationScope;\n return asyncStorage.run({ scope, isolationScope }, () => {\n return callback(scope);\n });\n }\n\n function withSetScope<T>(scope: Scope, callback: (scope: Scope) => T): T {\n const isolationScope = getScopes().isolationScope.clone();\n return asyncStorage.run({ scope, isolationScope }, () => {\n return callback(scope);\n });\n }\n\n function withIsolationScope<T>(callback: (isolationScope: Scope) => T): T {\n const scope = getScopes().scope;\n const isolationScope = getScopes().isolationScope.clone();\n return asyncStorage.run({ scope, isolationScope }, () => {\n return callback(isolationScope);\n });\n }\n\n function withSetIsolationScope<T>(isolationScope: Scope, callback: (isolationScope: Scope) => T): T {\n const scope = getScopes().scope;\n return asyncStorage.run({ scope, isolationScope }, () => {\n return callback(isolationScope);\n });\n }\n\n setAsyncContextStrategy({\n withScope,\n withSetScope,\n withIsolationScope,\n withSetIsolationScope,\n getCurrentScope: () => getScopes().scope,\n getIsolationScope: () => getScopes().isolationScope,\n });\n}\n"],"names":["AsyncLocalStorage","getDefaultCurrentScope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SAAS,EAAE,CAAC,KAAK,CAAA;AACnC,IAAI,MAAM,cAAe,GAAE,SAAS,EAAE,CAAC,cAAc,CAAC,KAAK,EAAE,CAAA;AAC7D,IAAI,OAAO,YAAY,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,cAAe,EAAC,EAAE,MAAM;AAC7D,MAAM,OAAO,QAAQ,CAAC,cAAc,CAAC,CAAA;AACrC,KAAK,CAAC,CAAA;AACN,GAAE;AACF;AACA,EAAE,SAAS,qBAAqB,CAAI,cAAc,EAAS,QAAQ,EAAmC;AACtG,IAAI,MAAM,KAAM,GAAE,SAAS,EAAE,CAAC,KAAK,CAAA;AACnC,IAAI,OAAO,YAAY,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,cAAe,EAAC,EAAE,MAAM;AAC7D,MAAM,OAAO,QAAQ,CAAC,cAAc,CAAC,CAAA;AACrC,KAAK,CAAC,CAAA;AACN,GAAE;AACF;AACA,EAAEC,4BAAuB,CAAC;AAC1B,IAAI,SAAS;AACb,IAAI,YAAY;AAChB,IAAI,kBAAkB;AACtB,IAAI,qBAAqB;AACzB,IAAI,eAAe,EAAE,MAAM,SAAS,EAAE,CAAC,KAAK;AAC5C,IAAI,iBAAiB,EAAE,MAAM,SAAS,EAAE,CAAC,cAAc;AACvD,GAAG,CAAC,CAAA;AACJ;;;;"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
|
|
3
|
+
const core = require('@sentry/core');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The Sentry Cloudflare SDK Client.
|
|
7
|
+
*
|
|
8
|
+
* @see CloudflareClientOptions for documentation on configuration options.
|
|
9
|
+
* @see ServerRuntimeClient for usage documentation.
|
|
10
|
+
*/
|
|
11
|
+
class CloudflareClient extends core.ServerRuntimeClient {
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new Cloudflare SDK instance.
|
|
14
|
+
* @param options Configuration options for this SDK.
|
|
15
|
+
*/
|
|
16
|
+
constructor(options) {
|
|
17
|
+
core.applySdkMetadata(options, 'cloudflare');
|
|
18
|
+
options._metadata = options._metadata || {};
|
|
19
|
+
|
|
20
|
+
const clientOptions = {
|
|
21
|
+
...options,
|
|
22
|
+
platform: 'javascript',
|
|
23
|
+
// TODO: Grab version information
|
|
24
|
+
runtime: { name: 'cloudflare' },
|
|
25
|
+
// TODO: Add server name
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
super(clientOptions);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
33
|
+
|
|
34
|
+
exports.CloudflareClient = CloudflareClient;
|
|
35
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sources":["../../src/client.ts"],"sourcesContent":["import type { ServerRuntimeClientOptions } from '@sentry/core';\nimport { ServerRuntimeClient, applySdkMetadata } from '@sentry/core';\nimport type { ClientOptions, Options } from '@sentry/types';\n\nimport type { CloudflareTransportOptions } from './transport';\n\n/**\n * The Sentry Cloudflare SDK Client.\n *\n * @see CloudflareClientOptions for documentation on configuration options.\n * @see ServerRuntimeClient for usage documentation.\n */\nexport class CloudflareClient extends ServerRuntimeClient<CloudflareClientOptions> {\n /**\n * Creates a new Cloudflare SDK instance.\n * @param options Configuration options for this SDK.\n */\n public constructor(options: CloudflareClientOptions) {\n applySdkMetadata(options, 'cloudflare');\n options._metadata = options._metadata || {};\n\n const clientOptions: ServerRuntimeClientOptions = {\n ...options,\n platform: 'javascript',\n // TODO: Grab version information\n runtime: { name: 'cloudflare' },\n // TODO: Add server name\n };\n\n super(clientOptions);\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\ninterface BaseCloudflareOptions {}\n\n/**\n * Configuration options for the Sentry Cloudflare SDK\n *\n * @see @sentry/types Options for more information.\n */\nexport interface CloudflareOptions extends Options<CloudflareTransportOptions>, BaseCloudflareOptions {}\n\n/**\n * Configuration options for the Sentry Cloudflare SDK Client class\n *\n * @see CloudflareClient for more information.\n */\nexport interface CloudflareClientOptions extends ClientOptions<CloudflareTransportOptions>, BaseCloudflareOptions {}\n"],"names":["ServerRuntimeClient","applySdkMetadata"],"mappings":";;;;AAMA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,gBAAA,SAAyBA,wBAAmB,CAA0B;AACnF;AACA;AACA;AACA;AACA,GAAS,WAAW,CAAC,OAAO,EAA2B;AACvD,IAAIC,qBAAgB,CAAC,OAAO,EAAE,YAAY,CAAC,CAAA;AAC3C,IAAI,OAAO,CAAC,SAAU,GAAE,OAAO,CAAC,SAAA,IAAa,EAAE,CAAA;AAC/C;AACA,IAAI,MAAM,aAAa,GAA+B;AACtD,MAAM,GAAG,OAAO;AAChB,MAAM,QAAQ,EAAE,YAAY;AAC5B;AACA,MAAM,OAAO,EAAE,EAAE,IAAI,EAAE,cAAc;AACrC;AACA,KAAK,CAAA;AACL;AACA,IAAI,KAAK,CAAC,aAAa,CAAC,CAAA;AACxB,GAAE;AACF,CAAA;AACA;AACA;;;;"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
|
|
3
|
+
const core = require('@sentry/core');
|
|
4
|
+
const utils = require('@sentry/utils');
|
|
5
|
+
const async = require('./async.js');
|
|
6
|
+
const sdk = require('./sdk.js');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Extract environment generic from exported handler.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Wrapper for Cloudflare handlers.
|
|
14
|
+
*
|
|
15
|
+
* Initializes the SDK and wraps the handler with Sentry instrumentation.
|
|
16
|
+
*
|
|
17
|
+
* Automatically instruments the `fetch` method of the handler.
|
|
18
|
+
*
|
|
19
|
+
* @param optionsCallback Function that returns the options for the SDK initialization.
|
|
20
|
+
* @param handler {ExportedHandler} The handler to wrap.
|
|
21
|
+
* @returns The wrapped handler.
|
|
22
|
+
*/
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
|
+
function withSentry(
|
|
25
|
+
optionsCallback,
|
|
26
|
+
handler,
|
|
27
|
+
) {
|
|
28
|
+
async.setAsyncLocalStorageAsyncContextStrategy();
|
|
29
|
+
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
|
|
31
|
+
if ('fetch' in handler && typeof handler.fetch === 'function' && !(handler.fetch ).__SENTRY_INSTRUMENTED__) {
|
|
32
|
+
handler.fetch = new Proxy(handler.fetch, {
|
|
33
|
+
apply(target, thisArg, args) {
|
|
34
|
+
const [request, env, context] = args;
|
|
35
|
+
return core.withIsolationScope(isolationScope => {
|
|
36
|
+
const options = optionsCallback(env);
|
|
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
|
+
});
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
|
|
103
|
+
(handler.fetch ).__SENTRY_INSTRUMENTED__ = true;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return handler;
|
|
107
|
+
}
|
|
108
|
+
|
|
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
|
+
exports.withSentry = withSentry;
|
|
126
|
+
//# sourceMappingURL=handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler.js","sources":["../../src/handler.ts"],"sourcesContent":["import type {\n ExportedHandler,\n ExportedHandlerFetchHandler,\n IncomingRequestCfProperties,\n} from '@cloudflare/workers-types';\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 { Options, Scope, SpanAttributes } from '@sentry/types';\nimport { stripUrlQueryAndFragment, winterCGRequestToRequestData } from '@sentry/utils';\nimport { setAsyncLocalStorageAsyncContextStrategy } from './async';\nimport { init } from './sdk';\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 return withIsolationScope(isolationScope => {\n const options = optionsCallback(env);\n const client = init(options);\n isolationScope.setClient(client);\n\n const attributes: SpanAttributes = {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.cloudflare-worker',\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 addRequest(isolationScope, request);\n addCloudResourceContext(isolationScope);\n if (request.cf) {\n addCultureContext(isolationScope, request.cf);\n attributes['network.protocol.name'] = request.cf.httpProtocol;\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 (target.apply(thisArg, args) as ReturnType<typeof target>);\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 // 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\nfunction addCloudResourceContext(isolationScope: Scope): void {\n isolationScope.setContext('cloud_resource', {\n 'cloud.provider': 'cloudflare',\n });\n}\n\nfunction addCultureContext(isolationScope: Scope, cf: IncomingRequestCfProperties): void {\n isolationScope.setContext('culture', {\n timezone: cf.timezone,\n });\n}\n\nfunction addRequest(isolationScope: Scope, request: Request): void {\n isolationScope.setSDKProcessingMetadata({ request: winterCGRequestToRequestData(request) });\n}\n"],"names":["setAsyncLocalStorageAsyncContextStrategy","withIsolationScope","init","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","SEMANTIC_ATTRIBUTE_SENTRY_SOURCE","SEMANTIC_ATTRIBUTE_SENTRY_OP","stripUrlQueryAndFragment","continueTrace","startSpan","setHttpStatus","captureException","flush","winterCGRequestToRequestData"],"mappings":";;;;;;;AAqBA;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,CAAC,OAAO,EAAE,GAAG,EAAE,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AA;AACA,mBAAA;AACA,iBAAA;AACA,eAAA,CAAA;AACA,aAAA;AACA,WAAA,CAAA;AACA,SAAA,CAAA,CAAA;AACA,OAAA;AACA,KAAA,CAAA,CAAA;AACA;AACA;AACA,IAAA,CAAA,OAAA,CAAA,KAAA,GAAA,uBAAA,GAAA,IAAA,CAAA;AACA,GAAA;AACA;AACA,EAAA,OAAA,OAAA,CAAA;AACA,CAAA;AACA;AACA,SAAA,uBAAA,CAAA,cAAA,EAAA;AACA,EAAA,cAAA,CAAA,UAAA,CAAA,gBAAA,EAAA;AACA,IAAA,gBAAA,EAAA,YAAA;AACA,GAAA,CAAA,CAAA;AACA,CAAA;AACA;AACA,SAAA,iBAAA,CAAA,cAAA,EAAA,EAAA,EAAA;AACA,EAAA,cAAA,CAAA,UAAA,CAAA,SAAA,EAAA;AACA,IAAA,QAAA,EAAA,EAAA,CAAA,QAAA;AACA,GAAA,CAAA,CAAA;AACA,CAAA;AACA;AACA,SAAA,UAAA,CAAA,cAAA,EAAA,OAAA,EAAA;AACA,EAAA,cAAA,CAAA,wBAAA,CAAA,EAAA,OAAA,EAAAC,kCAAA,CAAA,OAAA,CAAA,EAAA,CAAA,CAAA;AACA;;;;"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
|
|
3
|
+
const core = require('@sentry/core');
|
|
4
|
+
const handler = require('./handler.js');
|
|
5
|
+
const client = require('./client.js');
|
|
6
|
+
const sdk = require('./sdk.js');
|
|
7
|
+
const fetch = require('./integrations/fetch.js');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
exports.SDK_VERSION = core.SDK_VERSION;
|
|
12
|
+
exports.SEMANTIC_ATTRIBUTE_SENTRY_OP = core.SEMANTIC_ATTRIBUTE_SENTRY_OP;
|
|
13
|
+
exports.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN = core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN;
|
|
14
|
+
exports.SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE = core.SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE;
|
|
15
|
+
exports.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE = core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE;
|
|
16
|
+
exports.Scope = core.Scope;
|
|
17
|
+
exports.addBreadcrumb = core.addBreadcrumb;
|
|
18
|
+
exports.addEventProcessor = core.addEventProcessor;
|
|
19
|
+
exports.addIntegration = core.addIntegration;
|
|
20
|
+
exports.captureCheckIn = core.captureCheckIn;
|
|
21
|
+
exports.captureConsoleIntegration = core.captureConsoleIntegration;
|
|
22
|
+
exports.captureEvent = core.captureEvent;
|
|
23
|
+
exports.captureException = core.captureException;
|
|
24
|
+
exports.captureFeedback = core.captureFeedback;
|
|
25
|
+
exports.captureMessage = core.captureMessage;
|
|
26
|
+
exports.close = core.close;
|
|
27
|
+
exports.continueTrace = core.continueTrace;
|
|
28
|
+
exports.createTransport = core.createTransport;
|
|
29
|
+
exports.debugIntegration = core.debugIntegration;
|
|
30
|
+
exports.dedupeIntegration = core.dedupeIntegration;
|
|
31
|
+
exports.extraErrorDataIntegration = core.extraErrorDataIntegration;
|
|
32
|
+
exports.flush = core.flush;
|
|
33
|
+
exports.functionToStringIntegration = core.functionToStringIntegration;
|
|
34
|
+
exports.getActiveSpan = core.getActiveSpan;
|
|
35
|
+
exports.getClient = core.getClient;
|
|
36
|
+
exports.getCurrentScope = core.getCurrentScope;
|
|
37
|
+
exports.getGlobalScope = core.getGlobalScope;
|
|
38
|
+
exports.getIsolationScope = core.getIsolationScope;
|
|
39
|
+
exports.getRootSpan = core.getRootSpan;
|
|
40
|
+
exports.getSpanDescendants = core.getSpanDescendants;
|
|
41
|
+
exports.getSpanStatusFromHttpCode = core.getSpanStatusFromHttpCode;
|
|
42
|
+
exports.inboundFiltersIntegration = core.inboundFiltersIntegration;
|
|
43
|
+
exports.isInitialized = core.isInitialized;
|
|
44
|
+
exports.lastEventId = core.lastEventId;
|
|
45
|
+
exports.linkedErrorsIntegration = core.linkedErrorsIntegration;
|
|
46
|
+
exports.metrics = core.metrics;
|
|
47
|
+
exports.moduleMetadataIntegration = core.moduleMetadataIntegration;
|
|
48
|
+
exports.requestDataIntegration = core.requestDataIntegration;
|
|
49
|
+
exports.rewriteFramesIntegration = core.rewriteFramesIntegration;
|
|
50
|
+
exports.setContext = core.setContext;
|
|
51
|
+
exports.setCurrentClient = core.setCurrentClient;
|
|
52
|
+
exports.setExtra = core.setExtra;
|
|
53
|
+
exports.setExtras = core.setExtras;
|
|
54
|
+
exports.setHttpStatus = core.setHttpStatus;
|
|
55
|
+
exports.setMeasurement = core.setMeasurement;
|
|
56
|
+
exports.setTag = core.setTag;
|
|
57
|
+
exports.setTags = core.setTags;
|
|
58
|
+
exports.setUser = core.setUser;
|
|
59
|
+
exports.spanToBaggageHeader = core.spanToBaggageHeader;
|
|
60
|
+
exports.spanToJSON = core.spanToJSON;
|
|
61
|
+
exports.spanToTraceHeader = core.spanToTraceHeader;
|
|
62
|
+
exports.startInactiveSpan = core.startInactiveSpan;
|
|
63
|
+
exports.startNewTrace = core.startNewTrace;
|
|
64
|
+
exports.startSpan = core.startSpan;
|
|
65
|
+
exports.startSpanManual = core.startSpanManual;
|
|
66
|
+
exports.trpcMiddleware = core.trpcMiddleware;
|
|
67
|
+
exports.withActiveSpan = core.withActiveSpan;
|
|
68
|
+
exports.withIsolationScope = core.withIsolationScope;
|
|
69
|
+
exports.withMonitor = core.withMonitor;
|
|
70
|
+
exports.withScope = core.withScope;
|
|
71
|
+
exports.zodErrorsIntegration = core.zodErrorsIntegration;
|
|
72
|
+
exports.withSentry = handler.withSentry;
|
|
73
|
+
exports.CloudflareClient = client.CloudflareClient;
|
|
74
|
+
exports.getDefaultIntegrations = sdk.getDefaultIntegrations;
|
|
75
|
+
exports.fetchIntegration = fetch.fetchIntegration;
|
|
76
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
|
|
3
|
+
const core = require('@sentry/core');
|
|
4
|
+
const utils = require('@sentry/utils');
|
|
5
|
+
|
|
6
|
+
const INTEGRATION_NAME = 'Fetch';
|
|
7
|
+
|
|
8
|
+
const HAS_CLIENT_MAP = new WeakMap();
|
|
9
|
+
|
|
10
|
+
const _fetchIntegration = ((options = {}) => {
|
|
11
|
+
const breadcrumbs = options.breadcrumbs === undefined ? true : options.breadcrumbs;
|
|
12
|
+
const shouldCreateSpanForRequest = options.shouldCreateSpanForRequest;
|
|
13
|
+
|
|
14
|
+
const _createSpanUrlMap = new utils.LRUMap(100);
|
|
15
|
+
const _headersUrlMap = new utils.LRUMap(100);
|
|
16
|
+
|
|
17
|
+
const spans = {};
|
|
18
|
+
|
|
19
|
+
/** Decides whether to attach trace data to the outgoing fetch request */
|
|
20
|
+
function _shouldAttachTraceData(url) {
|
|
21
|
+
const client = core.getClient();
|
|
22
|
+
|
|
23
|
+
if (!client) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const clientOptions = client.getOptions();
|
|
28
|
+
|
|
29
|
+
if (clientOptions.tracePropagationTargets === undefined) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const cachedDecision = _headersUrlMap.get(url);
|
|
34
|
+
if (cachedDecision !== undefined) {
|
|
35
|
+
return cachedDecision;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const decision = utils.stringMatchesSomePattern(url, clientOptions.tracePropagationTargets);
|
|
39
|
+
_headersUrlMap.set(url, decision);
|
|
40
|
+
return decision;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Helper that wraps shouldCreateSpanForRequest option */
|
|
44
|
+
function _shouldCreateSpan(url) {
|
|
45
|
+
if (shouldCreateSpanForRequest === undefined) {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const cachedDecision = _createSpanUrlMap.get(url);
|
|
50
|
+
if (cachedDecision !== undefined) {
|
|
51
|
+
return cachedDecision;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const decision = shouldCreateSpanForRequest(url);
|
|
55
|
+
_createSpanUrlMap.set(url, decision);
|
|
56
|
+
return decision;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
name: INTEGRATION_NAME,
|
|
61
|
+
setupOnce() {
|
|
62
|
+
utils.addFetchInstrumentationHandler(handlerData => {
|
|
63
|
+
const client = core.getClient();
|
|
64
|
+
if (!client || !HAS_CLIENT_MAP.get(client)) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (core.isSentryRequestUrl(handlerData.fetchData.url, client)) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
core.instrumentFetchRequest(handlerData, _shouldCreateSpan, _shouldAttachTraceData, spans, 'auto.http.fetch');
|
|
73
|
+
|
|
74
|
+
if (breadcrumbs) {
|
|
75
|
+
createBreadcrumb(handlerData);
|
|
76
|
+
}
|
|
77
|
+
}, true);
|
|
78
|
+
},
|
|
79
|
+
setup(client) {
|
|
80
|
+
HAS_CLIENT_MAP.set(client, true);
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}) ;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Creates spans and attaches tracing headers to fetch requests.
|
|
87
|
+
*/
|
|
88
|
+
const fetchIntegration = core.defineIntegration(_fetchIntegration);
|
|
89
|
+
|
|
90
|
+
function createBreadcrumb(handlerData) {
|
|
91
|
+
const { startTimestamp, endTimestamp } = handlerData;
|
|
92
|
+
|
|
93
|
+
// We only capture complete fetch requests
|
|
94
|
+
if (!endTimestamp) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (handlerData.error) {
|
|
99
|
+
const data = handlerData.fetchData;
|
|
100
|
+
const hint = {
|
|
101
|
+
data: handlerData.error,
|
|
102
|
+
input: handlerData.args,
|
|
103
|
+
startTimestamp,
|
|
104
|
+
endTimestamp,
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
core.addBreadcrumb(
|
|
108
|
+
{
|
|
109
|
+
category: 'fetch',
|
|
110
|
+
data,
|
|
111
|
+
level: 'error',
|
|
112
|
+
type: 'http',
|
|
113
|
+
},
|
|
114
|
+
hint,
|
|
115
|
+
);
|
|
116
|
+
} else {
|
|
117
|
+
const data = {
|
|
118
|
+
...handlerData.fetchData,
|
|
119
|
+
status_code: handlerData.response && handlerData.response.status,
|
|
120
|
+
};
|
|
121
|
+
const hint = {
|
|
122
|
+
input: handlerData.args,
|
|
123
|
+
response: handlerData.response,
|
|
124
|
+
startTimestamp,
|
|
125
|
+
endTimestamp,
|
|
126
|
+
};
|
|
127
|
+
core.addBreadcrumb(
|
|
128
|
+
{
|
|
129
|
+
category: 'fetch',
|
|
130
|
+
data,
|
|
131
|
+
type: 'http',
|
|
132
|
+
},
|
|
133
|
+
hint,
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
exports.fetchIntegration = fetchIntegration;
|
|
139
|
+
//# sourceMappingURL=fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.js","sources":["../../../src/integrations/fetch.ts"],"sourcesContent":["import { addBreadcrumb, defineIntegration, getClient, instrumentFetchRequest, isSentryRequestUrl } from '@sentry/core';\nimport type {\n Client,\n FetchBreadcrumbData,\n FetchBreadcrumbHint,\n HandlerDataFetch,\n IntegrationFn,\n Span,\n} from '@sentry/types';\nimport { LRUMap, addFetchInstrumentationHandler, stringMatchesSomePattern } from '@sentry/utils';\n\nconst INTEGRATION_NAME = 'Fetch';\n\nconst HAS_CLIENT_MAP = new WeakMap<Client, boolean>();\n\nexport interface Options {\n /**\n * Whether breadcrumbs should be recorded for requests\n * Defaults to true\n */\n breadcrumbs: boolean;\n\n /**\n * Function determining whether or not to create spans to track outgoing requests to the given URL.\n * By default, spans will be created for all outgoing requests.\n */\n shouldCreateSpanForRequest?: (url: string) => boolean;\n}\n\nconst _fetchIntegration = ((options: Partial<Options> = {}) => {\n const breadcrumbs = options.breadcrumbs === undefined ? true : options.breadcrumbs;\n const shouldCreateSpanForRequest = options.shouldCreateSpanForRequest;\n\n const _createSpanUrlMap = new LRUMap<string, boolean>(100);\n const _headersUrlMap = new LRUMap<string, boolean>(100);\n\n const spans: Record<string, Span> = {};\n\n /** Decides whether to attach trace data to the outgoing fetch request */\n function _shouldAttachTraceData(url: string): boolean {\n const client = getClient();\n\n if (!client) {\n return false;\n }\n\n const clientOptions = client.getOptions();\n\n if (clientOptions.tracePropagationTargets === undefined) {\n return true;\n }\n\n const cachedDecision = _headersUrlMap.get(url);\n if (cachedDecision !== undefined) {\n return cachedDecision;\n }\n\n const decision = stringMatchesSomePattern(url, clientOptions.tracePropagationTargets);\n _headersUrlMap.set(url, decision);\n return decision;\n }\n\n /** Helper that wraps shouldCreateSpanForRequest option */\n function _shouldCreateSpan(url: string): boolean {\n if (shouldCreateSpanForRequest === undefined) {\n return true;\n }\n\n const cachedDecision = _createSpanUrlMap.get(url);\n if (cachedDecision !== undefined) {\n return cachedDecision;\n }\n\n const decision = shouldCreateSpanForRequest(url);\n _createSpanUrlMap.set(url, decision);\n return decision;\n }\n\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n addFetchInstrumentationHandler(handlerData => {\n const client = getClient();\n if (!client || !HAS_CLIENT_MAP.get(client)) {\n return;\n }\n\n if (isSentryRequestUrl(handlerData.fetchData.url, client)) {\n return;\n }\n\n instrumentFetchRequest(handlerData, _shouldCreateSpan, _shouldAttachTraceData, spans, 'auto.http.fetch');\n\n if (breadcrumbs) {\n createBreadcrumb(handlerData);\n }\n }, true);\n },\n setup(client) {\n HAS_CLIENT_MAP.set(client, true);\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Creates spans and attaches tracing headers to fetch requests.\n */\nexport const fetchIntegration = defineIntegration(_fetchIntegration);\n\nfunction createBreadcrumb(handlerData: HandlerDataFetch): void {\n const { startTimestamp, endTimestamp } = handlerData;\n\n // We only capture complete fetch requests\n if (!endTimestamp) {\n return;\n }\n\n if (handlerData.error) {\n const data = handlerData.fetchData;\n const hint: FetchBreadcrumbHint = {\n data: handlerData.error,\n input: handlerData.args,\n startTimestamp,\n endTimestamp,\n };\n\n addBreadcrumb(\n {\n category: 'fetch',\n data,\n level: 'error',\n type: 'http',\n },\n hint,\n );\n } else {\n const data: FetchBreadcrumbData = {\n ...handlerData.fetchData,\n status_code: handlerData.response && handlerData.response.status,\n };\n const hint: FetchBreadcrumbHint = {\n input: handlerData.args,\n response: handlerData.response,\n startTimestamp,\n endTimestamp,\n };\n addBreadcrumb(\n {\n category: 'fetch',\n data,\n type: 'http',\n },\n hint,\n );\n }\n}\n"],"names":["LRUMap","getClient","stringMatchesSomePattern","addFetchInstrumentationHandler","isSentryRequestUrl","instrumentFetchRequest","defineIntegration","addBreadcrumb"],"mappings":";;;;;AAWA,MAAM,gBAAA,GAAmB,OAAO,CAAA;AAChC;AACA,MAAM,cAAe,GAAE,IAAI,OAAO,EAAmB,CAAA;;AAgBrD,MAAM,iBAAA,IAAqB,CAAC,OAAO,GAAqB,EAAE,KAAK;AAC/D,EAAE,MAAM,WAAA,GAAc,OAAO,CAAC,WAAA,KAAgB,SAAA,GAAY,IAAA,GAAO,OAAO,CAAC,WAAW,CAAA;AACpF,EAAE,MAAM,0BAAA,GAA6B,OAAO,CAAC,0BAA0B,CAAA;AACvE;AACA,EAAE,MAAM,iBAAkB,GAAE,IAAIA,YAAM,CAAkB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