Class: Brut::Instrumentation::LoggerSpanExporter

Inherits:
Object
  • Object
show all
Defined in:
lib/brut/instrumentation/logger_span_exporter.rb

Overview

Based on OpenTelemetry::SDK::Trace::Export::ConsoleSpanExporter, but designed to log spans in a more traditional log-style format.

Constant Summary collapse

NO_PARENT =
"0000000000000000"

Instance Method Summary collapse

Constructor Details

#initializeLoggerSpanExporter

Returns a new instance of LoggerSpanExporter.



4
5
6
7
# File 'lib/brut/instrumentation/logger_span_exporter.rb', line 4

def initialize
  @stopped = false
  @child_spans = {}
end

Instance Method Details

#export(spans, timeout: nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/brut/instrumentation/logger_span_exporter.rb', line 11

def export(spans, timeout: nil)
  if @stopped
    SemanticLogger[self.class].warn "Attempt to export spans after exporter was shut down"
    return failure
  end

  Array(spans).each do |span|
    if span.hex_parent_span_id == NO_PARENT
      log_span(span:,indent: 0)
    elsif span.attributes["http.user_agent"]
      log_span(span:,indent: 0, synthetic_attributes: { browser: true })
    else
      @child_spans[span.hex_parent_span_id] ||= []
      @child_spans[span.hex_parent_span_id] << span
    end
  end

  success
end

#force_flush(timeout: nil) ⇒ Object



31
32
33
# File 'lib/brut/instrumentation/logger_span_exporter.rb', line 31

def force_flush(timeout: nil)
  success
end

#shutdown(timeout: nil) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/brut/instrumentation/logger_span_exporter.rb', line 35

def shutdown(timeout: nil)
  @stopped = true
  if @child_spans.any?
    SemanticLogger[self.class].warn "There were #{@child_spans.length} spans un-logged"
  end
  success
end