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(wasm): Adds a WASM integration #3080

Merged
merged 16 commits into from
Jan 18, 2021
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
5 changes: 5 additions & 0 deletions .craft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ targets:
onlyIfPresent: /^sentry-angular-.*\.tgz$/
config:
canonical: 'npm:@sentry/angular'
- name: registry
type: sdk
onlyIfPresent: /^sentry-wasm-.*\.tgz$/
config:
canonical: 'npm:@sentry/wasm'
- name: aws-lambda-layer
includeNames: /^sentry-node-serverless-\d+(\.\d+)*\.zip$/
layerName: SentryNodeServerlessSDK
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"packages/types",
"packages/typescript",
"packages/utils",
"packages/wasm",
"packages/vue"
],
"devDependencies": {
Expand Down Expand Up @@ -65,7 +66,8 @@
"typescript": "3.7.5"
},
"resolutions": {
"**/agent-base": "5"
"**/agent-base": "5",
"**/jest-environment-node": "24"
},
"version": "0.0.0"
}
22 changes: 22 additions & 0 deletions packages/types/src/debugMeta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Holds meta information to customize the behavior of sentry's event processing.
**/
export interface DebugMeta {
images?: Array<DebugImage>;
}

/**
* Possible choices for debug images.
*/
export type DebugImageType = 'wasm' | 'macho' | 'elf' | 'pe';

/**
* References to debug images.
*/
export interface DebugImage {
type: DebugImageType;
debug_id: string;
code_id?: string | null;
code_file: string;
debug_file?: string | null;
}
2 changes: 2 additions & 0 deletions packages/types/src/event.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Breadcrumb } from './breadcrumb';
import { Contexts } from './context';
import { DebugMeta } from './debugMeta';
import { Exception } from './exception';
import { Extras } from './extra';
import { Primitive } from './misc';
Expand Down Expand Up @@ -42,6 +43,7 @@ export interface Event {
type?: EventType;
spans?: Span[];
measurements?: Measurements;
debug_meta?: DebugMeta;
}

/** JSDoc */
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export { Breadcrumb, BreadcrumbHint } from './breadcrumb';
export { Client } from './client';
export { Context, Contexts } from './context';
export { Dsn, DsnComponents, DsnLike, DsnProtocol } from './dsn';
export { DebugImage, DebugImageType, DebugMeta } from './debugMeta';
export { ExtendedError } from './error';
export { Event, EventHint } from './event';
export { EventProcessor } from './eventprocessor';
Expand Down
2 changes: 2 additions & 0 deletions packages/types/src/stackframe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ export interface StackFrame {
pre_context?: string[];
post_context?: string[];
in_app?: boolean;
instruction_addr?: string;
addr_mode?: string;
vars?: { [key: string]: any };
}
29 changes: 29 additions & 0 deletions packages/wasm/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module.exports = {
root: true,
env: {
es6: true,
},
parserOptions: {
ecmaVersion: 2018,
},
extends: ['@sentry-internal/sdk'],
ignorePatterns: ['build/**', 'dist/**', 'esm/**', 'examples/**', 'scripts/**'],
overrides: [
{
files: ['*.ts', '*.tsx', '*.d.ts'],
parserOptions: {
project: './tsconfig.json',
},
},
{
files: ['test/**'],
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
},
},
],
rules: {
'max-lines': 'off',
},
};
4 changes: 4 additions & 0 deletions packages/wasm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.js.map
*.d.ts
!test/*.js
!.eslintrc.js
6 changes: 6 additions & 0 deletions packages/wasm/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*
!*.js.map
!*.d.ts
!*.js
!/esm/**/*
jest.config.js
29 changes: 29 additions & 0 deletions packages/wasm/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
MIT License

Copyright (c) 2021, Sentry
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22 changes: 22 additions & 0 deletions packages/wasm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<p align="center">
<a href="https://sentry.io" target="_blank" align="center">
<img src="https://sentry-brand.storage.googleapis.com/sentry-logo-black.png" width="280">
</a>
<br />
</p>

# Sentry JavaScript WebAssembly Support

