Skip to content

Instantly share code, notes, and snippets.

@floehopper
Last active January 6, 2023 10:50
Show Gist options
  • Select an option

  • Save floehopper/1d0d1c50c7fa31b143dea46b66eaec66 to your computer and use it in GitHub Desktop.

Select an option

Save floehopper/1d0d1c50c7fa31b143dea46b66eaec66 to your computer and use it in GitHub Desktop.

Revisions

  1. floehopper revised this gist Sep 19, 2022. 1 changed file with 0 additions and 3 deletions.
    3 changes: 0 additions & 3 deletions package.json
    Original file line number Diff line number Diff line change
    @@ -4,11 +4,8 @@
    "scripts": {
    "dev": "svelte-kit dev",
    "build": "export VITE_LATEST_SHA=`git rev-parse HEAD` && svelte-kit build",
    // ...
    },
    "dependencies": {
    "rollbar": "^2.24.1",
    // ...
    },
    // ...
    }
  2. floehopper revised this gist Sep 19, 2022. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions package.json
    Original file line number Diff line number Diff line change
    @@ -6,5 +6,9 @@
    "build": "export VITE_LATEST_SHA=`git rev-parse HEAD` && svelte-kit build",
    // ...
    },
    "dependencies": {
    "rollbar": "^2.24.1",
    // ...
    },
    // ...
    }
  3. floehopper created this gist Sep 19, 2022.
    31 changes: 31 additions & 0 deletions Rollbar.svelte
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    <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>
    22 changes: 22 additions & 0 deletions hooks.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    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,
    });
    }
    10 changes: 10 additions & 0 deletions package.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    {
    "name": "myapp",
    "version": "0.0.1",
    "scripts": {
    "dev": "svelte-kit dev",
    "build": "export VITE_LATEST_SHA=`git rev-parse HEAD` && svelte-kit build",
    // ...
    },
    // ...
    }