Skip to content

Commit

Permalink
feat(sentry): added sentry (#443)
Browse files Browse the repository at this point in the history
  • Loading branch information
StanGirard committed Jul 1, 2023
1 parent bf60167 commit fbd1e17
Show file tree
Hide file tree
Showing 10 changed files with 419 additions and 10 deletions.
2 changes: 1 addition & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ WORKDIR /code

COPY ./requirements.txt /code/requirements.txt

RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt --timeout 100
RUN pip install --no-cache-dir -r /code/requirements.txt --timeout 100

#You may need to run `chmod +x ./backend/scripts/start.sh` on your host machine if you get a permission error
COPY ./scripts/start.sh /code/scripts/start.sh
Expand Down
14 changes: 13 additions & 1 deletion backend/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os

import pypandoc
import sentry_sdk
from fastapi import FastAPI, HTTPException
from fastapi.responses import JSONResponse
import pypandoc
from logger import get_logger
from middlewares.cors import add_cors_middleware
from routes.api_key_routes import api_key_router
Expand All @@ -15,6 +17,15 @@

logger = get_logger(__name__)

if os.getenv("SENTRY_DSN"):
sentry_sdk.init(
dsn=os.getenv("SENTRY_DSN"),
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for performance monitoring.
# We recommend adjusting this value in production,
traces_sample_rate=1.0,
)

app = FastAPI()

add_cors_middleware(app)
Expand All @@ -26,6 +37,7 @@
async def startup_event():
pypandoc.download_pandoc()


app.include_router(brain_router)
app.include_router(chat_router)
app.include_router(crawl_router)
Expand Down
2 changes: 1 addition & 1 deletion backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Markdown==3.4.3
openai==0.27.6
pdf2image==1.16.3
pypdf==3.8.1
streamlit==1.22.0
StrEnum==0.4.10
supabase==1.0.3
tiktoken==0.4.0
Expand All @@ -23,3 +22,4 @@ asyncpg==0.27.0
flake8==6.0.0
flake8-black==0.3.6
sentence_transformers>=2.0.0
sentry-sdk==1.26.0
3 changes: 3 additions & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts

# Sentry Auth Token
.sentryclirc
38 changes: 38 additions & 0 deletions frontend/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,41 @@
const nextConfig = {};

module.exports = nextConfig;


// Injected content via Sentry wizard below

const { withSentryConfig } = require("@sentry/nextjs");

module.exports = withSentryConfig(
module.exports,
{
// For all available options, see:
// https://github.com/getsentry/sentry-webpack-plugin#options

// Suppresses source map uploading logs during build
silent: true,

org: "quivr-0f",
project: "javascript-nextjs",
},
{
// For all available options, see:
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/

// Upload a larger set of source maps for prettier stack traces (increases build time)
widenClientFileUpload: true,

// Transpiles SDK to be compatible with IE11 (increases bundle size)
transpileClientSDK: true,

// Routes browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers (increases server load)
tunnelRoute: "/monitoring",

// Hides source maps from generated client bundles
hideSourceMaps: true,

// Automatically tree-shake Sentry logger statements to reduce bundle size
disableLogger: true,
}
);
9 changes: 5 additions & 4 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@radix-ui/react-dialog": "^1.0.3",
"@radix-ui/react-toast": "^1.1.3",
"@radix-ui/react-tooltip": "^1.0.6",
"@sentry/nextjs": "^7.57.0",
"@supabase/auth-helpers-nextjs": "^0.6.1",
"@supabase/auth-ui-react": "^0.4.2",
"@supabase/auth-ui-shared": "^0.1.6",
Expand Down Expand Up @@ -61,13 +62,13 @@
},
"devDependencies": {
"@tailwindcss/typography": "^0.5.9",
"@types/next": "^9.0.0",
"husky": "^8.0.3",
"vitest": "^0.32.2",
"@testing-library/react": "^14.0.0",
"@types/next": "^9.0.0",
"@vitejs/plugin-react": "^4.0.1",
"dotenv": "^16.3.1",
"husky": "^8.0.3",
"jsdom": "^22.1.0",
"react-icons": "^4.8.0"
"react-icons": "^4.8.0",
"vitest": "^0.32.2"
}
}
38 changes: 38 additions & 0 deletions frontend/sentry.client.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// This file configures the initialization of Sentry on the client.
// The config you add here will be used whenever a users loads a page in their browser.
// https://docs.sentry.io/platforms/javascript/guides/nextjs/

import * as Sentry from "@sentry/nextjs";

// Get the DSN from the environment variable
const SENTRY_DSN = process.env.SENTRY_DSN;

// Only initialize Sentry if the DSN is set
if (SENTRY_DSN) {
Sentry.init({
dsn: SENTRY_DSN,

// Adjust this value in production, or use tracesSampler for greater control
tracesSampleRate: 1,

// Setting this option to true will print useful information to the console while you're setting up Sentry.
debug: false,

replaysOnErrorSampleRate: 1.0,

// This sets the sample rate to be 10%. You may want this to be 100% while
// in development and sample at a lower rate in production
replaysSessionSampleRate: 0.1,

// You can remove this option if you're not planning to use the Sentry Session Replay feature:
integrations: [
new Sentry.Replay({
// Additional Replay configuration goes in here, for example:
maskAllText: true,
blockAllMedia: true,
}),
],
});
} else {
console.log("Sentry is not initialized as SENTRY_DSN is not set");
}
19 changes: 19 additions & 0 deletions frontend/sentry.edge.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as Sentry from "@sentry/nextjs";

// Get the DSN from the environment variable
const SENTRY_DSN = process.env.SENTRY_DSN;

// Only initialize Sentry if the DSN is set
if (SENTRY_DSN) {
Sentry.init({
dsn: SENTRY_DSN,

// Adjust this value in production, or use tracesSampler for greater control
tracesSampleRate: 1,

// Setting this option to true will print useful information to the console while you're setting up Sentry.
debug: false,
});
} else {
console.log("Sentry is not initialized on the server as SENTRY_DSN is not set");
}
19 changes: 19 additions & 0 deletions frontend/sentry.server.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as Sentry from "@sentry/nextjs";

// Get the DSN from the environment variable
const SENTRY_DSN = process.env.SENTRY_DSN;

// Only initialize Sentry if the DSN is set
if (SENTRY_DSN) {
Sentry.init({
dsn: SENTRY_DSN,

// Adjust this value in production, or use tracesSampler for greater control
tracesSampleRate: 1,

// Setting this option to true will print useful information to the console while you're setting up Sentry.
debug: false,
});
} else {
console.log("Sentry is not initialized on the server as SENTRY_DSN is not set");
}
Loading

0 comments on commit fbd1e17

Please sign in to comment.