|
32 | 32 | # Do not send full list of gems with each event |
33 | 33 | config.send_modules = false |
34 | 34 |
|
35 | | - # Set sampling rates to 1.0 to capture 100% of transactions and |
36 | | - # profiles for performance monitoring. |
37 | | - config.traces_sample_rate = 1.0 |
38 | | - config.profiles_sample_rate = 1.0 |
39 | | - |
40 | 35 | filter = ActiveSupport::ParameterFilter.new(Rails.application.config.filter_parameters) |
41 | 36 | config.before_send = lambda do |event, _hint| |
42 | 37 | # use Rails' parameter filter to sanitize the event |
43 | 38 | filter.filter(event.to_hash) |
44 | 39 | end |
| 40 | + |
| 41 | + # The default sampling rate for Sentry transactions. Unless other |
| 42 | + # rules apply below, sample all requests by default. |
| 43 | + # |
| 44 | + # Collect profiles are transactions that are sampled. |
| 45 | + config.traces_sample_rate = ENV.fetch('SENTRY_TRACES_SAMPLE_RATE', '1.0').to_f |
| 46 | + config.profiles_sample_rate = 1.0 |
| 47 | + |
| 48 | + config.traces_sampler = lambda do |ctx| |
| 49 | + # If this is the continuation of a trace, just use that decision |
| 50 | + # (rate controlled by the caller). |
| 51 | + unless ctx[:parent_sampled].nil? |
| 52 | + next ctx[:parent_sampled] |
| 53 | + end |
| 54 | + |
| 55 | + # `transaction_context` is the transaction object in hash form. Keep |
| 56 | + # in mind that sampling happens right after the transaction is |
| 57 | + # initialized for example, at the beginning of the request. |
| 58 | + transaction_context = ctx[:transaction_context] |
| 59 | + |
| 60 | + # `transaction_context` helps you sample transactions with more |
| 61 | + # sophistication. For example, you can provide different sample |
| 62 | + # rates based on the operation or name. |
| 63 | + op = transaction_context[:op] |
| 64 | + transaction_name = transaction_context[:name] |
| 65 | + |
| 66 | + case op |
| 67 | + when 'http.server' |
| 68 | + # For Rails applications, the transaction name would be the |
| 69 | + # request's path (env["PATH_INFO"]) instead of |
| 70 | + # "Controller#action". |
| 71 | + case transaction_name |
| 72 | + when %r{^/(up|ping|system_info)} |
| 73 | + return 0.0 # Ignore health check requests |
| 74 | + end |
| 75 | + end |
| 76 | + |
| 77 | + config.traces_sample_rate |
| 78 | + end |
45 | 79 | end |
46 | 80 |
|
47 | 81 | Sentry.set_tags( |
|
0 commit comments