-
-
Notifications
You must be signed in to change notification settings - Fork 173
Update and fix Sentry and Algolia Search #1060
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import * as Sentry from "@sentry/nextjs"; | ||
|
|
||
| const SENTRY_DSN = process.env.SENTRY_DSN || process.env.NEXT_PUBLIC_SENTRY_DSN; | ||
| const SENTRY_ENVIRONMENT = process.env.SENTRY_ENVIRONMENT; | ||
|
|
||
| export function register() { | ||
| if (process.env.NEXT_RUNTIME === "nodejs") { | ||
| // this is your Sentry.init call from `sentry.server.config.js|ts` | ||
| Sentry.init({ | ||
| dsn: SENTRY_DSN, | ||
| // Adjust this value in production, or use tracesSampler for greater control | ||
| tracesSampleRate: 1, | ||
| environment: SENTRY_ENVIRONMENT, | ||
| }); | ||
| } | ||
|
Comment on lines
+7
to
+15
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve Sentry initialization for Node.js runtime The Sentry initialization for Node.js looks generally correct, but there are a few points to consider:
Consider refactoring the Node.js initialization as follows: if (process.env.NEXT_RUNTIME === "nodejs") {
if (SENTRY_DSN) {
Sentry.init({
dsn: SENTRY_DSN,
tracesSampleRate: process.env.NODE_ENV === 'production' ? 0.1 : 1,
environment: SENTRY_ENVIRONMENT,
});
} else {
console.warn('Sentry DSN not provided. Skipping Sentry initialization for Node.js runtime.');
}
}This approach:
|
||
|
|
||
| // This is your Sentry.init call from `sentry.edge.config.js|ts` | ||
| if (process.env.NEXT_RUNTIME === "edge") { | ||
| Sentry.init({ | ||
| dsn: SENTRY_DSN, | ||
| // Adjust this value in production, or use tracesSampler for greater control | ||
| tracesSampleRate: 1, | ||
| environment: SENTRY_ENVIRONMENT, | ||
| }); | ||
| } | ||
|
Comment on lines
+18
to
+25
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Refactor Edge runtime initialization to reduce duplication The Sentry initialization for Edge runtime is identical to the Node.js runtime, which leads to code duplication and the same potential issues we identified earlier. Consider refactoring to reduce duplication and improve both initializations: function initSentry(runtime: string) {
if (SENTRY_DSN) {
Sentry.init({
dsn: SENTRY_DSN,
tracesSampleRate: process.env.NODE_ENV === 'production' ? 0.1 : 1,
environment: SENTRY_ENVIRONMENT,
});
} else {
console.warn(`Sentry DSN not provided. Skipping Sentry initialization for ${runtime} runtime.`);
}
}
export function register() {
switch (process.env.NEXT_RUNTIME) {
case "nodejs":
initSentry("Node.js");
break;
case "edge":
initSentry("Edge");
break;
default:
console.warn(`Unexpected NEXT_RUNTIME value: ${process.env.NEXT_RUNTIME}`);
}
}This refactored version:
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider improving environment variable handling
The current implementation has a few potential issues:
SENTRY_DSNandNEXT_PUBLIC_SENTRY_DSNmight lead to confusion. Consider using only one of them consistently.SENTRY_ENVIRONMENTis not checked for existence, which might lead to undefined behavior if the environment variable is not set.Consider refactoring the environment variable handling as follows:
This approach:
NEXT_PUBLIC_SENTRY_DSNfor consistencySENTRY_ENVIRONMENTSENTRY_DSNis not set