Class: Bitfab::Otel::DirectExporter
- Inherits:
-
Object
- Object
- Bitfab::Otel::DirectExporter
- Defined in:
- lib/bitfab/otel.rb
Overview
Encodes carrier spans as OTLP/JSON and posts them straight to Bitfab.
Instance Method Summary collapse
- #export(spans, timeout: nil) ⇒ Object
- #force_flush(timeout: nil) ⇒ Object
-
#initialize(direct_sender:, max_request_bytes:, max_request_batch_size:, export_concurrency:, on_delivered: nil) ⇒ DirectExporter
constructor
A new instance of DirectExporter.
- #shutdown(timeout: nil) ⇒ Object
Constructor Details
#initialize(direct_sender:, max_request_bytes:, max_request_batch_size:, export_concurrency:, on_delivered: nil) ⇒ DirectExporter
Returns a new instance of DirectExporter.
232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/bitfab/otel.rb', line 232 def initialize(direct_sender:, max_request_bytes:, max_request_batch_size:, export_concurrency:, on_delivered: nil) @direct_sender = direct_sender @on_delivered = on_delivered @max_request_bytes = max_request_bytes @max_request_batch_size = max_request_batch_size @export_concurrency = export_concurrency # Eager, unlike the module-level mutexes: this one is first touched by # the export threads fanning out a batch, and `||=` racing between them # would hand each a different mutex and no mutual exclusion at all. @throttle_mutex = Mutex.new @throttled_until = 0.0 end |
Instance Method Details
#export(spans, timeout: nil) ⇒ Object
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/bitfab/otel.rb', line 245 def export(spans, timeout: nil) spans = spans.to_a return SUCCESS if spans.empty? begin encoded = spans.map { |span| Encoder.encode_span(span) } envelope = Encoder.request_envelope(spans.first) rescue => e Bitfab.warn_once( "otel-encode-failed", "failed to encode an OpenTelemetry span batch (#{e.})" ) return FAILURE end batches = build_request_batches(envelope, encoded) results = send_batches(envelope, batches) results.all? ? SUCCESS : FAILURE end |
#force_flush(timeout: nil) ⇒ Object
265 266 267 |
# File 'lib/bitfab/otel.rb', line 265 def force_flush(timeout: nil) SUCCESS end |
#shutdown(timeout: nil) ⇒ Object
269 270 271 |
# File 'lib/bitfab/otel.rb', line 269 def shutdown(timeout: nil) SUCCESS end |