-
-
Notifications
You must be signed in to change notification settings - Fork 501
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add a `LocalAggregator` instance on spans to duplicate metrics on the span as a gauge metric * proxy the main aggregator add calls to the local aggregator if a span is running * start a `metric.timing` span in the `Sentry::Metrics.timing` API * add `before_emit` callback part of #2246
- Loading branch information
1 parent
cf8f7ae
commit b0b73fd
Showing
15 changed files
with
375 additions
and
17 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# frozen_string_literal: true | ||
|
||
module Sentry | ||
module Metrics | ||
class LocalAggregator | ||
# exposed only for testing | ||
attr_reader :buckets | ||
|
||
def initialize | ||
@buckets = {} | ||
end | ||
|
||
def add(key, value) | ||
if @buckets[key] | ||
@buckets[key].add(value) | ||
else | ||
@buckets[key] = GaugeMetric.new(value) | ||
end | ||
end | ||
|
||
def to_hash | ||
return nil if @buckets.empty? | ||
|
||
@buckets.map do |bucket_key, metric| | ||
type, key, unit, tags = bucket_key | ||
|
||
payload_key = "#{type}:#{key}@#{unit}" | ||
payload_value = { | ||
tags: deserialize_tags(tags), | ||
min: metric.min, | ||
max: metric.max, | ||
count: metric.count, | ||
sum: metric.sum | ||
} | ||
|
||
[payload_key, payload_value] | ||
end.to_h | ||
end | ||
|
||
private | ||
|
||
def deserialize_tags(tags) | ||
tags.inject({}) do |h, tag| | ||
k, v = tag | ||
old = h[k] | ||
# make it an array if key repeats | ||
h[k] = old ? (old.is_a?(Array) ? old << v : [old, v]) : v | ||
h | ||
end | ||
end | ||
end | ||
end | ||
end |
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
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
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
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
Oops, something went wrong.