Class: OpenTelemetry::Exporter::Jaeger::CollectorExporter

Inherits:
Object
  • Object
show all
Defined in:
lib/opentelemetry/exporter/jaeger/collector_exporter.rb

Overview

An OpenTelemetry trace exporter that sends spans over HTTP as Thrift Binary encoded Jaeger spans.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint: ENV.fetch('OTEL_EXPORTER_JAEGER_ENDPOINT', 'http://localhost:14268/api/traces'), username: ENV['OTEL_EXPORTER_JAEGER_USER'], password: ENV['OTEL_EXPORTER_JAEGER_PASSWORD'], timeout: ENV.fetch('OTEL_EXPORTER_JAEGER_TIMEOUT', 10), ssl_verify_mode: CollectorExporter.ssl_verify_mode, metrics_reporter: nil) ⇒ CollectorExporter

Returns a new instance of CollectorExporter.

Raises:

  • (ArgumentError)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/opentelemetry/exporter/jaeger/collector_exporter.rb', line 28

def initialize(endpoint: ENV.fetch('OTEL_EXPORTER_JAEGER_ENDPOINT', 'http://localhost:14268/api/traces'),
               username: ENV['OTEL_EXPORTER_JAEGER_USER'],
               password: ENV['OTEL_EXPORTER_JAEGER_PASSWORD'],
               timeout: ENV.fetch('OTEL_EXPORTER_JAEGER_TIMEOUT', 10),
               ssl_verify_mode: CollectorExporter.ssl_verify_mode,
               metrics_reporter: nil)
  raise ArgumentError, "invalid url for Jaeger::CollectorExporter #{endpoint}" unless OpenTelemetry::Common::Utilities.valid_url?(endpoint)
  raise ArgumentError, 'username and password should either both be nil or both be set' if username.nil? != password.nil?

  transport_opts = { ssl_verify_mode: Integer(ssl_verify_mode) }
  @transport = ::Thrift::HTTPClientTransport.new(endpoint, transport_opts)
  unless username.nil? || password.nil?
    authorization = Base64.strict_encode64("#{username}:#{password}")
    auth_header = { 'Authorization': "Basic #{authorization}" }
    @transport.add_headers(auth_header)
  end
  @serializer = ::Thrift::Serializer.new
  @metrics_reporter = metrics_reporter || OpenTelemetry::SDK::Trace::Export::MetricsReporter
  @shutdown = false
end

Class Method Details

.ssl_verify_modeObject



18
19
20
21
22
23
24
25
26
# File 'lib/opentelemetry/exporter/jaeger/collector_exporter.rb', line 18

def self.ssl_verify_mode
  if ENV.key?('OTEL_RUBY_EXPORTER_JAEGER_SSL_VERIFY_PEER')
    OpenSSL::SSL::VERIFY_PEER
  elsif ENV.key?('OTEL_RUBY_EXPORTER_JAEGER_SSL_VERIFY_NONE')
    OpenSSL::SSL::VERIFY_NONE
  else
    OpenSSL::SSL::VERIFY_PEER
  end
end

Instance Method Details

#export(span_data, timeout: nil) ⇒ Integer

Called to export sampled SDK::Trace::SpanData structs.

Parameters:

  • span_data (Enumerable<OpenTelemetry::SDK::Trace::SpanData>)

    the list of recorded SDK::Trace::SpanData structs to be exported.

  • timeout (optional Numeric) (defaults to: nil)

    An optional timeout in seconds.

Returns:

  • (Integer)

    the result of the export.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/opentelemetry/exporter/jaeger/collector_exporter.rb', line 56

def export(span_data, timeout: nil)
  return FAILURE if @shutdown

  encoded_batches(span_data).each do |batch|
    @transport.write(@serializer.serialize(batch))
  end

  OpenTelemetry::Common::Utilities.untraced do
    measure_request_duration do
      @transport.flush
    end
  end
  SUCCESS
rescue StandardError => e
  @metrics_reporter.add_to_counter('otel.jaeger_exporter.failure', labels: { 'reason' => e.class.to_s })
  OpenTelemetry.handle_error(exception: e, message: 'unexpected error in Jaeger::CollectorExporter#export')
  FAILURE
end

#force_flush(timeout: nil) ⇒ Object

Called when SDK::Trace::TracerProvider#force_flush is called, if this exporter is registered to a SDK::Trace::TracerProvider object.

Parameters:

  • timeout (optional Numeric) (defaults to: nil)

    An optional timeout in seconds.



80
81
82
# File 'lib/opentelemetry/exporter/jaeger/collector_exporter.rb', line 80

def force_flush(timeout: nil)
  SUCCESS
end

#shutdown(timeout: nil) ⇒ Object

Called when SDK::Trace::TracerProvider#shutdown is called, if this exporter is registered to a SDK::Trace::TracerProvider object.

Parameters:

  • timeout (optional Numeric) (defaults to: nil)

    An optional timeout in seconds.



89
90
91
92
# File 'lib/opentelemetry/exporter/jaeger/collector_exporter.rb', line 89

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