Skip to content

Commit

Permalink
Add Sentry: Error Tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
starsep committed Feb 12, 2024
1 parent 0fd323b commit 2764d22
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 0 deletions.
121 changes: 121 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"@maplibre/maplibre-gl-geocoder": "^1.5.0",
"@mdi/js": "^7.4.47",
"@mdi/react": "^1.6.1",
"@sentry/react": "^7.100.1",
"bulma": "^0.9.4",
"bulma-checkradio": "^2.1.3",
"events": "^3.3.0",
Expand Down
2 changes: 2 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import React from "react";
import ReactDOM from "react-dom/client";
import "~/i18n";
import "~/mystyles.css";
import initSentry from "~/sentry";
import Main from "./Main";

initSentry();
const root = ReactDOM.createRoot(
document.getElementById("root") as HTMLElement,
);
Expand Down
29 changes: 29 additions & 0 deletions src/sentry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as Sentry from "@sentry/react";

export default function initSentry() {
if (shouldEnableSentry()) {
Sentry.init({
dsn: "https://7f263ca9541cbb26b1fe3228e80a8b6f@o4506736017539072.ingest.sentry.io/4506736027959296",
integrations: [Sentry.browserTracingIntegration()],
// Performance Monitoring
tracesSampleRate: 1.0, // Capture 100% of the transactions
// Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled
tracePropagationTargets: [
"localhost:5173",
/^https:\/\/(dev.)?openaedmap\.org/,
],
});
}
}

function shouldEnableSentry(): boolean {
const doNotTrack =
navigator.doNotTrack === "1" ||
navigator.doNotTrack === "yes" ||
navigator.doNotTrack === "true";

This comment has been minimized.

Copy link
@Zaczero

Zaczero Feb 13, 2024

Member

as per https://developer.mozilla.org/en-US/docs/Web/API/navigator/doNotTrack it's enough to check for "1", "yes" is very-very old behavior (before Firefox 32).

This comment has been minimized.

Copy link
@starsep

starsep Feb 13, 2024

Author Member

Indeed, simplified

const globalPrivacyControl =
navigator.globalPrivacyControl === true ||

Check failure on line 25 in src/sentry.ts

View workflow job for this annotation

GitHub Actions / deploy

Property 'globalPrivacyControl' does not exist on type 'Navigator'.
navigator.globalPrivacyControl === "true";

Check failure on line 26 in src/sentry.ts

View workflow job for this annotation

GitHub Actions / deploy

Property 'globalPrivacyControl' does not exist on type 'Navigator'.

This comment has been minimized.

Copy link
@Zaczero

Zaczero Feb 13, 2024

Member

The property is only boolean, this check is redundant

This comment has been minimized.

Copy link
@starsep

starsep Feb 13, 2024

Author Member

Indeed, simplified

// return !doNotTrack && !globalPrivacyControl;
return true;
}

0 comments on commit 2764d22

Please sign in to comment.