Skip to content

feat: Deno SDK #9206

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

Merged
merged 23 commits into from
Oct 12, 2023
Merged
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
37 changes: 35 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ jobs:
- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: ${{ env.DEFAULT_NODE_VERSION }}
node-version-file: 'package.json'
- name: Restore caches
uses: ./.github/actions/restore-cache
env:
Expand All @@ -406,7 +406,7 @@ jobs:
- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
node-version-file: 'package.json'
- name: Set up Bun
uses: oven-sh/setup-bun@v1
- name: Restore caches
Expand All @@ -419,6 +419,38 @@ jobs:
- name: Compute test coverage
uses: codecov/codecov-action@v3

job_deno_unit_tests:
name: Deno Unit Tests
needs: [job_get_metadata, job_build]
timeout-minutes: 10
runs-on: ubuntu-20.04
strategy:
fail-fast: false
steps:
- name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})
uses: actions/checkout@v4
with:
ref: ${{ env.HEAD_COMMIT }}
- name: Set up Node
uses: actions/setup-node@v3
with:
node-version-file: 'package.json'
- name: Set up Deno
uses: denoland/[email protected]
with:
deno-version: v1.37.1
- name: Restore caches
uses: ./.github/actions/restore-cache
env:
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
- name: Run tests
run: |
cd packages/deno
yarn build
yarn test
- name: Compute test coverage
uses: codecov/codecov-action@v3

job_node_unit_tests:
name: Node (${{ matrix.node }}) Unit Tests
needs: [job_get_metadata, job_build]
Expand Down Expand Up @@ -895,6 +927,7 @@ jobs:
job_browser_build_tests,
job_browser_unit_tests,
job_bun_unit_tests,
job_deno_unit_tests,
job_node_unit_tests,
job_nextjs_integration_test,
job_node_integration_tests,
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jest/transformers/*.js
# node tarballs
packages/*/sentry-*.tgz
.nxcache
# The Deno types are downloaded before building
packages/deno/lib.deno.d.ts

