Skip to content

Commit

Permalink
fix(Sentry): Get sentry sampling traces rate from env
Browse files Browse the repository at this point in the history
  • Loading branch information
qgerome committed Oct 7, 2022
1 parent 34c882a commit 4e24d9d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
7 changes: 6 additions & 1 deletion sentry.client.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion sentry.server.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4e24d9d

Please sign in to comment.