Skip to content

Commit

Permalink
Add: Add env for tracesSampleRate
Browse files Browse the repository at this point in the history
  • Loading branch information
sevenc-nanashi committed Aug 20, 2023
1 parent 61318f2 commit 30cfbad
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions .env.build
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ SENTRY_DSN_SUB_CHART=
SENTRY_DSN_SUB_IMAGE=
SENTRY_ORG=
SENTRY_PROJECT_FRONTEND=
SENTRY_TRACE_SAMPLE_RATE=0.001
# vim: set ft=sh:
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ SENTRY_DSN_SUB_CHART=
SENTRY_DSN_SUB_IMAGE=
SENTRY_ORG=
SENTRY_PROJECT_FRONTEND=
SENTRY_TRACE_SAMPLE_RATE=0.001
# vim: set ft=sh:
1 change: 1 addition & 0 deletions .env.prod.example
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ SENTRY_DSN_SUB_CHART=
SENTRY_DSN_SUB_IMAGE=
SENTRY_ORG=
SENTRY_PROJECT_FRONTEND=
SENTRY_TRACE_SAMPLE_RATE=0.001
# vim: set ft=sh:
1 change: 1 addition & 0 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ SENTRY_DSN_SUB_CHART=
SENTRY_DSN_SUB_IMAGE=
SENTRY_ORG=
SENTRY_PROJECT_FRONTEND=
SENTRY_TRACE_SAMPLE_RATE=0.001
# vim: set ft=sh:
3 changes: 2 additions & 1 deletion backend/config/initializers/sentry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
require "sentry-ruby"

if ENV["SENTRY_DSN_BACKEND"].present?
traces_sample_rate = ENV["SENTRY_TRACES_SAMPLE_RATE"]&.to_f || 0.1
Sentry.init do |config|
config.dsn = ENV["SENTRY_DSN_BACKEND"]
config.breadcrumbs_logger = [:active_support_logger]

config.traces_sample_rate = Rails.env.production? ? 0.1 : 1.0
config.traces_sample_rate = traces_sample_rate
end
end
3 changes: 3 additions & 0 deletions frontend/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ const nextConfig = nextTranslate({
host: process.env.HOST,
adminHandle: process.env.ADMIN_HANDLE,
sentryDsnFrontend: process.env.SENTRY_DSN_FRONTEND,
sentryTraceSampleRate: parseFloat(
process.env.SENTRY_TRACE_SAMPLE_RATE || "0.1"
),
},

async rewrites() {
Expand Down
3 changes: 2 additions & 1 deletion frontend/sentry.client.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import getConfig from "next/config"
const { publicRuntimeConfig } = getConfig()

if (publicRuntimeConfig.sentryDsnFrontend) {
const tracesSampleRate = publicRuntimeConfig.sentryTraceSampleRate
Sentry.init({
dsn: publicRuntimeConfig.sentryDsnFrontend,
integrations: [new Sentry.Replay()],

tracesSampleRate: process.env.NODE_ENV === "production" ? 0.1 : 1.0,
tracesSampleRate,
})
}
5 changes: 5 additions & 0 deletions frontend/sentry.server.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import * as Sentry from "@sentry/nextjs"

if (process.env.SENTRY_DSN_FRONTEND) {
const tracesSampleRate = parseFloat(
process.env.SENTRY_TRACE_SAMPLE_RATE || "0.1"
)
Sentry.init({
dsn: process.env.SENTRY_DSN_FRONTEND,

tracesSampleRate,
})
}
3 changes: 2 additions & 1 deletion sub-audio/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
if sentry_dsn := os.getenv("SENTRY_DSN_SUB_AUDIO"):
import sentry_sdk

sentry_sdk.init(sentry_dsn)
traits_sample_rate = float(os.getenv("SENTRY_TRACE_SAMPLE_RATE", "0.01"))
sentry_sdk.init(sentry_dsn, traces_sample_rate=traits_sample_rate)

app = fastapi.FastAPI()
redis = aioredis.from_url(os.getenv("REDIS_URL"), decode_responses=True)
Expand Down
5 changes: 4 additions & 1 deletion sub-chart/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ const gzip = promisify(gzipBase)
const app = Express()

if (sentryEnabled) {
const tracesSampleRate = parseFloat(
process.env.SENTRY_TRACE_SAMPLE_RATE || "0.1"
)
sentry.init({
dsn: process.env.SENTRY_DSN_SUB_CHART,
tracesSampleRate: 1.0,
tracesSampleRate,
})
}

Expand Down
3 changes: 2 additions & 1 deletion sub-image/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
if sentry_dsn := os.getenv("SENTRY_DSN_SUB_AUDIO"):
import sentry_sdk

sentry_sdk.init(sentry_dsn)
traits_sample_rate = float(os.getenv("SENTRY_TRACE_SAMPLE_RATE", "0.01"))
sentry_sdk.init(sentry_dsn, traces_sample_rate=traits_sample_rate)

app = fastapi.FastAPI(docs_url=None, redoc_url=None)
redis = aioredis.from_url(
Expand Down

0 comments on commit 30cfbad

Please sign in to comment.