Class: Bitfab::Otel::CollectorExporter

Inherits:
OpenTelemetry::Exporter::OTLP::Exporter
  • Object
show all
Defined in:
lib/bitfab/otel_collector.rb

Overview

OTLP/HTTP protobuf delivery to a customer's Collector.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key:, **options) ⇒ CollectorExporter

Returns a new instance of CollectorExporter.



14
15
16
17
# File 'lib/bitfab/otel_collector.rb', line 14

def initialize(api_key:, **options)
  super(**options)
  @api_key = api_key
end

Class Method Details

.traces_endpoint(endpoint) ⇒ Object



9
10
11
12
# File 'lib/bitfab/otel_collector.rb', line 9

def self.traces_endpoint(endpoint)
  base = endpoint.chomp("/")
  base.end_with?("/v1/traces") ? base : "#{base}/v1/traces"
end

Instance Method Details

#export(span_data, timeout: nil) ⇒ Object

The OTLP exporter reads headers once at construction, while a Bitfab key is resolved at request time (an env var may load after the client is built).



21
22
23
24
25
# File 'lib/bitfab/otel_collector.rb', line 21

def export(span_data, timeout: nil)
  key = @api_key.respond_to?(:call) ? @api_key.call : @api_key
  @headers = @headers.merge("Authorization" => "Bearer #{key}")
  super
end