Skip to content

Commit

Permalink
Chore/sentry (#476)
Browse files Browse the repository at this point in the history
* source map, webpack, stories, babel

* fixed jest tests

* hot reload

* set up

* getplatform func

* configured

* initialized

* test error dev

* test error dev removed

* webpack plugin removed

* refactored

* after review

* separated error and stacktarce

* platform on back

* .
  • Loading branch information
EduardZaydler authored Jan 22, 2024
1 parent 1017cee commit 17d714c
Show file tree
Hide file tree
Showing 6 changed files with 378 additions and 100 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"dependencies": {
"@clavinjune/codemirror-metricsql": "^0.0.1-dev.1010230001",
"@lezer/highlight": "^1.1.6",
"@sentry/react": "^7.81.1",
"@skbkontur/react-icons": "^5.2.9",
"@skbkontur/react-stack-layout": "1.0.3",
"@skbkontur/react-ui": "^4.16.0",
Expand Down
14 changes: 11 additions & 3 deletions src/Containers/ErrorContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import React, { ReactElement } from "react";
import { Layout, LayoutContent, LayoutTitle } from "../Components/Layout/Layout";

export default function ErrorContainer(): ReactElement {
interface IErrorContainerProps {
message: string;
title: string;
}

export default function ErrorContainer({
message = "Page not found",
title = "404",
}: IErrorContainerProps): ReactElement {
return (
<Layout>
<LayoutContent>
<LayoutTitle>404</LayoutTitle>
<p>Page not found</p>
<LayoutTitle>{title}</LayoutTitle>
<p>{message}</p>
</LayoutContent>
</Layout>
);
Expand Down
7 changes: 7 additions & 0 deletions src/Domain/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,11 @@ export interface Config {
isPlottingAvailable: boolean;
isSubscriptionToAllTagsAvailable: boolean;
};
sentry?: { dsn: string; platform: Platform };
}

export enum Platform {
DEV = "dev",
STAGING = "staging",
PROD = "prod",
}
21 changes: 16 additions & 5 deletions src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,32 @@ import { LocaleContext } from "@skbkontur/react-ui/lib/locale/LocaleContext";
import MoiraApi from "./Api/MoiraApi";
import { ApiProvider } from "./Api/MoiraApiInjection";
import checkMobile from "./helpers/check-mobile";
import * as Sentry from "@sentry/react";
import ErrorContainer from "./Containers/ErrorContainer";
import { initSentry } from "./helpers/initSentry";

import "./style.less";

const root = document.getElementById("root");

const moiraApi = new MoiraApi("/api");

initSentry(moiraApi);

const root = document.getElementById("root");

const render = (Component: ComponentType) => {
if (root !== null) {
ReactDOM.render(
<BrowserRouter>
<LocaleContext.Provider value={{ langCode: LangCodes.en_GB }}>
<ApiProvider value={moiraApi}>
<Component />
</ApiProvider>
<Sentry.ErrorBoundary
fallback={({ error, componentStack }) => (
<ErrorContainer title={error.toString()} message={componentStack} />
)}
>
<ApiProvider value={moiraApi}>
<Component />
</ApiProvider>
</Sentry.ErrorBoundary>
</LocaleContext.Provider>
</BrowserRouter>,
root
Expand Down
28 changes: 28 additions & 0 deletions src/helpers/initSentry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import MoiraApi from "../Api/MoiraApi";
import * as Sentry from "@sentry/react";

const getDSNConfig = async (api: MoiraApi) => {
try {
const res = await api.getConfig();
return res.sentry;
} catch (error) {
return Promise.reject("Error getting DSN");
}
};

export const initSentry = async (api: MoiraApi) => {
const config = await getDSNConfig(api);
if (!config) {
return;
}

const { dsn, platform } = config;
const isLocalPlatform = platform !== undefined;
Sentry.init({
dsn,
debug: isLocalPlatform,
environment: platform,
enabled: !isLocalPlatform,
tracesSampleRate: 1.0,
});
};
Loading

0 comments on commit 17d714c

Please sign in to comment.