Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cloudflare): Add basic cloudflare package and tests #12733

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions dev-packages/e2e-tests/verdaccio-config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ packages:
unpublish: $all
# proxy: npmjs # Don't proxy for E2E tests!

'@sentry/cloudflare':
access: $all
publish: $all
unpublish: $all
# proxy: npmjs # Don't proxy for E2E tests!

'@sentry/deno':
access: $all
publish: $all
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"packages/browser-utils",
"packages/bun",
"packages/core",
"packages/cloudflare",
"packages/deno",
"packages/ember",
"packages/eslint-config-sdk",
Expand Down
9 changes: 9 additions & 0 deletions packages/cloudflare/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
env: {},
extends: ['../../.eslintrc.js'],
rules: {
'@sentry-internal/sdk/no-optional-chaining': 'off',
'@sentry-internal/sdk/no-nullish-coalescing': 'off',
'@sentry-internal/sdk/no-class-field-initializers': 'off',
},
};
21 changes: 21 additions & 0 deletions packages/cloudflare/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Functional Software, Inc. dba Sentry

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
23 changes: 23 additions & 0 deletions packages/cloudflare/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<p align="center">
<a href="https://sentry.io/?utm_source=github&utm_medium=logo" target="_blank">
<img src="https://sentry-brand.storage.googleapis.com/sentry-wordmark-dark-280x84.png" alt="Sentry" width="280" height="84">
</a>
</p>

# Official Sentry SDK for Cloudflare [UNRELEASED]

