Last active
November 22, 2023 14:24
-
-
Save coorasse/06cf42b4daaa77a873702273c641e13c to your computer and use it in GitHub Desktop.
Sentry - skip fast transactions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /config/initializers/sentry.rb | |
config.before_send_transaction = lambda do |event, _hint| | |
relevant_span = event.spans.find { |s| s[:op] == 'view.process_action.action_controller' } | |
if relevant_span | |
sampling_config = { 50 => 1, 200 => 10, 500 => 20, 1000 => 50 } | |
duration_in_ms = (relevant_span[:timestamp] - relevant_span[:start_timestamp]) * 1000 | |
sampling_percentage = sampling_config. | |
sort. | |
find { |threshold, _percentage| duration_in_ms <= threshold }. | |
try(:[], 1) || 100 | |
# Perform the sampling check | |
Random.rand(100) <= sampling_percentage ? event : nil | |
else | |
event | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This can be simplified if don't have a sampling_config: