Sha256: 419b493f305c73631acba473cdd243f778aa36d575ad030971f6e4d96612eda3
Contents?: true
Size: 1.22 KB
Versions: 4
Compression:
Stored size: 1.22 KB
Contents
require_relative './udp_sender/transport' require 'jaeger/thrift/agent' require 'thread' module Jaeger module Client class UdpSender def initialize(service_name:, host:, port:, collector:, flush_interval:) @service_name = service_name @collector = collector @flush_interval = flush_interval transport = Transport.new(host, port) protocol = ::Thrift::CompactProtocol.new(transport) @client = Jaeger::Thrift::Agent::Client.new(protocol) end def start # Sending spans in a separate thread to avoid blocking the main thread. @thread = Thread.new do loop do emit_batch(@collector.retrieve) sleep @flush_interval end end end def stop @thread.terminate if @thread emit_batch(@collector.retrieve) end private def emit_batch(thrift_spans) return if thrift_spans.empty? batch = Jaeger::Thrift::Batch.new( 'process' => Jaeger::Thrift::Process.new( 'serviceName' => @service_name, 'tags' => [], ), 'spans' => thrift_spans ) @client.emitBatch(batch) end end end end
Version data entries
4 entries across 4 versions & 1 rubygems