Skip to content

Commit 17bf308

Browse files
authored
feat: feat(cloudflare): Add basic cloudflare package and tests (#12861)
resolves #12685 Initial attempt: #12733 This PR introduces `@sentry/cloudflare`, our package for cloudflare pages and cloudflare workers. It also adds a basic test with [`miniflare` ](https://miniflare.dev/), the local simulator for cloudflare workers. In the next step, I'll add basic SDK initialization + error monitoring for the cloudflare pages use case.
1 parent d304248 commit 17bf308

17 files changed

+593
-5
lines changed

dev-packages/e2e-tests/verdaccio-config/config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ packages:
6262
unpublish: $all
6363
# proxy: npmjs # Don't proxy for E2E tests!
6464

65+
'@sentry/cloudflare':
66+
access: $all
67+
publish: $all
68+
unpublish: $all
69+
# proxy: npmjs # Don't proxy for E2E tests!
70+
6571
'@sentry/deno':
6672
access: $all
6773
publish: $all

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"packages/browser-utils",
5252
"packages/bun",
5353
"packages/core",
54+
"packages/cloudflare",
5455
"packages/deno",
5556
"packages/ember",
5657
"packages/eslint-config-sdk",

packages/cloudflare/.eslintrc.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = {
2+
env: {
3+
node: true,
4+
},
5+
extends: ['../../.eslintrc.js'],
6+
rules: {
7+
'@sentry-internal/sdk/no-optional-chaining': 'off',
8+
'@sentry-internal/sdk/no-nullish-coalescing': 'off',
9+
'@sentry-internal/sdk/no-class-field-initializers': 'off',
10+
},
11+
};

packages/cloudflare/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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.

packages/cloudflare/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
[![npm version](https://img.shields.io/npm/v/@sentry/cloudflare.svg)](https://www.npmjs.com/package/@sentry/cloudflare)
10+
[![npm dm](https://img.shields.io/npm/dm/@sentry/cloudflare.svg)](https://www.npmjs.com/package/@sentry/cloudflare)
11+
[![npm dt](https://img.shields.io/npm/dt/@sentry/cloudflare.svg)](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+
## Usage
22+
23+
TODO: Add usage instructions here.

packages/cloudflare/package.json

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{
2+
"name": "@sentry/cloudflare",
3+
"version": "8.17.0",
4+
"description": "Offical Sentry SDK for Cloudflare Workers and Pages",
5+
"repository": "git://github.com/getsentry/sentry-javascript.git",
6+
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/cloudflare",
7+
"author": "Sentry",
8+
"license": "MIT",
9+
"engines": {
10+
"node": ">=14.18"
11+
},
12+
"files": [
13+
"/build"
14+
],
15+
"main": "build/cjs/index.js",
16+
"module": "build/esm/index.js",
17+
"types": "build/types/index.d.ts",
18+
"exports": {
19+
"./package.json": "./package.json",
20+
".": {
21+
"import": {
22+
"types": "./build/types/index.d.ts",
23+
"default": "./build/esm/index.js"
24+
},
25+
"require": {
26+
"types": "./build/types/index.d.ts",
27+
"default": "./build/cjs/index.js"
28+
}
29+
}
30+
},
31+
"typesVersions": {
32+
"<4.9": {
33+
"build/types/index.d.ts": [
34+
"build/types-ts3.8/index.d.ts"
35+
]
36+
}
37+
},
38+
"publishConfig": {
39+
"access": "public"
40+
},
41+
"dependencies": {
42+
"@sentry/core": "8.17.0",
43+
"@sentry/types": "8.17.0",
44+
"@sentry/utils": "8.17.0"
45+
},
46+
"devDependencies": {
47+
"@cloudflare/workers-types": "^4.20240620.0",
48+
"miniflare": "^3.20240701.0",
49+
"wrangler": "^3.63.2"
50+
},
51+
"scripts": {
52+
"build": "run-p build:transpile build:types",
53+
"build:dev": "yarn build",
54+
"build:transpile": "rollup -c rollup.npm.config.mjs",
55+
"build:types": "run-s build:types:core build:types:downlevel",
56+
"build:types:core": "tsc -p tsconfig.types.json",
57+
"build:types:downlevel": "yarn downlevel-dts build/types build/types-ts3.8 --to ts3.8",
58+
"build:watch": "run-p build:transpile:watch build:types:watch",
59+
"build:dev:watch": "yarn build:watch",
60+
"build:transpile:watch": "rollup -c rollup.npm.config.mjs --watch",
61+
"build:types:watch": "tsc -p tsconfig.types.json --watch",
62+
"build:tarball": "npm pack",
63+
"circularDepCheck": "madge --circular src/index.ts",
64+
"clean": "rimraf build coverage sentry-cloudflare-*.tgz",
65+
"fix": "eslint . --format stylish --fix",
66+
"lint": "eslint . --format stylish",
67+
"test": "yarn test:unit",
68+
"test:unit": "vitest run",
69+
"test:watch": "vitest --watch",
70+
"yalc:publish": "yalc publish --push --sig"
71+
},
72+
"volta": {
73+
"extends": "../../package.json"
74+
},
75+
"sideEffects": false
76+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { makeBaseNPMConfig, makeNPMConfigVariants } from '@sentry-internal/rollup-utils';
2+
3+
export default makeNPMConfigVariants(makeBaseNPMConfig());
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
declare const __DEBUG_BUILD__: boolean;
2+
3+
/**
4+
* This serves as a build time flag that will be true by default, but false in non-debug builds or if users replace `__SENTRY_DEBUG__` in their generated code.
5+
*
6+
* ATTENTION: This constant must never cross package boundaries (i.e. be exported) to guarantee that it can be used for tree shaking.
7+
*/
8+
export const DEBUG_BUILD = __DEBUG_BUILD__;

packages/cloudflare/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* @type {import('@cloudflare/workers-types').ExportedHandler}
3+
*/
4+
export default {
5+
async fetch(_request, _env, _ctx) {
6+
return new Response('Hello Sentry!');
7+
},
8+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { describe, expect, test } from 'vitest';
2+
3+
import { Miniflare } from 'miniflare';
4+
5+
describe('index', () => {
6+
test('simple test', async () => {
7+
const mf = new Miniflare({
8+
scriptPath: './test/fixtures/worker.mjs',
9+
modules: true,
10+
port: 8787,
11+
});
12+
13+
const res = await mf.dispatchFetch('http://localhost:8787/');
14+
expect(await res.text()).toBe('Hello Sentry!');
15+
await mf.dispose();
16+
});
17+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "../tsconfig.test.json",
3+
}

packages/cloudflare/tsconfig.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
4+
"include": ["src/**/*"],
5+
6+
"compilerOptions": {
7+
"types": ["@cloudflare/workers-types"]
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
4+
"include": ["test/**/*"],
5+
6+
"compilerOptions": {
7+
// other package-specific, test-specific options
8+
}
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
4+
"compilerOptions": {
5+
"declaration": true,
6+
"declarationMap": true,
7+
"emitDeclarationOnly": true,
8+
"outDir": "build/types"
9+
}
10+
}

scripts/node-unit-tests.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const DEFAULT_SKIP_TESTS_PACKAGES = [
3131
const SKIP_TEST_PACKAGES: Record<NodeVersion, VersionConfig> = {
3232
'14': {
3333
ignoredPackages: [
34+
'@sentry/cloudflare',
3435
'@sentry/solidstart',
3536
'@sentry/sveltekit',
3637
'@sentry/vercel-edge',
@@ -40,7 +41,7 @@ const SKIP_TEST_PACKAGES: Record<NodeVersion, VersionConfig> = {
4041
],
4142
},
4243
'16': {
43-
ignoredPackages: ['@sentry/vercel-edge', '@sentry/astro'],
44+
ignoredPackages: ['@sentry/cloudflare', '@sentry/vercel-edge', '@sentry/astro'],
4445
},
4546
'18': {
4647
ignoredPackages: [],

0 commit comments

Comments
 (0)