Class: SolidApm::SpanSubscriber::Base

Inherits:
Object
  • Object
show all
Defined in:
app/models/solid_apm/span_subscriber/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.backtrace_cleanerObject



48
49
50
51
52
53
54
55
56
57
58
# File 'app/models/solid_apm/span_subscriber/base.rb', line 48

def self.backtrace_cleaner
  @backtrace_cleaner ||= begin
    bc = ActiveSupport::BacktraceCleaner.new
    bc.remove_filters!
    gem_roots = Gem.path
    [Rails.root, *gem_roots].each do |path|
       bc.add_filter { |line| line.delete_prefix("#{path}/") }
    end
    bc
  end
end

.clean_trace(backtrace) ⇒ Object



60
61
62
63
64
65
66
# File 'app/models/solid_apm/span_subscriber/base.rb', line 60

def self.clean_trace(backtrace)
  if backtrace.is_a?(Array)
    backtrace_cleaner.clean(backtrace)
  else
    backtrace_cleaner.clean([backtrace]).first
  end
end

.inherited(subclass) ⇒ Object



13
14
15
# File 'app/models/solid_apm/span_subscriber/base.rb', line 13

def self.inherited(subclass)
  subscribers << subclass
end

.subscribeObject



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
# File 'app/models/solid_apm/span_subscriber/base.rb', line 21

def self.subscribe
  ActiveSupport::Notifications.subscribe(self::PATTERN) do |name, start, finish, id, payload|
    next unless SpanSubscriber::Base.transaction

    subtype, type = name.split('.')
    duration = ((finish.to_f - start.to_f) * 1000).round(6)

    span = {
      uuid: SecureRandom.uuid,
      sequence: SpanSubscriber::Base.spans.size + 1,
      timestamp: start,
      end_time: finish,
      duration: duration,
      name: name,
      type: type,
      subtype: subtype,
      summary: self.new.summary(payload),
      stacktrace: clean_trace(caller_locations)
    }

    SpanSubscriber::Base.spans << span

    # Allow the subscriber to yield additional spans, like ending the transaction
    yield(name, start, finish, id, payload) if block_given?
  end
end

.subscribe!Object



17
18
19
# File 'app/models/solid_apm/span_subscriber/base.rb', line 17

def self.subscribe!
  subscribers.each(&:subscribe)
end

Instance Method Details

#clean_trace(backtrace) ⇒ Object



68
69
70
# File 'app/models/solid_apm/span_subscriber/base.rb', line 68

def clean_trace(backtrace)
  self.class.clean_trace(backtrace)
end