Skip to content

Instantly share code, notes, and snippets.

@adamlogic
Created February 22, 2024 16:22
Show Gist options
  • Save adamlogic/13187c1efe2467cce12212ca70b58a2a to your computer and use it in GitHub Desktop.
Save adamlogic/13187c1efe2467cce12212ca70b58a2a to your computer and use it in GitHub Desktop.
Scout APM sampling
# Apply a sample rate to Scout so it only instruments a portion of requests
# or jobs. Here's an example of how to use it in a controller action or job:
# ScoutApm::Transaction.use_sample_rate 0.001
module ScoutApm
module Transaction
# Set SCOUT_SAMPLING=false to disable sampling. This will send all transactions to Scout,
# and very quickly use up our monthly transaction limit.
USE_SAMPLING = ENV["SCOUT_SAMPLING"] != "false"
def self.use_sample_rate(rate)
if USE_SAMPLING && rand > rate
ScoutApm::Transaction.ignore!
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment