sentry-ruby icon indicating copy to clipboard operation
sentry-ruby copied to clipboard

Add Metrics API and aggregator

Open sl0thentr0py opened this issue 1 year ago • 2 comments

  • new Sentry::Metrics module with 4 apis that map to the new 4 Sentry::Metrics::Metric classes
    • increment - simple counter
    • distribution - array of observations
    • gauge - statistics (last/min/max/sum/count)
    • set - unique values
  • new Sentry::Metrics::Aggregator that starts a thread that flushes pending metric buckets in 5 second intervals
    • buckets are a nested hash of timestamp (rolled to 10 second intervals) -> metric keys -> actual metric instance
    • there is a random flush_shift once per startup to create jittering
    • flushable buckets are sent in a new statsd type envelope that is not json so made a small change to the Envelope::Item
    • tag key/values are sanitized for unicode/special characters according to the two regexes

Reference spec - https://develop.sentry.dev/sdk/metrics/

part of #2246

sl0thentr0py avatar Feb 16 '24 15:02 sl0thentr0py

Codecov Report

Merging #2247 (0e87bab) into master (478c4cf) will increase coverage by 0.12%. The diff coverage is 99.50%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2247      +/-   ##
==========================================
+ Coverage   97.41%   97.54%   +0.12%     
==========================================
  Files         102      110       +8     
  Lines        3828     4026     +198     
==========================================
+ Hits         3729     3927     +198     
  Misses         99       99              
Components Coverage Δ
sentry-ruby 98.23% <99.50%> (+0.08%) :arrow_up:
sentry-rails 95.05% <ø> (ø)
sentry-sidekiq 94.70% <ø> (ø)
sentry-resque 92.30% <ø> (+1.53%) :arrow_up:
sentry-delayed_job 95.60% <ø> (ø)
sentry-opentelemetry 100.00% <ø> (ø)
Files Coverage Δ
sentry-ruby/lib/sentry-ruby.rb 96.56% <100.00%> (+0.12%) :arrow_up:
sentry-ruby/lib/sentry/configuration.rb 98.80% <100.00%> (+0.01%) :arrow_up:
sentry-ruby/lib/sentry/envelope.rb 97.95% <100.00%> (ø)
sentry-ruby/lib/sentry/metrics.rb 100.00% <100.00%> (ø)
sentry-ruby/lib/sentry/metrics/configuration.rb 100.00% <100.00%> (ø)
sentry-ruby/lib/sentry/metrics/counter_metric.rb 100.00% <100.00%> (ø)
...try-ruby/lib/sentry/metrics/distribution_metric.rb 100.00% <100.00%> (ø)
sentry-ruby/lib/sentry/metrics/gauge_metric.rb 100.00% <100.00%> (ø)
sentry-ruby/lib/sentry/metrics/metric.rb 100.00% <100.00%> (ø)
sentry-ruby/lib/sentry/metrics/set_metric.rb 100.00% <100.00%> (ø)
... and 3 more

... and 1 file with indirect coverage changes

codecov[bot] avatar Feb 16 '24 15:02 codecov[bot]

will add unit lists in separate PR

sl0thentr0py avatar Feb 29 '24 13:02 sl0thentr0py

@st0012 im gonna start merging these because we want to ship this week. If you have things you want changed, feel free to leave reviews anyway, I can change them separately.

sl0thentr0py avatar Mar 12 '24 12:03 sl0thentr0py