Skip to content

Commit

Permalink
Merge pull request #72 from nushydude/71-integrated-sentry-to-ui
Browse files Browse the repository at this point in the history
Integrate Sentry and add some unit tests with zod validation
  • Loading branch information
nushydude authored Jun 27, 2024
2 parents d35833d + c624e18 commit 166ca68
Show file tree
Hide file tree
Showing 11 changed files with 448 additions and 18 deletions.
211 changes: 211 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 @@ -3,6 +3,7 @@
"version": "1.0.0",
"private": true,
"dependencies": {
"@sentry/react": "^8.12.0",
"@tanstack/react-query": "^5.8.7",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
Expand Down
5 changes: 4 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as Sentry from '@sentry/react';
import { Router } from 'react-router-dom';
import { createBrowserHistory } from 'history';
import { ToastContainer } from 'react-toastify';
Expand All @@ -9,7 +10,7 @@ import { Footer } from './components/Footer';

const history = createBrowserHistory();

export const App = () => {
const App = () => {
useOneSignal();

return (
Expand All @@ -28,3 +29,5 @@ export const App = () => {
</Router>
);
};

export default Sentry.withProfiler(App);
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ const buildNumber = isProduction ? process.env.REACT_APP_BUILD_NUMBER : 'dev';
export const config = {
API_URI: 'https://crypto-stdev-express.vercel.app',
BUILD_NUMBER: buildNumber,
SENTRY_DSN: process.env.REACT_APP_SENTRY_DSN,
};
19 changes: 18 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
import * as Sentry from "@sentry/react";
import React from 'react';
import ReactDOM from 'react-dom/client';
import { Chart as ChartJS, registerables } from 'chart.js';
import 'react-toastify/dist/ReactToastify.css';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import './index.css';
import { App } from './App';
import App from './App';
// import * as serviceWorkerRegistration from './serviceWorkerRegistration';
import reportWebVitals from './reportWebVitals';
import { AppSettingsProvider } from './providers/AppSettingsProvider';
import UserProvider from './providers/UserProvider';
import { config } from "./config";

Sentry.init({
dsn: config.SENTRY_DSN,
integrations: [
Sentry.browserTracingIntegration(),
Sentry.replayIntegration(),
],
// Performance Monitoring
tracesSampleRate: 1.0, // Capture 100% of the transactions
// Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled
tracePropagationTargets: ["localhost", config.API_URI],
// Session Replay
replaysSessionSampleRate: 0.1, // This sets the sample rate at 10%. You may want to change it to 100% while in development and then sample at a lower rate in production.
replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur.
});

ChartJS.register(...registerables);

Expand Down
14 changes: 12 additions & 2 deletions src/utils/fetchSymbols.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
import { z } from 'zod';
import * as Sentry from '@sentry/react';
import { config } from '../config';
import { DEFAULT_SYMBOLS } from '../consts/DefaultSymbols';

// Define the Zod schema for the response
const responseSchema = z.object({
symbols: z.array(z.string()),
});

export const fetchSymbols = async (): Promise<Array<string>> => {
try {
const response = await fetch(`${config.API_URI}/api/symbols`);
const jsonResponse = await response.json();

const { symbols } = await response.json();
// Validate the response
const parsedResponse = responseSchema.parse(jsonResponse);

return symbols;
return parsedResponse.symbols;
} catch (error) {
Sentry.captureException(error);
return DEFAULT_SYMBOLS;
}
};
Loading

0 comments on commit 166ca68

Please sign in to comment.