class Datadog::SyncWriter

SyncWriter flushes both services and traces synchronously DEV: To be replaced by Datadog::Workers::TraceWriter.

Attributes

priority_sampler[R]
transport[R]

Public Class Methods

new(options = {}) click to toggle source
# File lib/ddtrace/sync_writer.rb, line 13
def initialize(options = {})
  @transport = options.fetch(:transport) do
    transport_options = options.fetch(:transport_options, {})
    Transport::HTTP.default(transport_options)
  end

  @priority_sampler = options.fetch(:priority_sampler, nil)
end

Public Instance Methods

stop() click to toggle source

Added for interface completeness

# File lib/ddtrace/sync_writer.rb, line 40
def stop
  # No cleanup to do for the SyncWriter
  true
end
write(trace, services = nil) click to toggle source
# File lib/ddtrace/sync_writer.rb, line 22
def write(trace, services = nil)
  unless services.nil?
    Datadog::Patcher.do_once('SyncWriter#write') do
      Datadog.logger.warn(%(
        write: Writing services has been deprecated and no longer need to be provided.
        write(traces, services) can be updted to write(traces)
      ))
    end
  end

  perform_concurrently(
    proc { flush_trace(trace) }
  )
rescue => e
  Datadog.logger.debug(e)
end

Private Instance Methods

flush_trace(trace) click to toggle source
# File lib/ddtrace/sync_writer.rb, line 51
def flush_trace(trace)
  processed_traces = Pipeline.process!([trace])
  return if processed_traces.empty?
  inject_hostname!(processed_traces.first) if Datadog.configuration.report_hostname
  transport.send_traces(processed_traces)
end
inject_hostname!(trace) click to toggle source
# File lib/ddtrace/sync_writer.rb, line 58
def inject_hostname!(trace)
  unless trace.first.nil?
    hostname = Datadog::Runtime::Socket.hostname
    unless hostname.nil? || hostname.empty?
      trace.first.set_tag(Ext::NET::TAG_HOSTNAME, hostname)
    end
  end
end
perform_concurrently(*tasks) click to toggle source
# File lib/ddtrace/sync_writer.rb, line 47
def perform_concurrently(*tasks)
  tasks.map { |task| Thread.new(&task) }.each(&:join)
end