Skip to content

Commit

Permalink
Added Sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
Wakeful-Cloud committed May 25, 2024
1 parent 24f2789 commit 8992e29
Show file tree
Hide file tree
Showing 13 changed files with 167 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ docker run -p 80:8080 beacon
| `VITE_HCAPTCHA_SITE_KEY` | `CADDY_HCAPTCHA_SITE_KEY` | The hCaptcha site key | Required ( :warning: **Must be manually set** :warning:; see [hCaptcha dashboard](https://dashboard.hcaptcha.com/sites)) |
| `VITE_SUPABASE_URL` | `CADDY_SUPABASE_URL` | The absolute Supabase API URL | Required (Automatically set by the setup script) |
| `VITE_SUPABASE_ANON_KEY` | `CADDY_SUPABASE_ANON_KEY` | The Supabase API anonymous key | Required (Automatically set by the setup script) |
| `VITE_SENTRY_DSN` | `CADDY_SENTRY_DSN` | The Sentry DSN | Optional (Automatically set by the setup script) |

### Technologies

Expand Down
2 changes: 1 addition & 1 deletion capacitor.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {CapacitorConfig} from "@capacitor/cli";

const config: CapacitorConfig = {
appId: "io.ionic.starter",
appName: "beacon",
appName: "Beacon",
webDir: "dist",
server: {
androidScheme: "https",
Expand Down
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
content="black-translucent"
/>

<meta name="mobile-web-app-capable" content="yes" />

<% if (!isDev) { %>
<script type="module" crossorigin src="/runtime-vars.js"></script>
<% } %>
Expand Down
4 changes: 2 additions & 2 deletions ionic.config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "beacon",
"name": "Beacon",
"integrations": {
"capacitor": {}
},
"type": "react-vite"
}
}
112 changes: 112 additions & 0 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
"@ionic/react": "^8.1.0",
"@ionic/react-router": "^8.1.0",
"@ionic/storage": "^4.0.0",
"@sentry/browser": "^8.4.0",
"@supabase/sentry-js-integration": "^0.2.0-beta.4",
"@supabase/supabase-js": "^2.43.1",
"@types/humanize-duration": "^3.27.4",
"@types/leaflet": "^1.9.12",
Expand Down
1 change: 1 addition & 0 deletions public/runtime-vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ window.__VITE_VARS__ = {
VITE_SUPABASE_URL: {{env "CADDY_SUPABASE_URL" | mustToRawJson}},
VITE_SUPABASE_ANON_KEY: {{env "CADDY_SUPABASE_ANON_KEY" | mustToRawJson}},
VITE_HCAPTCHA_SITE_KEY: {{env "CADDY_HCAPTCHA_SITE_KEY" | mustToRawJson}},
VITE_SENTRY_DSN: {{env "CADDY_SENTRY_DSN" | mustToRawJson}},
};
3 changes: 2 additions & 1 deletion scripts/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ export const writeEnvs = async () => {
frontendEnv,
`VITE_HCAPTCHA_SITE_KEY = "" # Required!
VITE_SUPABASE_URL = ${JSON.stringify(status.apiUrl)}
VITE_SUPABASE_ANON_KEY = ${JSON.stringify(status.anonKey)}`,
VITE_SUPABASE_ANON_KEY = ${JSON.stringify(status.anonKey)}
VITE_SENTRY_DSN = "" # Required!`,
{
flag: envFlags,
},
Expand Down
5 changes: 5 additions & 0 deletions src/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ interface ImportMetaEnv {
* The Supabase API key
*/
readonly VITE_SUPABASE_ANON_KEY: string;

/**
* The Sentry DSN
*/
readonly VITE_SENTRY_DSN?: string;
}

interface ImportMeta {
Expand Down
12 changes: 9 additions & 3 deletions src/lib/vars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,19 @@ const SUPABASE_URL = RUNTIME_VARS.VITE_SUPABASE_URL;
*/
const SUPABASE_ANON_KEY = RUNTIME_VARS.VITE_SUPABASE_ANON_KEY;

/**
* Sentry DSN
*/
const SENTRY_DSN = RUNTIME_VARS.VITE_SENTRY_DSN;

// Validate variables
const vars = {
VERSION,
GIT_COMMIT,
GIT_BRANCH,
GIT_COMMIT,
HCAPTCHA_SITE_KEY,
SUPABASE_URL,
SUPABASE_ANON_KEY,
SUPABASE_URL,
VERSION,
};

const missing = [];
Expand All @@ -65,6 +70,7 @@ export {
GIT_BRANCH,
GIT_COMMIT,
HCAPTCHA_SITE_KEY,
SENTRY_DSN,
SUPABASE_ANON_KEY,
SUPABASE_URL,
VERSION,
Expand Down
28 changes: 28 additions & 0 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,38 @@ import "~/lib/geolocation";

import {IonApp, isPlatform, setupIonicReact} from "@ionic/react";
import {IonReactRouter} from "@ionic/react-router";
import {browserTracingIntegration, init as sentryInit} from "@sentry/browser";
import {SupabaseIntegration} from "@supabase/sentry-js-integration";
import {SupabaseClient} from "@supabase/supabase-js";
import {StrictMode} from "react";
import {createRoot} from "react-dom/client";

import {App} from "~/app";
import {SENTRY_DSN, SUPABASE_URL} from "~/lib/vars";

// Setup Sentry
if (SENTRY_DSN !== undefined) {
sentryInit({
dsn: SENTRY_DSN,
integrations: [
new SupabaseIntegration(SupabaseClient, {
tracing: true,
breadcrumbs: true,
errors: true,
}),
browserTracingIntegration({
/**
* Callback to determine if a request should create a span
* @param url Request URL
* @returns Whether a span should be created
*/
shouldCreateSpanForRequest: url =>
!url.startsWith(`${SUPABASE_URL}/rest`),
}),
],
tracesSampleRate: 1,
});
}

// Setup React
const container = document.getElementById("root");
Expand Down
2 changes: 0 additions & 2 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ export const Index: FC = () => {
className="my-2"
color="dark"
fill="outline"
target="_blank"
href="/terms-and-conditions"
>
<IonIcon
Expand All @@ -194,7 +193,6 @@ export const Index: FC = () => {
className="my-2"
color="dark"
fill="outline"
target="_blank"
href="/privacy-policy"
>
<IonIcon slot="start" ios={shieldOutline} md={shieldSharp} />
Expand Down
4 changes: 2 additions & 2 deletions src/pages/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,11 @@ export const Settings: FC = () => {
<IonLabel>Bug report/feature request</IonLabel>
</IonItem>

<IonItem target="_blank" href="/terms-and-conditions">
<IonItem href="/terms-and-conditions">
<IonLabel>Terms and Conditions</IonLabel>
</IonItem>

<IonItem target="_blank" href="/privacy-policy">
<IonItem href="/privacy-policy">
<IonLabel>Privacy Policy</IonLabel>
</IonItem>
</IonItemGroup>
Expand Down

0 comments on commit 8992e29

Please sign in to comment.