Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

add sentry to current console.log

Sara Vieirac43e2c75846f
diff --git a/.eslintrc.json b/.eslintrc.json
index 1f8b5d3606..697ebd0514 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -25,6 +25,7 @@
}
},
"rules": {
+ "no-console": 2,
// It's too dumb to understand properly what's defined in ts
"react/prop-types": 0,
"@typescript-eslint/no-unused-vars": [
diff --git a/app/entry.client.tsx b/app/entry.client.tsx
index a03dffbf9c..8edb41b9a0 100644
--- a/app/entry.client.tsx
+++ b/app/entry.client.tsx
@@ -1,12 +1,7 @@
import { hydrate } from "react-dom";
import { RemixBrowser } from "@remix-run/react";
-import * as Sentry from "@sentry/browser";
-import { BrowserTracing } from "@sentry/tracing";
+import { initSentry } from "./shared/sentry";
-Sentry.init({
- dsn: "https://[email protected]/6530661",
- integrations: [new BrowserTracing()],
- tracesSampleRate: 1.0,
-});
+initSentry();
hydrate(<RemixBrowser />, document);
diff --git a/app/services/auth.server.ts b/app/services/auth.server.ts
index eaa9389177..352cad7334 100644
--- a/app/services/auth.server.ts
+++ b/app/services/auth.server.ts
@@ -10,6 +10,7 @@ import {
createOrLoginWithGithub,
createOrLoginWithGoogle,
} from "~/shared/db/user.server";
+import { sentryException } from "~/shared/sentry";
const url = `${
process.env.VERCEL_URL
@@ -60,8 +61,15 @@ if (process.env.DEV_LOGIN === "true") {
try {
const user = await createOrLoginWithDev(secret);
return user;
- } catch (e) {
- console.log(e);
+ } catch (error: unknown) {
+ if (error instanceof Error) {
+ sentryException({
+ message: error.message,
+ extra: {
+ loginMethod: "dev",
+ },
+ });
+ }
}
}
diff --git a/app/shared/sentry.ts b/app/shared/sentry.ts
new file mode 100644
index 0000000000..980eccb89c
--- /dev/null
+++ b/app/shared/sentry.ts
@@ -0,0 +1,49 @@
+import * as Sentry from "@sentry/browser";
+import { Extras } from "@sentry/types";
+
+import { BrowserTracing } from "@sentry/tracing";
+
+export const initSentry = () =>
+ Sentry.init({
+ dsn: "https://[email protected]/6530661",
+ integrations: [new BrowserTracing()],
+ tracesSampleRate: 1.0,
+ });
+
+type SentryHelperProps = {
+ message: string;
+ extra?: Extras;
+ skipLogging?: boolean;
+};
+
+export const sentryMessage = ({
+ message,
+ extra,
+ skipLogging = false,
+}: SentryHelperProps) => {
+ Sentry.withScope((scope) => {
+ if (extra) scope.setExtras(extra);
+ Sentry.captureMessage(message);
+ });
+
+ if (skipLogging !== true) {
+ // eslint-disable-next-line no-console
+ console.log(message);
+ }
+};
+
+export const sentryException = ({
+ message,
+ extra,
+ skipLogging = false,
+}: SentryHelperProps) => {
+ Sentry.withScope((scope) => {
+ if (extra) scope.setExtras(extra);
+ Sentry.captureException(message);
+ });
+
+ if (skipLogging !== true) {
+ // eslint-disable-next-line no-console
+ console.error(message);
+ }
+};