# logs
yarn-error.log
Expand Down
5 changes: 3 additions & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"recommendations": [
"esbenp.prettier-vscode",
"dbaeumer.vscode-eslint",
"augustocdias.tasks-shell-input"
],
"augustocdias.tasks-shell-input",
"denoland.vscode-deno"
]
}
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@
{
"mode": "auto"
}
]
],
"deno.enablePaths": ["packages/deno/test"]
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"postpublish": "lerna run --stream --concurrency 1 postpublish",
"test": "lerna run --ignore \"@sentry-internal/{browser-integration-tests,e2e-tests,integration-shims,node-integration-tests,overhead-metrics}\" test",
"test:unit": "lerna run --ignore \"@sentry-internal/{browser-integration-tests,e2e-tests,integration-shims,node-integration-tests,overhead-metrics}\" test:unit",
"test-ci-browser": "lerna run test --ignore \"@sentry/{bun,node,node-experimental,opentelemetry-node,serverless,nextjs,remix,gatsby,sveltekit,vercel-edge}\" --ignore \"@sentry-internal/{browser-integration-tests,e2e-tests,integration-shims,node-integration-tests,overhead-metrics}\"",
"test-ci-browser": "lerna run test --ignore \"@sentry/{bun,deno,node,node-experimental,opentelemetry-node,serverless,nextjs,remix,gatsby,sveltekit,vercel-edge}\" --ignore \"@sentry-internal/{browser-integration-tests,e2e-tests,integration-shims,node-integration-tests,overhead-metrics}\"",
"test-ci-node": "ts-node ./scripts/node-unit-tests.ts",
"test-ci-bun": "lerna run test --scope @sentry/bun",
"test:update-snapshots": "lerna run test:update-snapshots",
Expand All @@ -45,6 +45,7 @@
"packages/browser-integration-tests",
"packages/bun",
"packages/core",
"packages/deno",
"packages/e2e-tests",
"packages/ember",
"packages/eslint-config-sdk",
Expand Down
18 changes: 18 additions & 0 deletions packages/deno/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
extends: ['../../.eslintrc.js'],
ignorePatterns: ['lib.deno.d.ts', 'scripts/*.mjs'],
rules: {
'@sentry-internal/sdk/no-optional-chaining': 'off',
'@sentry-internal/sdk/no-nullish-coalescing': 'off',
'@sentry-internal/sdk/no-unsupported-es6-methods': 'off',
'@sentry-internal/sdk/no-class-field-initializers': 'off',
},
overrides: [
{
files: ['./test/*.ts'],
rules: {
'import/no-unresolved': 'off',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we get rid of all the npm: prefixes we can probably enable this rule again.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything in /test/* is Deno typescript.
Some imports use denos URL imports which eslint doesn't understand

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checks out!

},
},
],
};
14 changes: 14 additions & 0 deletions packages/deno/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Copyright (c) 2023 Sentry (https://sentry.io) and individual contributors. All rights reserved.

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.
64 changes: 64 additions & 0 deletions packages/deno/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<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 Deno (Beta)

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

## Links

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

The Sentry Deno SDK is in beta. Please help us improve the SDK by [reporting any issues or giving us feedback](https://github.com/getsentry/sentry-javascript/issues).

## Usage

To use this SDK, call `Sentry.init(options)` as early as possible in the main entry module. This will initialize the SDK and
hook into the environment. Note that you can turn off almost all side effects using the respective options.

```javascript
import * as Sentry from 'npm:@sentry/deno';

Sentry.init({
dsn: '__DSN__',
// ...
});
```

To set context information or send manual events, use the exported functions of `@sentry/deno`. Note that these
functions will not perform any action before you have called `init()`:

```javascript
// Set user information, as well as tags and further extras
Sentry.configureScope(scope => {
scope.setExtra('battery', 0.7);
scope.setTag('user_mode', 'admin');
scope.setUser({ id: '4711' });
// scope.clear();
});

// Add a breadcrumb for future events
Sentry.addBreadcrumb({
message: 'My Breadcrumb',
// ...
});

// Capture exceptions, messages or manual events
Sentry.captureMessage('Hello, world!');
Sentry.captureException(new Error('Good bye'));
Sentry.captureEvent({
message: 'Manual',
stacktrace: [
// ...
],
});
```



1 change: 1 addition & 0 deletions packages/deno/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('../../jest/jest.config.js');
61 changes: 61 additions & 0 deletions packages/deno/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"name": "@sentry/deno",
"version": "7.73.0",
"description": "Official Sentry SDK for Deno",
"repository": "git://github.com/getsentry/sentry-javascript.git",
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/deno",
"author": "Sentry",
"license": "MIT",
"main": "build/index.js",
"module": "build/index.js",
"types": "build/index.d.ts",
"private": true,
"dependencies": {
"@sentry/core": "7.73.0",
"@sentry/browser": "7.73.0",
"@sentry/types": "7.73.0",
"@sentry/utils": "7.73.0",
"lru_map": "^0.3.3"
},
"devDependencies": {
"@types/node": "20.8.2",
"@rollup/plugin-commonjs": "^25.0.5",
"@rollup/plugin-typescript": "^11.1.5",
"rollup-plugin-dts": "^6.1.0"
},
"scripts": {
"deno-types": "node ./scripts/download-deno-types.mjs",
"build": "run-s build:transpile build:types",
"build:dev": "yarn build",
"build:transpile": "yarn deno-types && rollup -c rollup.config.js",
"build:types": "run-s deno-types build:types:tsc build:types:bundle",
"build:types:tsc": "tsc -p tsconfig.types.json",
"build:types:bundle": "rollup -c rollup.types.config.js",
"circularDepCheck": "madge --circular src/index.ts",
"clean": "rimraf build coverage",
"prefix": "yarn deno-types",
"fix": "run-s fix:eslint fix:prettier",
"fix:eslint": "eslint . --format stylish --fix",
"fix:prettier": "prettier --write \"{src,test,scripts}/**/**.ts\"",
"prelint": "yarn deno-types",
"lint": "run-s lint:prettier lint:eslint",
"lint:eslint": "eslint . --format stylish",
"lint:prettier": "prettier --check \"{src,test,scripts}/**/**.ts\"",
"install:deno": "node ./scripts/install-deno.mjs",
"test": "run-s deno-types install:deno test:types test:unit",
"test:types": "deno check ./build/index.js",
"test:unit": "deno test --allow-read --allow-run",
"test:unit:update": "deno test --allow-read --allow-write --allow-run -- --update"
},
"volta": {
"extends": "../../package.json"
},
"sideEffects": false,
"madge": {
"detectiveOptions": {
"ts": {
"skipTypeImports": true
}
}
}
}
24 changes: 24 additions & 0 deletions packages/deno/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import nodeResolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import sucrase from '@rollup/plugin-sucrase';

export default {
input: ['src/index.ts'],
output: {
dir: 'build',
sourcemap: true,
preserveModules: false,
strict: false,
freeze: false,
interop: 'auto',
format: 'esm',
banner: '/// <reference types="./index.d.ts" />',
},
plugins: [
nodeResolve({
extensions: ['.mjs', '.js', '.json', '.node', '.ts', '.tsx'],
}),
commonjs(),
sucrase({ transforms: ['typescript'] }),
],
};
17 changes: 17 additions & 0 deletions packages/deno/rollup.types.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import dts from 'rollup-plugin-dts';

export default {
input: './build/index.d.ts',
output: [{ file: 'build/index.d.ts', format: 'es' }],
plugins: [
dts({ respectExternal: true }),
// The bundled types contain a declaration for the __DEBUG_BUILD__ global
// This can result in errors about duplicate global declarations so we strip it out!
{
name: 'strip-global',
renderChunk(code) {
return { code: code.replace(/declare global \{\s*const __DEBUG_BUILD__: boolean;\s*\}/g, '') };
},
},
],
};
7 changes: 7 additions & 0 deletions packages/deno/scripts/download-deno-types.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { writeFileSync, existsSync } from 'fs';
import { download } from './download.mjs';

if (!existsSync('lib.deno.d.ts')) {
const code = await download('https://github.com/denoland/deno/releases/download/v1.37.1/lib.deno.d.ts');
writeFileSync('lib.deno.d.ts', code);
}
10 changes: 10 additions & 0 deletions packages/deno/scripts/download.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** Download a url to a string */
export async function download(url) {
try {
return await fetch(url).then(res => res.text());
} catch (e) {
// eslint-disable-next-line no-console
console.error('Failed to download', url, e);
process.exit(1);
}
}
26 changes: 26 additions & 0 deletions packages/deno/scripts/install-deno.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { execSync } from 'child_process';

import { download } from './download.mjs';

try {
execSync('deno --version', { stdio: 'inherit' });
} catch (_) {
// eslint-disable-next-line no-console
console.error('Deno is not installed. Installing...');
if (process.platform === 'win32') {
// TODO
// eslint-disable-next-line no-console
console.error('Please install Deno manually: https://docs.deno.com/runtime/manual/getting_started/installation');
process.exit(1);
} else {
const script = await download('https://deno.land/x/install/install.sh');

try {
execSync(script, { stdio: 'inherit' });
} catch (e) {
// eslint-disable-next-line no-console
console.error('Failed to install Deno', e);
process.exit(1);
}
}
}
Loading