Class: Errorgap::SpanRecorder

Inherits:
Object
  • Object
show all
Defined in:
lib/errorgap/span_recorder.rb

Overview

Yielded to Errorgap.track_transaction / track_job blocks so callers can record spans manually (outside Rails' automatic sql.active_record instrumentation) — e.g. outbound HTTP calls or queries in a plain Ruby service. Spans are appended to the same thread-local store the automatic collector uses, so manual and automatic spans merge into one transaction.

Instance Method Summary collapse

Instance Method Details

#add(span) ⇒ Object



27
28
29
# File 'lib/errorgap/span_recorder.rb', line 27

def add(span)
  SpanCollector.store << span
end

#database(sql, duration_ms, file: nil, line: nil, fn_name: nil) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/errorgap/span_recorder.rb', line 10

def database(sql, duration_ms, file: nil, line: nil, fn_name: nil)
  SpanCollector.store << Span.new(
    kind: "db",
    sql: SpanCollector.normalize_sql(sql.to_s),
    file: file, line: line, fn_name: fn_name,
    duration_ms: duration_ms.to_f.round(3)
  )
end

#external(duration_ms, file: nil, line: nil, fn_name: nil) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/errorgap/span_recorder.rb', line 19

def external(duration_ms, file: nil, line: nil, fn_name: nil)
  SpanCollector.store << Span.new(
    kind: "http",
    file: file, line: line, fn_name: fn_name,
    duration_ms: duration_ms.to_f.round(3)
  )
end