File: subscriber.rb

package info (click to toggle)
ruby-gitlab-labkit 0.36.1-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 444 kB
  • sloc: ruby: 1,705; makefile: 6
file content (35 lines) | stat: -rw-r--r-- 1,466 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
# frozen_string_literal: true

module Labkit
  module Tracing
    module Rails
      module ActiveSupport
        # ActiveSupport bridges action active support notifications to
        # the distributed tracing subsystem
        class Subscriber
          include Labkit::Tracing::TracingCommon

          CACHE_READ_TOPIC = "cache_read.active_support"
          CACHE_GENERATE_TOPIC = "cache_generate.active_support"
          CACHE_FETCH_HIT_TOPIC = "cache_fetch_hit.active_support"
          CACHE_WRITE_TOPIC = "cache_write.active_support"
          CACHE_DELETE_TOPIC = "cache_delete.active_support"

          # Instruments Rails ActiveSupport events for opentracing.
          # Returns a lambda, which, when called will unsubscribe from the notifications
          def self.instrument
            subscriptions = [
              ::ActiveSupport::Notifications.subscribe(CACHE_READ_TOPIC, CacheReadInstrumenter.new),
              ::ActiveSupport::Notifications.subscribe(CACHE_GENERATE_TOPIC, CacheGenerateInstrumenter.new),
              ::ActiveSupport::Notifications.subscribe(CACHE_FETCH_HIT_TOPIC, CacheFetchHitInstrumenter.new),
              ::ActiveSupport::Notifications.subscribe(CACHE_WRITE_TOPIC, CacheWriteInstrumenter.new),
              ::ActiveSupport::Notifications.subscribe(CACHE_DELETE_TOPIC, CacheDeleteInstrumenter.new),
            ]

            create_unsubscriber subscriptions
          end
        end
      end
    end
  end
end