Class: StackifyRubyAPM::Subscriber Private

Inherits:
Object
  • Object
show all
Includes:
Log
Defined in:
lib/stackify_apm/subscriber.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Defined Under Namespace

Classes: Notification

Constant Summary

Constants included from Log

Log::PREFIX

Instance Method Summary collapse

Methods included from Log

#debug, #error, #fatal, #info, #log, #warn

Constructor Details

#initialize(agent) ⇒ Subscriber

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Subscriber.



14
15
16
17
18
19
# File 'lib/stackify_apm/subscriber.rb', line 14

def initialize(agent)
  debug '[Subscriber] initialize()'
  debug agent.inspect
  @agent = agent
  @normalizers = Normalizers.build(agent.config)
end

Instance Method Details

#call(name, started, finished, id, payload) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

call

Called when the rails version is 3.x

rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/stackify_apm/subscriber.rb', line 40

def call(name, started, finished, id, payload)
  return unless (transaction = @agent.current_transaction)

  debug '[Subscriber] call():'
  debug id
  debug name
  debug transaction

  normalized = @normalizers.normalize(transaction, name, payload)

  if started
    span =
      if normalized == :skip
        nil
      else
        name, type, context = normalized
        @agent.span(name, type, context: context)
      end
    transaction.notifications << Notification.new(id, span)
  end
  # rubocop:enable Metrics/CyclomaticComplexity
  # rubocop:enable Metrics/PerceivedComplexity
  # rubocop:disable Style/GuardClause

  if finished
    while (notification = transaction.notifications.pop)
      next unless notification.id == id
      if (span = notification.span)
        span.done
      end
      return
    end
  end
  # rubocop:enable Style/GuardClause
end

#finish(_name, id, _payload) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

finish

Called when the rails version is NOT 3.x



98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/stackify_apm/subscriber.rb', line 98

def finish(_name, id, _payload)
  # debug "AS::Notification#finish:#{name}:#{id}"
  debug '[Subscriber] finish():'
  return unless (transaction = @agent.current_transaction)

  while (notification = transaction.notifications.pop)
    next unless notification.id == id

    if (span = notification.span)
      span.done
    end
    return
  end
end

#register!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



21
22
23
24
25
26
# File 'lib/stackify_apm/subscriber.rb', line 21

def register!
  unregister! if @subscription

  @subscription =
    ActiveSupport::Notifications.subscribe(notifications_regex, self)
end

#start(name, id, payload) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

start

Called when the rails version is NOT 3.x



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/stackify_apm/subscriber.rb', line 77

def start(name, id, payload)
  return unless (transaction = @agent.current_transaction)

  debug '[Subscriber] start():'
  debug id
  debug name
  debug transaction
  normalized = @normalizers.normalize(transaction, name, payload)

  span =
    if normalized == :skip
      nil
    else
      name, type, context = normalized
      @agent.span(name, type, context: context)
    end

  transaction.notifications << Notification.new(id, span)
end

#unregister!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



28
29
30
31
# File 'lib/stackify_apm/subscriber.rb', line 28

def unregister!
  ActiveSupport::Notifications.unsubscribe @subscription
  @subscription = nil
end