Skip to content

Commit

Permalink
chore: improve sentry environment handling (#1519)
Browse files Browse the repository at this point in the history
  • Loading branch information
julianpoy authored Feb 9, 2025
2 parents d1ae7cf + 7b230de commit 3f881a4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ services:
- FIRESTORE_BUCKET=
- STORAGE_TYPE=s3 #POSSIBLE VALUES: s3, firebase, filesystem
- NODE_ENV=development
- ENVIRONMENT=development
- VERBOSE=false
- VERSION=development
- POSTGRES_DB=recipesage_dev
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/services/sentry-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ Sentry.init({
tracesSampleRate: parseFloat(process.env.SENTRY_SAMPLE_RATE || 1.0, 10),
profilesSampleRate: parseFloat(process.env.SENTRY_SAMPLE_RATE || 1.0, 10),

environment: process.env.NODE_ENV,
environment: process.env.ENVIRONMENT || "unknown",
release: RS_VERSION,
});
10 changes: 9 additions & 1 deletion packages/frontend/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,17 @@ console.error = (...args) => {
};

if (!IS_SELFHOST) {
const hostname = window.location.hostname;
let sentryEnvironment = environment.production ? "production" : "development";
if (sentryEnvironment === "production" && hostname.startsWith("beta.")) {
// We don't do separate builds for beta/production, so hostname check is the best
// approach
sentryEnvironment = "beta";
}

Sentry.init({
release: (window as any).version,
environment: environment.production ? "production" : "dev",
environment: sentryEnvironment,
dsn: "https://[email protected]/2",
transport: Sentry.makeBrowserOfflineTransport(Sentry.makeFetchTransport),
tracesSampleRate: SENTRY_SAMPLE_RATE,
Expand Down
9 changes: 9 additions & 0 deletions packages/frontend/src/service-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ declare let self: ServiceWorkerGlobalScope;
import * as Sentry from "@sentry/browser";

if (process.env.ENVIRONMENT !== "selfhost") {
const hostname = self.location.hostname;

let environment = process.env.ENVIRONMENT;
if (environment === "production" && hostname.startsWith("beta.")) {
// We don't do separate builds for beta/production, so hostname check is the best
// approach
environment = "beta";
}

Sentry.init({
release: process.env.APP_VERSION,
environment: process.env.ENVIRONMENT,
Expand Down

0 comments on commit 3f881a4

Please sign in to comment.