[![npm version](https://img.shields.io/npm/v/@sentry/cloudflare.svg)](https://www.npmjs.com/package/@sentry/cloudflare)
[![npm dm](https://img.shields.io/npm/dm/@sentry/cloudflare.svg)](https://www.npmjs.com/package/@sentry/cloudflare)
[![npm dt](https://img.shields.io/npm/dt/@sentry/cloudflare.svg)](https://www.npmjs.com/package/@sentry/cloudflare)

## Links

- [Official SDK Docs](https://docs.sentry.io/quickstart/)
- [TypeDoc](http://getsentry.github.io/sentry-javascript/)

**Note: This SDK is unreleased. Please follow the [tracking GH issue](https://github.com/getsentry/sentry-javascript/issues/12620) for updates.**

## Usage

TODO: Add usage instructions here.

77 changes: 77 additions & 0 deletions packages/cloudflare/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"name": "@sentry/cloudflare",
"version": "8.13.0",
"description": "Offical Sentry SDK for Cloudflare Workers and Pages",
"repository": "git://github.com/getsentry/sentry-javascript.git",
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/cloudflare",
"author": "Sentry",
"license": "MIT",
"engines": {
"node": ">=14.18"
},
"files": [
"/build"
],
"type": "module",
"main": "build/cjs/index.js",
"module": "build/esm/index.js",
"types": "build/types/index.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
"import": {
"types": "./build/types/index.d.ts",
"default": "./build/esm/index.js"
},
"require": {
"types": "./build/types/index.d.ts",
"default": "./build/cjs/index.js"
}
}
},
"typesVersions": {
"<4.9": {
"build/types/index.d.ts": [
"build/types-ts3.8/index.d.ts"
]
}
},
"publishConfig": {
"access": "public"
},
"dependencies": {
"@sentry/core": "8.13.0",
"@sentry/types": "8.13.0",
"@sentry/utils": "8.13.0"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20240620.0",
"miniflare": "^3.20240620.0",
"wrangler": "^3.62.0"
},
"scripts": {
"build": "run-p build:transpile build:types",
"build:dev": "yarn build",
"build:transpile": "rollup -c rollup.npm.config.mjs",
"build:types": "run-s build:types:core build:types:downlevel",
"build:types:core": "tsc -p tsconfig.types.json",
"build:types:downlevel": "yarn downlevel-dts build/types build/types-ts3.8 --to ts3.8",
"build:watch": "run-p build:transpile:watch build:types:watch",
"build:dev:watch": "yarn build:watch",
"build:transpile:watch": "rollup -c rollup.npm.config.mjs --watch",
"build:types:watch": "tsc -p tsconfig.types.json --watch",
"build:tarball": "npm pack",
"circularDepCheck": "madge --circular src/index.ts",
"clean": "rimraf build coverage sentry-cloudflare-*.tgz",
"fix": "eslint . --format stylish --fix",
"lint": "eslint . --format stylish",
"test": "yarn test:unit",
"test:unit": "vitest run",
"test:watch": "vitest --watch",
"yalc:publish": "yalc publish --push --sig"
},
"volta": {
"extends": "../../package.json"
},
"sideEffects": false
}
3 changes: 3 additions & 0 deletions packages/cloudflare/rollup.npm.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { makeBaseNPMConfig, makeNPMConfigVariants } from '@sentry-internal/rollup-utils';

export default makeNPMConfigVariants(makeBaseNPMConfig());
1 change: 1 addition & 0 deletions packages/cloudflare/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
1 change: 1 addition & 0 deletions packages/cloudflare/test/fixtures/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "type": "module" }
7 changes: 7 additions & 0 deletions packages/cloudflare/test/fixtures/worker.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { ExportedHandler, Response as CFResponse } from '@cloudflare/workers-types';

export default ({
async fetch(request, env, ctx) {
return new Response('Hello Sentry!') as unknown as CFResponse;
},
} satisfies ExportedHandler);
15 changes: 15 additions & 0 deletions packages/cloudflare/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { describe, expect, test } from 'vitest';

import { Miniflare } from 'miniflare';

describe('index', () => {
test('simple test', async () => {
const mf = new Miniflare({
scriptPath: './test/fixtures/worker.mts',
});

const res = await mf.dispatchFetch('http://localhost:8787/');

Check failure on line 11 in packages/cloudflare/test/index.test.ts

View workflow job for this annotation

GitHub Actions / Browser Unit Tests

test/index.test.ts > index > simple test

MiniflareCoreError [ERR_RUNTIME_FAILURE]: The Workers runtime failed to start. There is likely additional logging output above. ❯ Miniflare2.#assembleAndUpdateConfig ../../node_modules/miniflare/src/index.ts:1343:10 ❯ Mutex.runWith ../../node_modules/miniflare/src/workers/shared/sync.ts:66:45 ❯ Miniflare2.#waitForReady ../../node_modules/miniflare/src/index.ts:1425:3 ❯ Miniflare2.dispatchFetch ../../node_modules/miniflare/src/index.ts:1552:3 ❯ test/index.test.ts:11:17 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { code: 'ERR_RUNTIME_FAILURE' }

Check failure on line 11 in packages/cloudflare/test/index.test.ts

View workflow job for this annotation

GitHub Actions / Node (16) Unit Tests

test/index.test.ts > index > simple test

MiniflareCoreError [ERR_RUNTIME_FAILURE]: The Workers runtime failed to start. There is likely additional logging output above. ❯ Miniflare2.#assembleAndUpdateConfig ../../node_modules/miniflare/src/index.ts:1343:10 ❯ Mutex.runWith ../../node_modules/miniflare/src/workers/shared/sync.ts:66:45 ❯ Miniflare2.#waitForReady ../../node_modules/miniflare/src/index.ts:1425:3 ❯ Miniflare2.dispatchFetch ../../node_modules/miniflare/src/index.ts:1552:3 ❯ test/index.test.ts:11:17 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { code: 'ERR_RUNTIME_FAILURE' }

Check failure on line 11 in packages/cloudflare/test/index.test.ts

View workflow job for this annotation

GitHub Actions / Node (18) Unit Tests

test/index.test.ts > index > simple test

MiniflareCoreError [ERR_RUNTIME_FAILURE]: The Workers runtime failed to start. There is likely additional logging output above. ❯ Miniflare2.#assembleAndUpdateConfig ../../node_modules/miniflare/src/index.ts:1343:10 ❯ Mutex.runWith ../../node_modules/miniflare/src/workers/shared/sync.ts:66:45 ❯ Miniflare2.#waitForReady ../../node_modules/miniflare/src/index.ts:1425:3 ❯ Miniflare2.dispatchFetch ../../node_modules/miniflare/src/index.ts:1552:3 ❯ test/index.test.ts:11:17 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { code: 'ERR_RUNTIME_FAILURE' }

Check failure on line 11 in packages/cloudflare/test/index.test.ts

View workflow job for this annotation

GitHub Actions / Node (20) Unit Tests

test/index.test.ts > index > simple test

MiniflareCoreError [ERR_RUNTIME_FAILURE]: The Workers runtime failed to start. There is likely additional logging output above. ❯ Miniflare2.#assembleAndUpdateConfig ../../node_modules/miniflare/src/index.ts:1343:10 ❯ Mutex.runWith ../../node_modules/miniflare/src/workers/shared/sync.ts:66:45 ❯ Miniflare2.#waitForReady ../../node_modules/miniflare/src/index.ts:1425:3 ❯ Miniflare2.dispatchFetch ../../node_modules/miniflare/src/index.ts:1552:3 ❯ test/index.test.ts:11:17 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { code: 'ERR_RUNTIME_FAILURE' }

Check failure on line 11 in packages/cloudflare/test/index.test.ts

View workflow job for this annotation

GitHub Actions / Node (22) Unit Tests

test/index.test.ts > index > simple test

MiniflareCoreError [ERR_RUNTIME_FAILURE]: The Workers runtime failed to start. There is likely additional logging output above. ❯ Miniflare2.#assembleAndUpdateConfig ../../node_modules/miniflare/src/index.ts:1343:10 ❯ Mutex.runWith ../../node_modules/miniflare/src/workers/shared/sync.ts:66:45 ❯ Miniflare2.#waitForReady ../../node_modules/miniflare/src/index.ts:1425:3 ❯ Miniflare2.dispatchFetch ../../node_modules/miniflare/src/index.ts:1552:3 ❯ test/index.test.ts:11:17 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { code: 'ERR_RUNTIME_FAILURE' }
expect(await res.text()).toBe('Hello Sentry!');
await mf.dispose();
});
});
10 changes: 10 additions & 0 deletions packages/cloudflare/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.json",

"include": ["src/**/*"],

"compilerOptions": {
"lib": ["es2018"],
"types": ["@cloudflare/workers-types"]
}
}
9 changes: 9 additions & 0 deletions packages/cloudflare/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",

"include": ["test/**/*"],

"compilerOptions": {
"types": ["@cloudflare/workers-types"]
}
}
10 changes: 10 additions & 0 deletions packages/cloudflare/tsconfig.types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",

"compilerOptions": {
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": true,
"outDir": "build/types"
}
}
Loading
Loading