Class: D13n::Metric::StreamState

Inherits:
Object
  • Object
show all
Defined in:
lib/d13n/metric/stream_state.rb

Constant Summary collapse

D13N_STREAM_HEADER =
'X-D13n-Stream-ID'
D13N_APP_HEADER =
'X-D13n-App'
REQUEST_ID_HEADER =
'HTTP_X_REQUEST_ID'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStreamState

Returns a new instance of StreamState.



39
40
41
42
43
44
# File 'lib/d13n/metric/stream_state.rb', line 39

def initialize
  @traced_span_stack = D13n::Metric::Stream::TracedSpanStack.new
  @current_stream = nil
  @referring_stream_id = nil
  @is_cross_app_caller = false
end

Instance Attribute Details

#current_streamObject

Returns the value of attribute current_stream.



35
36
37
# File 'lib/d13n/metric/stream_state.rb', line 35

def current_stream
  @current_stream
end

#is_cross_app_callerObject

Returns the value of attribute is_cross_app_caller.



37
38
39
# File 'lib/d13n/metric/stream_state.rb', line 37

def is_cross_app_caller
  @is_cross_app_caller
end

#referring_stream_idObject

Returns the value of attribute referring_stream_id.



37
38
39
# File 'lib/d13n/metric/stream_state.rb', line 37

def referring_stream_id
  @referring_stream_id
end

#requestObject

Returns the value of attribute request.



36
37
38
# File 'lib/d13n/metric/stream_state.rb', line 36

def request
  @request
end

#request_infoObject

Returns the value of attribute request_info.



33
34
35
# File 'lib/d13n/metric/stream_state.rb', line 33

def request_info
  @request_info
end

#tag_hashObject

Returns the value of attribute tag_hash.



34
35
36
# File 'lib/d13n/metric/stream_state.rb', line 34

def tag_hash
  @tag_hash
end

#traced_span_stackObject (readonly)

Returns the value of attribute traced_span_stack.



32
33
34
# File 'lib/d13n/metric/stream_state.rb', line 32

def traced_span_stack
  @traced_span_stack
end

Class Method Details

.default_metric_dataObject



22
23
24
25
26
27
28
29
30
# File 'lib/d13n/metric/stream_state.rb', line 22

def self.default_metric_data
  state = st_get
  stream = state.current_stream
  if stream
    stream.default_metric_data
  else
    {}
  end
end

.request_infoObject



18
19
20
# File 'lib/d13n/metric/stream_state.rb', line 18

def self.request_info
  st_get.request_info
end

.st_getObject



10
11
12
# File 'lib/d13n/metric/stream_state.rb', line 10

def self.st_get
  st_state_for(Thread.current)
end

.st_state_for(thread) ⇒ Object



14
15
16
# File 'lib/d13n/metric/stream_state.rb', line 14

def self.st_state_for(thread)
  thread[:d13n_stream_state] ||= new
end

Instance Method Details

#clear_referring_stream_idObject



64
65
66
# File 'lib/d13n/metric/stream_state.rb', line 64

def clear_referring_stream_id()
  @referring_stream_id = nil
end

#notify_call(request) ⇒ Object



56
57
58
# File 'lib/d13n/metric/stream_state.rb', line 56

def notify_call(request)
  save_referring_stream_id(request)
end

#notify_rack_call(request) ⇒ Object



52
53
54
# File 'lib/d13n/metric/stream_state.rb', line 52

def notify_rack_call(request)
  notify_call(request)
end

#reset(stream = nil) ⇒ Object



46
47
48
49
50
# File 'lib/d13n/metric/stream_state.rb', line 46

def reset(stream=nil)
  @traced_span_stack.clear
  @current_stream = stream
  @is_cross_app_caller = false
end

#save_referring_stream_id(request) ⇒ Object



60
61
62
# File 'lib/d13n/metric/stream_state.rb', line 60

def save_referring_stream_id(request)
  @referring_stream_id = request[D13N_STREAM_HEADER] if request[D13N_STREAM_HEADER]
end