/
tracing.rb
68 lines (53 loc) · 1.86 KB
/
tracing.rb
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
module Sentry
module Rails
module Tracing
START_TIMESTAMP_NAME = :sentry_start_timestamp
def self.register_subscribers(subscribers)
@subscribers = subscribers
end
def self.subscribers
@subscribers
end
def self.subscribe_tracing_events
# need to avoid duplicated subscription
return if @subscribed
subscribers.each(&:subscribe!)
@subscribed = true
end
def self.unsubscribe_tracing_events
return unless @subscribed
subscribers.each(&:unsubscribe!)
@subscribed = false
end
# this is necessary because instrumentation events don't record absolute start/finish time
# so we need to retrieve the correct time this way
def self.patch_active_support_notifications
unless ::ActiveSupport::Notifications::Instrumenter.ancestors.include?(SentryNotificationExtension)
::ActiveSupport::Notifications::Instrumenter.send(:prepend, SentryNotificationExtension)
end
SentryNotificationExtension.module_eval do
def instrument(name, payload = {}, &block)
is_public_event = name[0] != "!"
payload[START_TIMESTAMP_NAME] = Time.now.utc.to_f if is_public_event
super(name, payload, &block)
end
end
end
def self.remove_active_support_notifications_patch
if ::ActiveSupport::Notifications::Instrumenter.ancestors.include?(SentryNotificationExtension)
SentryNotificationExtension.module_eval do
def instrument(name, payload = {}, &block)
super
end
end
end
end
def self.get_current_transaction
Sentry.get_current_scope.get_transaction
end
# it's just a container for the extended method
module SentryNotificationExtension
end
end
end
end