Class: OpenTelemetry::Exporter::OTLP::Exporter
- Inherits:
-
Object
- Object
- OpenTelemetry::Exporter::OTLP::Exporter
- Defined in:
- lib/opentelemetry/exporter/otlp/exporter.rb
Overview
An OpenTelemetry trace exporter that sends spans over HTTP as Protobuf encoded OTLP ExportTraceServiceRequests.
Instance Method Summary collapse
-
#export(span_data) ⇒ Integer
Called to export sampled SDK::Trace::SpanData structs.
-
#initialize(endpoint: config_opt('OTEL_EXPORTER_OTLP_SPAN_ENDPOINT', 'OTEL_EXPORTER_OTLP_ENDPOINT', default: 'localhost:55681/v1/trace'), insecure: config_opt('OTEL_EXPORTER_OTLP_SPAN_INSECURE', 'OTEL_EXPORTER_OTLP_INSECURE', default: false), certificate_file: config_opt('OTEL_EXPORTER_OTLP_SPAN_CERTIFICATE', 'OTEL_EXPORTER_OTLP_CERTIFICATE'), headers: config_opt('OTEL_EXPORTER_OTLP_SPAN_HEADERS', 'OTEL_EXPORTER_OTLP_HEADERS'), compression: config_opt('OTEL_EXPORTER_OTLP_SPAN_COMPRESSION', 'OTEL_EXPORTER_OTLP_COMPRESSION'), timeout: config_opt('OTEL_EXPORTER_OTLP_SPAN_TIMEOUT', 'OTEL_EXPORTER_OTLP_TIMEOUT', default: 10)) ⇒ Exporter
constructor
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity.
-
#shutdown ⇒ Object
Called when SDK::Trace::Tracer#shutdown is called, if this exporter is registered to a SDK::Trace::Tracer object.
Constructor Details
#initialize(endpoint: config_opt('OTEL_EXPORTER_OTLP_SPAN_ENDPOINT', 'OTEL_EXPORTER_OTLP_ENDPOINT', default: 'localhost:55681/v1/trace'), insecure: config_opt('OTEL_EXPORTER_OTLP_SPAN_INSECURE', 'OTEL_EXPORTER_OTLP_INSECURE', default: false), certificate_file: config_opt('OTEL_EXPORTER_OTLP_SPAN_CERTIFICATE', 'OTEL_EXPORTER_OTLP_CERTIFICATE'), headers: config_opt('OTEL_EXPORTER_OTLP_SPAN_HEADERS', 'OTEL_EXPORTER_OTLP_HEADERS'), compression: config_opt('OTEL_EXPORTER_OTLP_SPAN_COMPRESSION', 'OTEL_EXPORTER_OTLP_COMPRESSION'), timeout: config_opt('OTEL_EXPORTER_OTLP_SPAN_TIMEOUT', 'OTEL_EXPORTER_OTLP_TIMEOUT', default: 10)) ⇒ Exporter
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/opentelemetry/exporter/otlp/exporter.rb', line 33 def initialize(endpoint: config_opt('OTEL_EXPORTER_OTLP_SPAN_ENDPOINT', 'OTEL_EXPORTER_OTLP_ENDPOINT', default: 'localhost:55681/v1/trace'), # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity insecure: config_opt('OTEL_EXPORTER_OTLP_SPAN_INSECURE', 'OTEL_EXPORTER_OTLP_INSECURE', default: false), certificate_file: config_opt('OTEL_EXPORTER_OTLP_SPAN_CERTIFICATE', 'OTEL_EXPORTER_OTLP_CERTIFICATE'), headers: config_opt('OTEL_EXPORTER_OTLP_SPAN_HEADERS', 'OTEL_EXPORTER_OTLP_HEADERS'), # TODO: what format is expected here? compression: config_opt('OTEL_EXPORTER_OTLP_SPAN_COMPRESSION', 'OTEL_EXPORTER_OTLP_COMPRESSION'), timeout: config_opt('OTEL_EXPORTER_OTLP_SPAN_TIMEOUT', 'OTEL_EXPORTER_OTLP_TIMEOUT', default: 10)) raise ArgumentError, "invalid url for OTLP::Exporter #{endpoint}" if invalid_url?("http://#{endpoint}") raise ArgumentError, "unsupported compression key #{compression}" unless compression.nil? || compression == 'gzip' raise ArgumentError, 'headers must be comma-separated k:v pairs or a Hash' unless valid_headers?(headers) uri = URI "http://#{endpoint}" @http = Net::HTTP.new(uri.host, uri.port) @http.use_ssl = insecure.to_s.downcase == 'false' @http.ca_file = certificate_file unless certificate_file.nil? @http.keep_alive_timeout = KEEP_ALIVE_TIMEOUT @http.open_timeout = OPEN_TIMEOUT @http.read_timeout = READ_TIMEOUT @path = uri.path @headers = case headers when String then CSV.parse(headers, col_sep: ':', row_sep: ',').to_h when Hash then headers end @timeout = timeout.to_f # TODO: use this as a default timeout when we implement timeouts in https://github.com/open-telemetry/opentelemetry-ruby/pull/341 @compression = compression @shutdown = false end |
Instance Method Details
#export(span_data) ⇒ Integer
Called to export sampled SDK::Trace::SpanData structs.
68 69 70 71 72 |
# File 'lib/opentelemetry/exporter/otlp/exporter.rb', line 68 def export(span_data) return FAILURE if @shutdown send_bytes(encode(span_data)) end |
#shutdown ⇒ Object
Called when SDK::Trace::Tracer#shutdown is called, if this exporter is registered to a SDK::Trace::Tracer object.
77 78 79 80 |
# File 'lib/opentelemetry/exporter/otlp/exporter.rb', line 77 def shutdown @shutdown = true @http.finish if @http.started? end |