Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add metrics code locations #2263

Merged
merged 24 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
be9422d
metrics wip
sl0thentr0py Feb 16, 2024
ee59473
aggregator add impl
sl0thentr0py Feb 21, 2024
675292b
config and apis
sl0thentr0py Feb 21, 2024
73e5e04
encode statsd format and sanitization
sl0thentr0py Feb 22, 2024
9569bf9
capture envelope
sl0thentr0py Feb 22, 2024
8efde86
fix set
sl0thentr0py Feb 26, 2024
512408c
add transaction name to tags
sl0thentr0py Feb 26, 2024
bdac066
Specs
sl0thentr0py Feb 27, 2024
3f51c15
changelog
sl0thentr0py Feb 27, 2024
c1217cd
metric specs
sl0thentr0py Feb 27, 2024
8f9dabb
incr -> increment
sl0thentr0py Feb 29, 2024
ff3814f
Move config to separate metrics obj
sl0thentr0py Mar 5, 2024
f7163ef
Use scope name/source, not transaction
sl0thentr0py Mar 5, 2024
ff9792f
Remove is_json for envelope and use string check
sl0thentr0py Mar 11, 2024
9ba1a4e
trigger ci
sl0thentr0py Mar 11, 2024
478a78b
trigger ci
sl0thentr0py Mar 11, 2024
0e87bab
remove io-console pin
sl0thentr0py Mar 11, 2024
e6bbb90
Add Sentry::Metrics.timing API to measure blocks
sl0thentr0py Mar 4, 2024
7567daa
Merge remote-tracking branch 'origin/master' into neel/metrics/timing
sl0thentr0py Mar 12, 2024
116318b
Metric summaries on span
sl0thentr0py Mar 5, 2024
0df891d
Merge remote-tracking branch 'origin/master' into neel/metrics/span-a…
sl0thentr0py Mar 12, 2024
da14eaf
Add config.metrics.before_emit callback
sl0thentr0py Mar 8, 2024
088ccad
code locations
sl0thentr0py Mar 8, 2024
4107fd4
Merge remote-tracking branch 'origin/master' into neel/metrics/code-l…
sl0thentr0py Mar 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
metrics wip
  • Loading branch information
sl0thentr0py committed Feb 21, 2024
commit be9422ddbda95f5e7647d1064fe10a67f2e74d7c
17 changes: 17 additions & 0 deletions sentry-ruby/lib/sentry/metrics.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

require 'sentry/metrics/metric'
require 'sentry/metrics/counter_metric'
require 'sentry/metrics/distribution_metric'
require 'sentry/metrics/gauge_metric'
require 'sentry/metrics/set_metric'

module Sentry
module Metrics
class << self
# TODO-neel-metrics define units, maybe symbols
def incr(key, value: 1.0, unit: 'none', tags: nil, timestamp: nil)
end
end
end
end
83 changes: 83 additions & 0 deletions sentry-ruby/lib/sentry/metrics/aggregator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# frozen_string_literal: true

module Sentry
module Metrics
class Aggregator
include LoggingHelper

FLUSH_INTERVAL = 5
ROLLUP_IN_SECONDS = 10

def initialize(configuration, client)
@client = client
@logger = configuration.logger
@release = configuration.release
@environment = configuration.environment

@thread = nil
@exited = false

@buckets = {}
end

def add(type,
key,
value,
unit,
tags: nil,
timestamp: nil)
return unless ensure_thread

timestamp = timestamp.to_i if timestamp.is_a?(Time)
timestamp ||= Sentry.utc_now.to_i

# this is integer division and thus takes the floor of the division
# and buckets into 10 second intervals
bucket_timestamp = (timestamp / ROLLUP_IN_SECONDS) * ROLLUP_IN_SECONDS
serialized_tags = serialize_tags(tags)
bucket_key = [type, key, unit, serialized_tags]

# TODO lock and add to bucket
42
end

def flush
# TODO
end

def kill
log_debug("[Metrics::Aggregator] killing thread")

@exited = true
@thread&.kill
end

private

def ensure_thread
return false if @exited
return true if @thread&.alive?

@thread = Thread.new do
loop do
# TODO use event for force flush later
sleep(FLUSH_INTERVAL)
flush
end
end

true
rescue ThreadError
log_debug("[Metrics::Aggregator] thread creation failed")
@exited = true
false
end

def serialize_tags(tags)
# TODO support array tags
return [] unless tags
tags.map { |k, v| [k.to_s, v.to_s] }
end
end
end
end
25 changes: 25 additions & 0 deletions sentry-ruby/lib/sentry/metrics/counter_metric.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

module Sentry
module Metrics
class CounterMetric < Metric
attr_reader :value

def initialize(value)
@value = value.to_f
end

def add(value)
@value += value.to_f
end

def serialize
[value]
end

def weight
1
end
end
end
end
25 changes: 25 additions & 0 deletions sentry-ruby/lib/sentry/metrics/distribution_metric.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

module Sentry
module Metrics
class DistributionMetric < Metric
attr_reader :value

def initialize(value)
@value = [value.to_f]
end

def add(value)
@value << value.to_f
end

def serialize
value
end

def weight
value.size
end
end
end
end
35 changes: 35 additions & 0 deletions sentry-ruby/lib/sentry/metrics/gauge_metric.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# frozen_string_literal: true

module Sentry
module Metrics
class GaugeMetric < Metric
attr_reader :last, :min, :max, :sum, :count

def initialize(value)
value = value.to_f
@last = value
@min = value
@max = value
@sum = value
@count = 1
end

def add(value)
value = value.to_f
@last = value
@min = [@min, value].min
@max = [@max, value].max
@sum += value
@count += 1
end

def serialize
[last, min, max, sum, count]
end

def weight
5
end
end
end
end
19 changes: 19 additions & 0 deletions sentry-ruby/lib/sentry/metrics/metric.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module Sentry
module Metrics
class Metric
def add(value)
raise NotImplementedError
end

def serialize
raise NotImplementedError
end

def weight
raise NotImplementedError
end
end
end
end
30 changes: 30 additions & 0 deletions sentry-ruby/lib/sentry/metrics/set_metric.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

require 'set'
require 'zlib'

module Sentry
module Metrics
class SetMetric < Metric
attr_reader :value

def initialize(value)
@value = Set[value.to_f]
end

def add(value)
@value << value
end

def serialize
value.map do |v|
x.is_a?(String) ? Zlib.crc32(x) : x.to_i
end
end

def weight
value.size
end
end
end
end