Method: Sentry::Metrics::Aggregator#add

Defined in:
lib/sentry/metrics/aggregator.rb

#add(type, key, value, unit: "none", tags: {}, timestamp: nil, stacklevel: nil) ⇒ Object

[View source]

59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/sentry/metrics/aggregator.rb', line 59

def add(type,
        key,
        value,
        unit: "none",
        tags: {},
        timestamp: nil,
        stacklevel: nil)
  return unless ensure_thread
  return unless METRIC_TYPES.keys.include?(type)

  updated_tags = get_updated_tags(tags)
  return if @before_emit && !@before_emit.call(key, updated_tags)

  timestamp ||= Sentry.utc_now

  # this is integer division and thus takes the floor of the division
  # and buckets into 10 second intervals
  bucket_timestamp = (timestamp.to_i / ROLLUP_IN_SECONDS) * ROLLUP_IN_SECONDS

  serialized_tags = serialize_tags(updated_tags)
  bucket_key = [type, key, unit, serialized_tags]

  added = @mutex.synchronize do
    record_code_location(type, key, unit, timestamp, stacklevel: stacklevel) if @enable_code_locations
    process_bucket(bucket_timestamp, bucket_key, type, value)
  end

  # for sets, we pass on if there was a new entry to the local gauge
  local_value = type == :s ? added : value
  process_span_aggregator(bucket_key, local_value)
end