From 4e24d9def1f2e6fd0f8f3890bb632741593b90b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Quentin=20G=C3=A9r=C3=B4me?= Date: Fri, 7 Oct 2022 16:59:41 +0200 Subject: [PATCH] fix(Sentry): Get sentry sampling traces rate from env --- README.md | 1 + next.config.js | 4 ++++ sentry.client.config.js | 7 ++++++- sentry.server.config.js | 7 ++++++- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 58e5a16..0a0c939 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ The following environment variables should be provided at build time (for the `d The following environment variables should be provided at run time: - `GRAPHQL_ENDPOINT`: the URL of the OpenHexa GraphQL API - `SENTRY_DSN`: the [Sentry](https://sentry.io/) DSN +- `SENTRY_TRACES_SAMPLE_RATE`: the [Sentry](https://sentry.io/) sampling rate of traces - `SENTRY_ENVIRONMENT`: the [Sentry](https://sentry.io/) environment tag ## Local development diff --git a/next.config.js b/next.config.js index af9a80f..0b0ffee 100644 --- a/next.config.js +++ b/next.config.js @@ -6,6 +6,10 @@ const { i18n } = require("./next-i18next.config"); const config = { publicRuntimeConfig: { GRAPHQL_ENDPOINT: process.env.GRAPHQL_ENDPOINT, + SENTRY_TRACES_SAMPLE_RATE: process.env.SENTRY_TRACES_SAMPLE_RATE + ? parseFloat(process.env.SENTRY_TRACES_SAMPLE_RATE) + : 1, + SENTRY_DSN: process.env.SENTRY_DSN, SENTRY_ENVIRONMENT: process.env.SENTRY_ENVIRONMENT, }, diff --git a/sentry.client.config.js b/sentry.client.config.js index 28652c8..d99f721 100644 --- a/sentry.client.config.js +++ b/sentry.client.config.js @@ -11,7 +11,12 @@ Sentry.init({ dsn: publicRuntimeConfig.SENTRY_DSN, environment: publicRuntimeConfig.SENTRY_ENVIRONMENT, // Adjust this value in production, or use tracesSampler for greater control - tracesSampleRate: 0.005, + tracesSampler(context) { + if (context.location?.pathname === "/ready") { + return 0; + } + return publicRuntimeConfig.SENTRY_TRACES_SAMPLE_RATE; + }, // ... // Note: if you want to override the automatic release value, do not set a // `release` value here - use the environment variable `SENTRY_RELEASE`, so diff --git a/sentry.server.config.js b/sentry.server.config.js index 48ae894..fe94e4c 100644 --- a/sentry.server.config.js +++ b/sentry.server.config.js @@ -12,7 +12,12 @@ Sentry.init({ dsn: publicRuntimeConfig.SENTRY_DSN, environment: publicRuntimeConfig.SENTRY_ENVIRONMENT, // Adjust this value in production, or use tracesSampler for greater control - tracesSampleRate: 0.005, + tracesSampler(context) { + if (context.location?.pathname === "/ready") { + return 0; + } + return publicRuntimeConfig.SENTRY_TRACES_SAMPLE_RATE; + }, // ... // Note: if you want to override the automatic release value, do not set a // `release` value here - use the environment variable `SENTRY_RELEASE`, so