From 2a78a85efa9fe2bde28794932321b01e44217449 Mon Sep 17 00:00:00 2001 From: Ben Zhang Date: Tue, 3 Sep 2024 14:12:38 -0700 Subject: [PATCH] Configure Sentry to only send traces from select deployments (#3077) Sentry has been gathering statistics from our preview environment. This skews the performance metrics. This PR makes it so that it only gathers statistics from prod. image https://watonomous.sentry.io/performance/trace/4bf52500e7c94bb1821bb275d8cd2e26/?environment=production&fov=0,4399.89990234375&node=txn-49f3b18bc3b14ba59da3471900a05c72&project=4506137389105152&source=web_vitals_module&statsPeriod=7d×tamp=1725305801&transaction=/ --- sentry.client.config.ts | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/sentry.client.config.ts b/sentry.client.config.ts index a3204a9..4805665 100644 --- a/sentry.client.config.ts +++ b/sentry.client.config.ts @@ -5,23 +5,42 @@ import * as Sentry from "@sentry/nextjs"; import { websiteConfig } from '@/lib/data' +// proportion of traces to send to Sentry +const TRACES_SAMPLE_RATE = 1.0 + if (process.env.NODE_ENV === 'production') { Sentry.init({ dsn: websiteConfig.sentry_dsn, - // Adjust this value in production, or use tracesSampler for greater control - tracesSampleRate: 1, + tracesSampler({ location }) { + // Not sure what traces don't have a location, but sample them just in case. + if (!location) { + return TRACES_SAMPLE_RATE; + } + + // Only send traces to Sentry if the user is on the production domain + if (!location.host.endsWith('watonomous.ca')) { + return 0.0 + } + + // Do not send traces to Sentry if the user is in the preview environment + if (location.host === 'rgw-preview.watonomous.ca') { + return 0.0 + } + + return TRACES_SAMPLE_RATE; + }, // Setting this option to true will print useful information to the console while you're setting up Sentry. debug: false, - // TODO: reduce session sample rate in production + // TODO: reduce session sample rate in production if needed replaysSessionSampleRate: 1.0, replaysOnErrorSampleRate: 1.0, tunnel: websiteConfig.sentry_tunnel, - integrations: [] + integrations: [], }); // Lazy-load the Sentry Replay integration