Module: D13n::Metric::Stream::SpanTracerHelpers
- Extended by:
- SpanTracerHelpers
- Included in:
- SpanTracerHelpers
- Defined in:
- lib/d13n/metric/stream/span_tracer_helpers.rb
Constant Summary collapse
- MAX_ALLOWED_METRIC_DURATION =
1_000_000_000
Instance Method Summary collapse
- #collect_span_duration_timing(collector, state, name, timing, metric_data, options, rate = 1.0) ⇒ Object
- #collect_span_exclusive_timing(collector, state, name, timing, metric_data, options, rate = 1.0) ⇒ Object
- #collect_span_metrics(state, first_name, duration, exclusive, metric_data, options) ⇒ Object
- #collect_span_request_count(collector, state, name, metric_data, options, count = 1, rate = 1.0) ⇒ Object
- #get_metric_data(state, t0, t1, metric_data) ⇒ Object
- #get_timings(t0, t1, frame) ⇒ Object
- #trace_footer(state, t0, first_name, expected_frame, options, t1 = Time.now.to_f) ⇒ Object
- #trace_header(state, t0) ⇒ Object
Methods included from D13n::Metric::Stream::StreamTracerHelpers::Namer
#metric_name, #prefix, #stream_apdex_tags, #stream_basic_tags, #stream_duration_tags, #stream_error_tags, #stream_exclusive_tags, #stream_http_request_content_length_tags, #stream_http_response_code_tags, #stream_http_response_content_length_tags, #stream_http_response_content_type_tags, #stream_request_tags
Instance Method Details
#collect_span_duration_timing(collector, state, name, timing, metric_data, options, rate = 1.0) ⇒ Object
11 12 13 |
# File 'lib/d13n/metric/stream/span_tracer_helpers.rb', line 11 def collect_span_duration_timing(collector, state, name, timing, metric_data, , rate=1.0) collector.measure(metric_name("timing"), timing, sample_rate: rate, tags: (metric_data)) end |
#collect_span_exclusive_timing(collector, state, name, timing, metric_data, options, rate = 1.0) ⇒ Object
15 16 17 |
# File 'lib/d13n/metric/stream/span_tracer_helpers.rb', line 15 def collect_span_exclusive_timing(collector, state, name, timing, metric_data, , rate=1.0) collector.measure(metric_name("timing"), timing, sample_rate: rate, tags: (metric_data)) end |
#collect_span_metrics(state, first_name, duration, exclusive, metric_data, options) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/d13n/metric/stream/span_tracer_helpers.rb', line 23 def collect_span_metrics(state, first_name, duration, exclusive, metric_data, ) collector = D13n::Metric::Manager.instance collect_span_duration_timing(collector, state, first_name, duration, metric_data, ) collect_span_exclusive_timing(collector, state, first_name, exclusive, metric_data, ) collect_span_request_count(collector, state, first_name, metric_data, ) end |
#collect_span_request_count(collector, state, name, metric_data, options, count = 1, rate = 1.0) ⇒ Object
19 20 21 |
# File 'lib/d13n/metric/stream/span_tracer_helpers.rb', line 19 def collect_span_request_count(collector, state, name, metric_data, , count = 1, rate = 1.0) collector.increment(metric_name("count"), count, sample_rate: rate, tags: (metric_data)) end |
#get_metric_data(state, t0, t1, metric_data) ⇒ Object
66 67 68 69 |
# File 'lib/d13n/metric/stream/span_tracer_helpers.rb', line 66 def get_metric_data(state, t0, t1, metric_data) stream = state.current_stream stream.generate_default_metric_data(state, t0, t1, metric_data) end |
#get_timings(t0, t1, frame) ⇒ Object
60 61 62 63 64 |
# File 'lib/d13n/metric/stream/span_tracer_helpers.rb', line 60 def get_timings(t0, t1, frame) duration = t1 - t0 exclusive = duration - frame.children_time [duration, exclusive] end |
#trace_footer(state, t0, first_name, expected_frame, options, t1 = Time.now.to_f) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/d13n/metric/stream/span_tracer_helpers.rb', line 35 def (state, t0, first_name, expected_frame, , t1=Time.now.to_f) if expected_frame stack = state.traced_span_stack frame = stack.pop_frame(state, expected_frame, first_name, t1) duration, exclusive = get_timings(t0, t1, frame) metric_data = {:exclusive => exclusive} get_metric_data(state, t0, t1, metric_data) if duration < MAX_ALLOWED_METRIC_DURATION if duration < 0 D13n.logger.warn("metric_duration_negative:#{first_name} Metric #{first_name} has negative duration: #{duration} s") end if exclusive < 0 D13n.logger.warn("metric_exclusive_negative: #{first_name} Metric #{first_name} has negative exclusive time: duration = #{duration} s, child_time = #{frame.children_time}") end collect_span_metrics(state, first_name, duration, exclusive, metric_data, ) else D13n.logger.warn("too_huge_metric:#{first_name}, Ignoring metric #{first_name} with unacceptably large duration: #{duration} s") end end end |
#trace_header(state, t0) ⇒ Object
30 31 32 33 |
# File 'lib/d13n/metric/stream/span_tracer_helpers.rb', line 30 def trace_header(state, t0) stack = state.traced_span_stack stack.push_frame(state, :span_tracer, t0) end |