From be1673864110bb803a41fdbe230221f135912790 Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Fri, 26 Nov 2021 00:00:45 +0100 Subject: [PATCH] Update Sentry to ignore health check transactions --- config/initializers/sentry.rb | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/config/initializers/sentry.rb b/config/initializers/sentry.rb index 65c72e14..e9559609 100644 --- a/config/initializers/sentry.rb +++ b/config/initializers/sentry.rb @@ -7,5 +7,33 @@ Sentry.init do |config| # Set tracesSampleRate to 1.0 to capture 100% # of transactions for performance monitoring. # We recommend adjusting this value in production - config.traces_sample_rate = 0.01 + config.traces_sampler = lambda do |sampling_context| + # if this is the continuation of a trace, just use that decision (rate controlled by the caller) + unless sampling_context[:parent_sampled].nil? + next sampling_context[:parent_sampled] + end + + # transaction_context is the transaction object in hash form + # keep in mind that sampling happens right after the transaction is initialized + # for example, at the beginning of the request + transaction_context = sampling_context[:transaction_context] + + # transaction_context helps you sample transactions with more sophistication + # for example, you can provide different sample rates based on the operation or name + op = transaction_context[:op] + transaction_name = transaction_context[:name] + + case op + when /request/ + # for Rails applications, transaction_name would be the request's path (env["PATH_INFO"]) instead of "Controller#action" + case transaction_name + when '/', '/ping' + 0.00 # ignore health check + else + 0.05 + end + else + 0.0 # ignore all other transactions + end + end end