Wasm

Sentry's Wasm integration enhances the Browser SDK, and allows it to provide more detailed debug information not only for the error itself, but also for the entire module it was executed from. It includes things like Debug IDs, Debug Files, Code IDs, Code Files and memory addresses.

Install @sentry/browser and @sentry/wasm using yarn or npm:

Copied
npm install --save @sentry/browser @sentry/wasm

and afterwards use it like this:

Copied
import * as Sentry from "@sentry/browser";
import { wasmIntegration } from "@sentry/wasm";

Sentry.init({
  dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
  integrations: [wasmIntegration()],
});

// Now, whenever any code from WebAssembly module will throw an error,
// it'll get captured and it'll contain all the necessary information.

function executeInternalWasmStuff() {
  throw new Error("whoops");
}

const { instance } = await WebAssembly.instantiateStreaming(
  fetch("very-complex-module.wasm"),
  {
    env: {
      external_func: executeInternalWasmStuff,
    },
  }
);

instance.exports.internal_func();

If you are curious how Wasm modules look from the inside, here's a quick example written in Rust:

Copied
#![no_std]

#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
    loop {}
}

extern "C" {
    pub fn external_func();
}

#[no_mangle]
pub fn internal_func() {
    unsafe {
        external_func();
    }
}

For more details on how to compile Rust to Wasm, see Compiling from Rust to WebAssembly MDN documentation.

Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").