Class: OpenTelemetry::Exporter::Zipkin::Exporter
- Inherits:
-
Object
- Object
- OpenTelemetry::Exporter::Zipkin::Exporter
- Defined in:
- lib/opentelemetry/exporter/zipkin/exporter.rb
Overview
An OpenTelemetry trace exporter that sends spans over HTTP as JSON encoded Zipkin spans.
Instance Method Summary collapse
-
#export(span_data, timeout: nil) ⇒ Integer
Called to export sampled SDK::Trace::SpanData structs.
-
#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.
-
#initialize(endpoint: OpenTelemetry::Common::Utilities.config_opt('OTEL_EXPORTER_ZIPKIN_ENDPOINT', default: 'http://localhost:9411/api/v2/spans'), headers: OpenTelemetry::Common::Utilities.config_opt('OTEL_EXPORTER_ZIPKIN_TRACES_HEADERS', 'OTEL_EXPORTER_ZIPKIN_HEADERS'), timeout: OpenTelemetry::Common::Utilities.config_opt('OTEL_EXPORTER_ZIPKIN_TRACES_TIMEOUT', 'OTEL_EXPORTER_ZIPKIN_TIMEOUT', default: 10), metrics_reporter: nil) ⇒ Exporter
constructor
A new instance of Exporter.
-
#shutdown(timeout: nil) ⇒ Object
Called when SDK::Trace::Tracer#shutdown is called, if this exporter is registered to a SDK::Trace::Tracer object.
Constructor Details
#initialize(endpoint: OpenTelemetry::Common::Utilities.config_opt('OTEL_EXPORTER_ZIPKIN_ENDPOINT', default: 'http://localhost:9411/api/v2/spans'), headers: OpenTelemetry::Common::Utilities.config_opt('OTEL_EXPORTER_ZIPKIN_TRACES_HEADERS', 'OTEL_EXPORTER_ZIPKIN_HEADERS'), timeout: OpenTelemetry::Common::Utilities.config_opt('OTEL_EXPORTER_ZIPKIN_TRACES_TIMEOUT', 'OTEL_EXPORTER_ZIPKIN_TIMEOUT', default: 10), metrics_reporter: nil) ⇒ Exporter
Returns a new instance of Exporter.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/opentelemetry/exporter/zipkin/exporter.rb', line 29 def initialize(endpoint: OpenTelemetry::Common::Utilities.config_opt('OTEL_EXPORTER_ZIPKIN_ENDPOINT', default: 'http://localhost:9411/api/v2/spans'), headers: OpenTelemetry::Common::Utilities.config_opt('OTEL_EXPORTER_ZIPKIN_TRACES_HEADERS', 'OTEL_EXPORTER_ZIPKIN_HEADERS'), timeout: OpenTelemetry::Common::Utilities.config_opt('OTEL_EXPORTER_ZIPKIN_TRACES_TIMEOUT', 'OTEL_EXPORTER_ZIPKIN_TIMEOUT', default: 10), metrics_reporter: nil) raise ArgumentError, "invalid url for Zipkin::Exporter #{endpoint}" unless OpenTelemetry::Common::Utilities.valid_url?(endpoint) raise ArgumentError, 'headers must be comma-separated k=v pairs or a Hash' unless valid_headers?(headers) @uri = if endpoint == ENV['OTEL_EXPORTER_ZIPKIN_ENDPOINT'] URI("#{endpoint}/api/v2/spans") else URI(endpoint) end @http = Net::HTTP.new(@uri.host, @uri.port) @http.use_ssl = @uri.scheme == 'https' @http.keep_alive_timeout = KEEP_ALIVE_TIMEOUT @timeout = timeout.to_f @path = @uri.path @headers = case headers when String then CSV.parse(headers, col_sep: '=', row_sep: ',').to_h when Hash then headers end @metrics_reporter = metrics_reporter || OpenTelemetry::SDK::Trace::Export::MetricsReporter @shutdown = false end |
Instance Method Details
#export(span_data, timeout: nil) ⇒ Integer
Called to export sampled SDK::Trace::SpanData structs.
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/opentelemetry/exporter/zipkin/exporter.rb', line 64 def export(span_data, timeout: nil) return FAILURE if @shutdown zipkin_spans = encode_spans(span_data) send_spans(zipkin_spans, timeout: timeout) rescue StandardError => e @metrics_reporter.add_to_counter('otel.zipkin_exporter.failure', labels: { 'reason' => e.class.to_s }) OpenTelemetry.handle_error(exception: e, message: 'unexpected error in Zipkin::Exporter#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.
80 81 82 |
# File 'lib/opentelemetry/exporter/zipkin/exporter.rb', line 80 def force_flush(timeout: nil) SUCCESS end |
#shutdown(timeout: nil) ⇒ Object
Called when SDK::Trace::Tracer#shutdown is called, if this exporter is registered to a SDK::Trace::Tracer object.
92 93 94 95 |
# File 'lib/opentelemetry/exporter/zipkin/exporter.rb', line 92 def shutdown(timeout: nil) @shutdown = true SUCCESS end |