Class: RequestTagger::Setup

Inherits:
Object
  • Object
show all
Defined in:
lib/request_tagger/setup.rb

Class Method Summary collapse

Class Method Details

.http_tagObject



36
37
38
# File 'lib/request_tagger/setup.rb', line 36

def self.http_tag
  { field: http_tag_identifier, value: request_id }
end

.inbound_headerObject



28
29
30
# File 'lib/request_tagger/setup.rb', line 28

def self.inbound_header
  @options[:header] || 'HTTP_X_REQUEST_ID'
end

.request_idObject



47
48
49
# File 'lib/request_tagger/setup.rb', line 47

def self.request_id
  Thread.current[:__request_tagger__request_id__] || uninitialized
end

.request_id=(val) ⇒ Object



40
41
42
43
44
45
# File 'lib/request_tagger/setup.rb', line 40

def self.request_id=(val)
  # I would prefer not to use `Thread.current` for storage but, since we
  # can't control what kind of Rails server is in use, we don't have much
  # choice.
  Thread.current[:__request_tagger__request_id__] = val
end

.sql_tagObject



32
33
34
# File 'lib/request_tagger/setup.rb', line 32

def self.sql_tag
  "/* #{sql_tag_identifier}: #{sql_sanitize(request_id)} */"
end

.start(options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/request_tagger/setup.rb', line 7

def self.start(options = {})
  raise AlreadyStartedError, I18n.t('errors.start_once') if @initialized

  @options = options

  wrap_active_record
  wrap_http

  @initialized = true
end

.stopObject



18
19
20
21
22
23
24
25
26
# File 'lib/request_tagger/setup.rb', line 18

def self.stop
  return unless @initialized

  restore_active_record
  restore_http

  @options = {}
  @initialized = false
end