Class: TracecapOpenTelemetry::Exporter

Inherits:
OpenTelemetry::SDK::Trace::Export::InMemorySpanExporter
  • Object
show all
Defined in:
lib/tracecap_opentelemetry/exporter.rb

Overview

pretend to be this for now for ‘simple_exporter?’ check

Constant Summary collapse

SUCCESS =
OpenTelemetry::SDK::Trace::Export::SUCCESS
FAILURE =
OpenTelemetry::SDK::Trace::Export::FAILURE

Instance Method Summary collapse

Constructor Details

#initializeExporter

Returns a new instance of Exporter.



10
11
12
# File 'lib/tracecap_opentelemetry/exporter.rb', line 10

def initialize
  @stopped = false
end

Instance Method Details

#export(spans, timeout: nil) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/tracecap_opentelemetry/exporter.rb', line 14

def export(spans, timeout: nil)
  return FAILURE if @stopped

  return SUCCESS unless TracecapOpenTelemetry::active?

  Array(spans).each do |span|
    tags = span.attributes
    component = tags["db.system"] || tags["component"] || "Trace"

    operation = span.name

    context = tags.dup
    context["span_id"] = span.hex_span_id
    context["span_parent_id"] = span.hex_parent_span_id if span.hex_parent_span_id != "0000000000000000"
    json_ctx = JSON.dump(context)

    start_time_nsec = span.start_timestamp.to_i
    end_time_nsec = span.end_timestamp.to_i
    now_nsec = (Time.now.to_r * 1_000_000_000).to_i
    duration = end_time_nsec - start_time_nsec
    end_delta = now_nsec - end_time_nsec

    TracecapOpenTelemetry::emit_span(duration, end_delta, component.to_s, operation.to_s, json_ctx)
  end

  SUCCESS
end

#force_flush(timeout: nil) ⇒ Object



42
43
44
# File 'lib/tracecap_opentelemetry/exporter.rb', line 42

def force_flush(timeout: nil)
  SUCCESS
end

#shutdown(timeout: nil) ⇒ Object



46
47
48
49
# File 'lib/tracecap_opentelemetry/exporter.rb', line 46

def shutdown(timeout: nil)
  @stopped = true
  SUCCESS
end