class Datadog::Workers::TraceWriter
Writes traces to transport synchronously
Attributes
transport[R]
Public Class Methods
new(options = {})
click to toggle source
# File lib/ddtrace/workers/trace_writer.rb, line 16 def initialize(options = {}) transport_options = options.fetch(:transport_options, {}) if transport_options.is_a?(Proc) transport_options = { on_build: transport_options } end transport_options[:hostname] = options[:hostname] if options.key?(:hostname) transport_options[:port] = options[:port] if options.key?(:port) @transport = options.fetch(:transport) do Transport::HTTP.default(transport_options) end end
Public Instance Methods
flush_completed()
click to toggle source
TODO: Register `Datadog::Diagnostics::EnvironmentLogger.log!` TODO: as a flush_completed
subscriber when the `TraceWriter` TODO: instantiation code is implemented.
# File lib/ddtrace/workers/trace_writer.rb, line 78 def flush_completed @flush_completed ||= FlushCompleted.new end
flush_traces(traces)
click to toggle source
# File lib/ddtrace/workers/trace_writer.rb, line 58 def flush_traces(traces) transport.send_traces(traces).tap do |response| flush_completed.publish(response) end end
inject_hostname!(traces)
click to toggle source
# File lib/ddtrace/workers/trace_writer.rb, line 64 def inject_hostname!(traces) traces.each do |trace| next if 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(traces)
click to toggle source
# File lib/ddtrace/workers/trace_writer.rb, line 31 def perform(traces) write_traces(traces) end
process_traces(traces)
click to toggle source
# File lib/ddtrace/workers/trace_writer.rb, line 48 def process_traces(traces) # Run traces through the processing pipeline traces = Pipeline.process!(traces) # Inject hostname if configured to do so inject_hostname!(traces) if Datadog.configuration.report_hostname traces end
write(trace)
click to toggle source
# File lib/ddtrace/workers/trace_writer.rb, line 35 def write(trace) write_traces([trace]) end
write_traces(traces)
click to toggle source
# File lib/ddtrace/workers/trace_writer.rb, line 39 def write_traces(traces) traces = process_traces(traces) flush_traces(traces) rescue StandardError => e Datadog.logger.error( "Error while writing traces: dropped #{traces.length} items. Cause: #{e} Location: #{e.backtrace.first}" ) end