[![npm version](https://img.shields.io/npm/v/@sentry/wasm.svg)](https://www.npmjs.com/package/@sentry/wasm)
[![npm dm](https://img.shields.io/npm/dm/@sentry/wasm.svg)](https://www.npmjs.com/package/@sentry/wasm)
[![npm dt](https://img.shields.io/npm/dt/@sentry/wasm.svg)](https://www.npmjs.com/package/@sentry/wasm)
[![typedoc](https://img.shields.io/badge/docs-typedoc-blue.svg)](http://getsentry.github.io/sentry-javascript/)

## Links

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

## General

This package provides support for WebAssembly in stack traces.
6 changes: 6 additions & 0 deletions packages/wasm/jest-puppeteer.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
server: {
command: 'node test/server.js',
port: process.env.PORT,
},
};
69 changes: 69 additions & 0 deletions packages/wasm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"name": "@sentry/wasm",
"version": "5.29.2",
"description": "Support for WASM.",
"repository": "git://github.com/getsentry/sentry-javascript.git",
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/wasm",
"author": "Sentry",
"license": "MIT",
"engines": {
"node": ">=6"
mitsuhiko marked this conversation as resolved.
Show resolved Hide resolved
},
"main": "dist/index.js",
"module": "esm/index.js",
"types": "dist/index.d.ts",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@sentry/browser": "5.29.2",
"@sentry/types": "5.29.2",
"tslib": "^1.9.3"
},
"devDependencies": {
"@sentry-internal/eslint-config-sdk": "5.29.2",
"@types/jest-environment-puppeteer": "^4.4.0",
"@types/puppeteer": "^5.4.0",
"eslint": "7.6.0",
"express": "^4.17.1",
"jest": "^24.7.1",
"jest-puppeteer": "^4.4.0",
"npm-run-all": "^4.1.2",
"prettier": "1.19.0",
"puppeteer": "^5.5.0",
"rimraf": "^2.6.3",
"rollup": "^1.10.1",
"rollup-plugin-commonjs": "^9.3.4",
"rollup-plugin-node-resolve": "^4.2.3",
"rollup-plugin-terser": "^4.0.4",
"rollup-plugin-typescript2": "^0.21.0",
"typescript": "3.7.5"
},
"scripts": {
"build": "run-p build:es5 build:esm build:bundle",
"build:es5": "tsc -p tsconfig.build.json",
"build:esm": "tsc -p tsconfig.esm.json",
"build:watch": "run-p build:watch:es5 build:watch:esm",
"build:watch:es5": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
"build:watch:esm": "tsc -p tsconfig.esm.json -w --preserveWatchOutput",
"build:bundle": "rollup --config",
"clean": "rimraf dist esm coverage *.js *.js.map *.d.ts",
"link:yarn": "yarn link",
"lint": "run-s lint:prettier lint:eslint",
"lint:prettier": "prettier --check \"{src,test}/**/*.ts\"",
"lint:eslint": "eslint . --cache --cache-location '../../eslintcache/' --format stylish",
"fix": "run-s fix:eslint fix:prettier",
"fix:prettier": "prettier --write \"{src,test}/**/*.ts\"",
"fix:eslint": "eslint . --format stylish --fix",
"test": "PORT=1337 jest",
"test:watch": "jest --watch",
"pack": "npm pack"
},
"volta": {
"extends": "../../package.json"
},
"jest": {
"preset": "jest-puppeteer"
},
"sideEffects": false
}
83 changes: 83 additions & 0 deletions packages/wasm/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { terser } from 'rollup-plugin-terser';
import typescript from 'rollup-plugin-typescript2';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';

const terserInstance = terser({
mangle: {
// captureExceptions and captureMessage are public API methods and they don't need to be listed here
// as mangler doesn't touch user-facing thing, however sentryWrapped is not, and it would be mangled into a minified version.
// We need those full names to correctly detect our internal frames for stripping.
// I listed all of them here just for the clarity sake, as they are all used in the frames manipulation process.
reserved: ['captureException', 'captureMessage', 'sentryWrapped'],
properties: false,
},
});

const plugins = [
typescript({
tsconfig: 'tsconfig.build.json',
tsconfigOverride: {
compilerOptions: {
declaration: false,
module: 'ES2015',
paths: {
'@sentry/utils': ['../utils/src'],
'@sentry/core': ['../core/src'],
'@sentry/hub': ['../hub/src'],
'@sentry/types': ['../types/src'],
'@sentry/minimal': ['../minimal/src'],
},
},
},
include: ['*.ts+(|x)', '**/*.ts+(|x)', '../**/*.ts+(|x)'],
}),
resolve({
mainFields: ['module'],
}),
commonjs(),
];

function mergeIntoSentry() {
return `
__window.Sentry = __window.Sentry || {};
__window.Sentry.Integrations = __window.Sentry.Integrations || {};
for (var key in exports) {
if (Object.prototype.hasOwnProperty.call(exports, key)) {
__window.Sentry.Integrations[key] = exports[key];
}
}
`;
}

function loadAllIntegrations() {
const builds = [];
[
{
extension: '.js',
plugins,
},
{
extension: '.min.js',
plugins: [...plugins, terserInstance],
},
].forEach(build => {
builds.push({
input: `src/index.ts`,
output: {
banner: '(function (__window) {',
intro: 'var exports = {};',
outro: mergeIntoSentry(),
footer: '}(window));',
file: `build/wasm${build.extension}`,
format: 'cjs',
sourcemap: true,
strict: false,
},
plugins: build.plugins,
});
});
return builds;
}

export default loadAllIntegrations();
Loading