Class: Flare::MetricSpanProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/flare/metric_span_processor.rb

Overview

OpenTelemetry SpanProcessor that extracts metrics from spans. Aggregates counts, durations, and error rates by namespace/service/target/operation.

Constant Summary collapse

SERVER =

Standard OTel span kind symbols

:server
CLIENT =
:client
CONSUMER =
:consumer
CACHE_STORE_MAP =

Cache store class name patterns mapped to short service names

{
  "redis" => "redis",
  "mem_cache" => "memcache",
  "memcache" => "memcache",
  "dalli" => "memcache",
  "file" => "file",
  "memory" => "memory",
  "null" => "null",
  "solid_cache" => "solid_cache"
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(storage:, http_metrics_config: nil) ⇒ MetricSpanProcessor

Returns a new instance of MetricSpanProcessor.



29
30
31
32
33
# File 'lib/flare/metric_span_processor.rb', line 29

def initialize(storage:, http_metrics_config: nil)
  @storage = storage
  @http_metrics_config = http_metrics_config || HttpMetricsConfig::DEFAULT
  @pid = $$
end

Instance Method Details

#force_flush(timeout: nil) ⇒ Object



60
61
62
# File 'lib/flare/metric_span_processor.rb', line 60

def force_flush(timeout: nil)
  OpenTelemetry::SDK::Trace::Export::SUCCESS
end

#on_finish(span) ⇒ Object Also known as: on_end

Called when a span ends - extract and record metrics. OTel SDK 1.10+ calls on_finish; older versions call on_end.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/flare/metric_span_processor.rb', line 40

def on_finish(span)
  return unless span.end_timestamp && span.start_timestamp

  detect_forking

  if web_request?(span)
    record_web_metric(span)
  elsif background_job?(span)
    record_background_metric(span)
  elsif database_span?(span)
    record_db_metric(span)
  elsif http_client_span?(span)
    record_http_metric(span)
  elsif cache_span?(span)
    record_cache_metric(span)
  elsif view_span?(span)
    record_view_metric(span)
  end
end

#on_start(span, parent_context) ⇒ Object

Called when a span starts - no-op for metrics



36
# File 'lib/flare/metric_span_processor.rb', line 36

def on_start(span, parent_context); end

#shutdown(timeout: nil) ⇒ Object



66
67
68
# File 'lib/flare/metric_span_processor.rb', line 66

def shutdown(timeout: nil)
  OpenTelemetry::SDK::Trace::Export::SUCCESS
end