File: metric_event.rb

package info (click to toggle)
ruby-sentry-ruby 6.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 644 kB
  • sloc: ruby: 5,771; makefile: 8; sh: 4
file content (49 lines) | stat: -rw-r--r-- 987 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# frozen_string_literal: true

require "sentry/utils/telemetry_attributes"

module Sentry
  class MetricEvent
    include Sentry::Utils::TelemetryAttributes

    attr_reader :name, :type, :value, :unit, :timestamp, :trace_id, :span_id, :attributes
    attr_writer :trace_id, :span_id, :attributes

    def initialize(
      name:,
      type:,
      value:,
      unit: nil,
      attributes: nil
    )
      @name = name
      @type = type
      @value = value
      @unit = unit
      @attributes = attributes || {}

      @timestamp = Sentry.utc_now
      @trace_id = nil
      @span_id = nil
    end

    def to_h
      {
        name: @name,
        type: @type,
        value: @value,
        unit: @unit,
        timestamp: @timestamp,
        trace_id: @trace_id,
        span_id: @span_id,
        attributes: serialize_attributes
      }.compact
    end

    private

    def serialize_attributes
      @attributes.transform_values! { |v| attribute_hash(v) }
    end
  end
end