refactoring pt.1
128
.clinerules/sentryrules.md
Normal file
@ -0,0 +1,128 @@
|
||||
These examples should be used as guidance when configuring Sentry functionality within a project.
|
||||
|
||||
# Exception Catching
|
||||
|
||||
Use `Sentry.captureException(error)` to capture an exception and log the error in Sentry.
|
||||
Use this in try catch blocks or areas where exceptions are expected
|
||||
|
||||
# Tracing Examples
|
||||
|
||||
Spans should be created for meaningful actions within an applications like button clicks, API calls, and function calls
|
||||
Use the `Sentry.startSpan` function to create a span
|
||||
Child spans can exist within a parent span
|
||||
|
||||
## Custom Span instrumentation in component actions
|
||||
|
||||
The `name` and `op` properties should be meaninful for the activities in the call.
|
||||
Attach attributes based on relevant information and metrics from the request
|
||||
|
||||
```javascript
|
||||
function TestComponent() {
|
||||
const handleTestButtonClick = () => {
|
||||
// Create a transaction/span to measure performance
|
||||
Sentry.startSpan(
|
||||
{
|
||||
op: "ui.click",
|
||||
name: "Test Button Click",
|
||||
},
|
||||
(span) => {
|
||||
const value = "some config";
|
||||
const metric = "some metric";
|
||||
|
||||
// Metrics can be added to the span
|
||||
span.setAttribute("config", value);
|
||||
span.setAttribute("metric", metric);
|
||||
|
||||
doSomething();
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<button type="button" onClick={handleTestButtonClick}>
|
||||
Test Sentry
|
||||
</button>
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
## Custom span instrumentation in API calls
|
||||
|
||||
The `name` and `op` properties should be meaninful for the activities in the call.
|
||||
Attach attributes based on relevant information and metrics from the request
|
||||
|
||||
```javascript
|
||||
async function fetchUserData(userId) {
|
||||
return Sentry.startSpan(
|
||||
{
|
||||
op: "http.client",
|
||||
name: `GET /api/users/${userId}`,
|
||||
},
|
||||
async () => {
|
||||
const response = await fetch(`/api/users/${userId}`);
|
||||
const data = await response.json();
|
||||
return data;
|
||||
},
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
# Logs
|
||||
|
||||
Where logs are used, ensure Sentry is imported using `import * as Sentry from "@sentry/nextjs"`
|
||||
Enable logging in Sentry using `Sentry.init({ _experiments: { enableLogs: true } })`
|
||||
Reference the logger using `const { logger } = Sentry`
|
||||
Sentry offers a consoleLoggingIntegration that can be used to log specific console error types automatically without instrumenting the individual logger calls
|
||||
|
||||
## Configuration
|
||||
|
||||
In NextJS the client side Sentry initialization is in `instrumentation-client.ts`, the server initialization is in `sentry.edge.config.ts` and the edge initialization is in `sentry.server.config.ts`
|
||||
Initialization does not need to be repeated in other files, it only needs to happen the files mentioned above. You should use `import * as Sentry from "@sentry/nextjs"` to reference Sentry functionality
|
||||
|
||||
### Baseline
|
||||
|
||||
```javascript
|
||||
import * as Sentry from "@sentry/nextjs";
|
||||
|
||||
Sentry.init({
|
||||
dsn: "https://e1805fb820448d9a2633170f0a8aaef4@o4509987417817088.ingest.us.sentry.io/4509987418800128",
|
||||
|
||||
_experiments: {
|
||||
enableLogs: true,
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
### Logger Integration
|
||||
|
||||
```javascript
|
||||
Sentry.init({
|
||||
dsn: "https://e1805fb820448d9a2633170f0a8aaef4@o4509987417817088.ingest.us.sentry.io/4509987418800128",
|
||||
integrations: [
|
||||
// send console.log, console.warn, and console.error calls as logs to Sentry
|
||||
Sentry.consoleLoggingIntegration({ levels: ["log", "warn", "error"] }),
|
||||
],
|
||||
});
|
||||
```
|
||||
|
||||
## Logger Examples
|
||||
|
||||
`logger.fmt` is a template literal function that should be used to bring variables into the structured logs.
|
||||
|
||||
```javascript
|
||||
logger.trace("Starting database connection", { database: "users" });
|
||||
logger.debug(logger.fmt`Cache miss for user: ${userId}`);
|
||||
logger.info("Updated profile", { profileId: 345 });
|
||||
logger.warn("Rate limit reached for endpoint", {
|
||||
endpoint: "/api/results/",
|
||||
isEnterprise: false,
|
||||
});
|
||||
logger.error("Failed to process payment", {
|
||||
orderId: "order_123",
|
||||
amount: 99.99,
|
||||
});
|
||||
logger.fatal("Database connection pool exhausted", {
|
||||
database: "users",
|
||||
activeConnections: 100,
|
||||
});
|
||||
```
|
||||
3
.gitignore
vendored
@ -3,3 +3,6 @@ node_modules
|
||||
.env
|
||||
|
||||
/generated/prisma
|
||||
|
||||
# Sentry Config File
|
||||
.env.sentry-build-plugin
|
||||
|
||||
@ -1,5 +1,10 @@
|
||||
{
|
||||
"pages": {
|
||||
"/global-error": [
|
||||
"static/chunks/webpack.js",
|
||||
"static/chunks/main-app.js",
|
||||
"static/chunks/app/global-error.js"
|
||||
],
|
||||
"/layout": [
|
||||
"static/chunks/webpack.js",
|
||||
"static/chunks/main-app.js",
|
||||
@ -16,20 +21,15 @@
|
||||
"static/chunks/main-app.js",
|
||||
"static/chunks/app/api/auth/[...nextauth]/route.js"
|
||||
],
|
||||
"/api/assets/route": [
|
||||
"/projects/page": [
|
||||
"static/chunks/webpack.js",
|
||||
"static/chunks/main-app.js",
|
||||
"static/chunks/app/api/assets/route.js"
|
||||
"static/chunks/app/projects/page.js"
|
||||
],
|
||||
"/api/projects/route": [
|
||||
"/crew/page": [
|
||||
"static/chunks/webpack.js",
|
||||
"static/chunks/main-app.js",
|
||||
"static/chunks/app/api/projects/route.js"
|
||||
],
|
||||
"/api/blog/route": [
|
||||
"static/chunks/webpack.js",
|
||||
"static/chunks/main-app.js",
|
||||
"static/chunks/app/api/blog/route.js"
|
||||
"static/chunks/app/crew/page.js"
|
||||
],
|
||||
"/blog/page": [
|
||||
"static/chunks/webpack.js",
|
||||
@ -41,15 +41,25 @@
|
||||
"static/chunks/main-app.js",
|
||||
"static/chunks/app/faq/page.js"
|
||||
],
|
||||
"/api/faq/route": [
|
||||
"static/chunks/webpack.js",
|
||||
"static/chunks/main-app.js",
|
||||
"static/chunks/app/api/faq/route.js"
|
||||
],
|
||||
"/contact/page": [
|
||||
"static/chunks/webpack.js",
|
||||
"static/chunks/main-app.js",
|
||||
"static/chunks/app/contact/page.js"
|
||||
],
|
||||
"/projects/page": [
|
||||
"/admin/layout": [
|
||||
"static/chunks/webpack.js",
|
||||
"static/chunks/main-app.js",
|
||||
"static/chunks/app/projects/page.js"
|
||||
"static/chunks/app/admin/layout.js"
|
||||
],
|
||||
"/admin/page": [
|
||||
"static/chunks/webpack.js",
|
||||
"static/chunks/main-app.js",
|
||||
"static/chunks/app/admin/page.js"
|
||||
]
|
||||
}
|
||||
}
|
||||
@ -2,9 +2,7 @@
|
||||
"polyfillFiles": [
|
||||
"static/chunks/polyfills.js"
|
||||
],
|
||||
"devFiles": [
|
||||
"static/chunks/react-refresh.js"
|
||||
],
|
||||
"devFiles": [],
|
||||
"ampDevFiles": [],
|
||||
"lowPriorityFiles": [
|
||||
"static/development/_buildManifest.js",
|
||||
@ -16,16 +14,7 @@
|
||||
],
|
||||
"rootMainFilesTree": {},
|
||||
"pages": {
|
||||
"/_app": [
|
||||
"static/chunks/webpack.js",
|
||||
"static/chunks/main.js",
|
||||
"static/chunks/pages/_app.js"
|
||||
],
|
||||
"/_error": [
|
||||
"static/chunks/webpack.js",
|
||||
"static/chunks/main.js",
|
||||
"static/chunks/pages/_error.js"
|
||||
]
|
||||
"/_app": []
|
||||
},
|
||||
"ampFirstPages": []
|
||||
}
|
||||
|
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 53 KiB After Width: | Height: | Size: 53 KiB |
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 5.1 KiB After Width: | Height: | Size: 5.1 KiB |
|
After Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 9.5 KiB After Width: | Height: | Size: 9.5 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 102 KiB After Width: | Height: | Size: 102 KiB |
|
After Width: | Height: | Size: 5.0 KiB |
|
Before Width: | Height: | Size: 7.7 KiB After Width: | Height: | Size: 7.7 KiB |
|
After Width: | Height: | Size: 5.4 KiB |
|
After Width: | Height: | Size: 5.5 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 7.7 KiB |
|
Before Width: | Height: | Size: 6.0 KiB After Width: | Height: | Size: 6.0 KiB |
|
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 9.3 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 6.6 KiB After Width: | Height: | Size: 6.6 KiB |
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 35 KiB |
|
After Width: | Height: | Size: 45 KiB |
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 56 KiB After Width: | Height: | Size: 56 KiB |
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 8.0 KiB After Width: | Height: | Size: 8.0 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 7.1 KiB |
|
Before Width: | Height: | Size: 7.6 KiB After Width: | Height: | Size: 7.6 KiB |
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 21 KiB |
|
Before Width: | Height: | Size: 9.4 KiB After Width: | Height: | Size: 9.4 KiB |
BIN
.next/cache/webpack/client-development/0.pack.gz
vendored
BIN
.next/cache/webpack/client-development/1.pack.gz
vendored
BIN
.next/cache/webpack/client-development/10.pack.gz
vendored
BIN
.next/cache/webpack/client-development/11.pack.gz
vendored
BIN
.next/cache/webpack/client-development/12.pack.gz
vendored
BIN
.next/cache/webpack/client-development/13.pack.gz
vendored
BIN
.next/cache/webpack/client-development/14.pack.gz
vendored
BIN
.next/cache/webpack/client-development/15.pack.gz
vendored
BIN
.next/cache/webpack/client-development/16.pack.gz
vendored
BIN
.next/cache/webpack/client-development/17.pack.gz
vendored
BIN
.next/cache/webpack/client-development/2.pack.gz
vendored
BIN
.next/cache/webpack/client-development/3.pack.gz
vendored
BIN
.next/cache/webpack/client-development/4.pack.gz
vendored
BIN
.next/cache/webpack/client-development/5.pack.gz
vendored
BIN
.next/cache/webpack/client-development/6.pack.gz
vendored
BIN
.next/cache/webpack/client-development/7.pack.gz
vendored
BIN
.next/cache/webpack/client-development/8.pack.gz
vendored
BIN
.next/cache/webpack/client-development/9.pack.gz
vendored
BIN
.next/cache/webpack/client-development/index.pack.gz
vendored
BIN
.next/cache/webpack/edge-server-development/0.pack.gz
vendored
Normal file
BIN
.next/cache/webpack/edge-server-development/1.pack.gz
vendored
Normal file
BIN
.next/cache/webpack/edge-server-development/2.pack.gz
vendored
Normal file
BIN
.next/cache/webpack/edge-server-development/index.pack.gz
vendored
Normal file
BIN
.next/cache/webpack/edge-server-development/index.pack.gz.old
vendored
Normal file
BIN
.next/cache/webpack/server-development/0.pack.gz
vendored
BIN
.next/cache/webpack/server-development/1.pack.gz
vendored
BIN
.next/cache/webpack/server-development/10.pack.gz
vendored
BIN
.next/cache/webpack/server-development/11.pack.gz
vendored
BIN
.next/cache/webpack/server-development/12.pack.gz
vendored
BIN
.next/cache/webpack/server-development/13.pack.gz
vendored
BIN
.next/cache/webpack/server-development/14.pack.gz
vendored
BIN
.next/cache/webpack/server-development/15.pack.gz
vendored
BIN
.next/cache/webpack/server-development/16.pack.gz
vendored
BIN
.next/cache/webpack/server-development/17.pack.gz
vendored
BIN
.next/cache/webpack/server-development/18.pack.gz
vendored
BIN
.next/cache/webpack/server-development/19.pack.gz
vendored
BIN
.next/cache/webpack/server-development/2.pack.gz
vendored
BIN
.next/cache/webpack/server-development/20.pack.gz
vendored
BIN
.next/cache/webpack/server-development/21.pack.gz
vendored
BIN
.next/cache/webpack/server-development/22.pack.gz
vendored
BIN
.next/cache/webpack/server-development/3.pack.gz
vendored
BIN
.next/cache/webpack/server-development/4.pack.gz
vendored
BIN
.next/cache/webpack/server-development/5.pack.gz
vendored
BIN
.next/cache/webpack/server-development/6.pack.gz
vendored
BIN
.next/cache/webpack/server-development/7.pack.gz
vendored
BIN
.next/cache/webpack/server-development/8.pack.gz
vendored
BIN
.next/cache/webpack/server-development/9.pack.gz
vendored
BIN
.next/cache/webpack/server-development/index.pack.gz
vendored
@ -1,31 +0,0 @@
|
||||
{
|
||||
"polyfillFiles": [
|
||||
"static/chunks/polyfills.js"
|
||||
],
|
||||
"devFiles": [
|
||||
"static/chunks/fallback/react-refresh.js"
|
||||
],
|
||||
"ampDevFiles": [
|
||||
"static/chunks/fallback/webpack.js",
|
||||
"static/chunks/fallback/amp.js"
|
||||
],
|
||||
"lowPriorityFiles": [],
|
||||
"rootMainFiles": [
|
||||
"static/chunks/fallback/webpack.js",
|
||||
"static/chunks/fallback/main-app.js"
|
||||
],
|
||||
"rootMainFilesTree": {},
|
||||
"pages": {
|
||||
"/_app": [
|
||||
"static/chunks/fallback/webpack.js",
|
||||
"static/chunks/fallback/main.js",
|
||||
"static/chunks/fallback/pages/_app.js"
|
||||
],
|
||||
"/_error": [
|
||||
"static/chunks/fallback/webpack.js",
|
||||
"static/chunks/fallback/main.js",
|
||||
"static/chunks/fallback/pages/_error.js"
|
||||
]
|
||||
},
|
||||
"ampFirstPages": []
|
||||
}
|
||||
@ -4,8 +4,8 @@
|
||||
"dynamicRoutes": {},
|
||||
"notFoundRoutes": [],
|
||||
"preview": {
|
||||
"previewModeId": "2dbbd9987899e3cc204e40a239815375",
|
||||
"previewModeSigningKey": "bad8f11a5056d21fe20e0a5bd813454b38ea3fd25ce77e7cafe32a4ed4634967",
|
||||
"previewModeEncryptionKey": "6ba64c891fac3489e8fdafbd722323c67985c8be4cd315b61eb3ea2addc6df0f"
|
||||
"previewModeId": "0d7f22499a8e7cb0f6dc0991b071ee08",
|
||||
"previewModeSigningKey": "4815944c88776b54f4d30ca55e3481a304fedf700da30261c2d89034e267b911",
|
||||
"previewModeEncryptionKey": "d597e4fbbf187baf182306010bb7c4a6c59d24fd1babf34805112333501a3634"
|
||||
}
|
||||
}
|
||||
@ -1 +1 @@
|
||||
{"version":3,"caseSensitive":false,"basePath":"","rewrites":{"beforeFiles":[],"afterFiles":[{"source":"/admin/:path*","destination":"/admin/:path*","regex":"^\\/admin(?:\\/((?:[^\\/]+?)(?:\\/(?:[^\\/]+?))*))?(?:\\/)?$","check":true}],"fallback":[]},"redirects":[{"source":"/:path+/","destination":"/:path+","permanent":true,"internal":true,"regex":"^(?:\\/((?:[^\\/]+?)(?:\\/(?:[^\\/]+?))*))\\/$"}],"headers":[]}
|
||||
{"version":3,"caseSensitive":false,"basePath":"","rewrites":{"beforeFiles":[],"afterFiles":[{"source":"/monitoring(/?)","has":[{"type":"query","key":"o","value":"(?<orgid>\\d*)"},{"type":"query","key":"p","value":"(?<projectid>\\d*)"},{"type":"query","key":"r","value":"(?<region>[a-z]{2})"}],"destination":"https://o:orgid.ingest.:region.sentry.io/api/:projectid/envelope/?hsts=0","regex":"^\\/monitoring(\\/?)(?:\\/)?$","check":true},{"source":"/monitoring(/?)","has":[{"type":"query","key":"o","value":"(?<orgid>\\d*)"},{"type":"query","key":"p","value":"(?<projectid>\\d*)"}],"destination":"https://o:orgid.ingest.sentry.io/api/:projectid/envelope/?hsts=0","regex":"^\\/monitoring(\\/?)(?:\\/)?$","check":true},{"source":"/admin/:path*","destination":"/admin/:path*","regex":"^\\/admin(?:\\/((?:[^\\/]+?)(?:\\/(?:[^\\/]+?))*))?(?:\\/)?$","check":true}],"fallback":[]},"redirects":[{"source":"/:path+/","destination":"/:path+","permanent":true,"internal":true,"regex":"^(?:\\/((?:[^\\/]+?)(?:\\/(?:[^\\/]+?))*))\\/$"}],"headers":[]}
|
||||