Skip to content

Instantly share code, notes, and snippets.

@floehopper
Last active January 6, 2023 10:50
Show Gist options
  • Save floehopper/1d0d1c50c7fa31b143dea46b66eaec66 to your computer and use it in GitHub Desktop.
Save floehopper/1d0d1c50c7fa31b143dea46b66eaec66 to your computer and use it in GitHub Desktop.
Rollbar configuration in a SvelteKit app - both client-side & server-side
import "dotenv/config";
import Rollbar from "rollbar";
import { dev, mode } from "$app/env";
const rollbar = new Rollbar({
accessToken: process.env.ROLLBAR_POST_SERVER_ITEM_ACCESS_TOKEN,
payload: {
environment: mode,
},
});
/** @type {import('@sveltejs/kit').HandleError} */
export async function handleError({ error, event }) {
const headers = {};
event.request.headers.forEach((v, k) => (headers[k] = v));
if (!dev)
rollbar.error(error, {
headers: headers,
url: event.url,
method: event.request.method,
});
}
{
"name": "myapp",
"version": "0.0.1",
"scripts": {
"dev": "svelte-kit dev",
"build": "export VITE_LATEST_SHA=`git rev-parse HEAD` && svelte-kit build",
},
"dependencies": {
"rollbar": "^2.24.1",
},
}
<script>
/* eslint-disable */
import { mode } from "$app/env";
import { onMount } from "svelte";
const rollbarAccessToken = import.meta.env
.VITE_ROLLBAR_POST_CLIENT_ITEM_ACCESS_TOKEN;
const codeVersion = import.meta.env.VITE_LATEST_SHA;
onMount(() => {
let _rollbarConfig = {
accessToken: rollbarAccessToken,
captureUncaught: true,
captureUnhandledRejections: true,
payload: {
environment: mode,
client: {
javascript: {
code_version: codeVersion,
source_map_enabled: true,
guess_uncaught_frames: true,
},
},
},
};
// Insert Rollbar snippet here
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment