Class: Datadog::Tracing::Workers::TraceWriter

Inherits:
Core::Worker
  • Object
show all
Defined in:
lib/datadog/tracing/workers/trace_writer.rb

Overview

Writes traces to transport synchronously

Direct Known Subclasses

AsyncTraceWriter

Defined Under Namespace

Classes: FlushCompleted

Instance Attribute Summary collapse

Attributes inherited from Core::Worker

#task

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ TraceWriter

DEV-3.0: change to keyword arguments

rubocop:disable Lint/MissingSuper



27
28
29
30
31
32
33
34
35
36
# File 'lib/datadog/tracing/workers/trace_writer.rb', line 27

def initialize(options = {})
  @logger = options[:logger] || Datadog.logger

  transport_options = options.fetch(:transport_options, {})
  @agent_settings = options[:agent_settings]

  @transport = options.fetch(:transport) do
    Datadog::Tracing::Transport::HTTP.default(agent_settings: agent_settings, logger: logger, **transport_options)
  end
end

Instance Attribute Details

#agent_settingsObject (readonly)

Returns the value of attribute agent_settings.



19
20
21
# File 'lib/datadog/tracing/workers/trace_writer.rb', line 19

def agent_settings
  @agent_settings
end

#loggerObject (readonly)

Returns the value of attribute logger.



19
20
21
# File 'lib/datadog/tracing/workers/trace_writer.rb', line 19

def logger
  @logger
end

#transportObject (readonly)

Returns the value of attribute transport.



19
20
21
# File 'lib/datadog/tracing/workers/trace_writer.rb', line 19

def transport
  @transport
end

Instance Method Details

#flush_completedObject

TODO: Register Datadog::Tracing::Diagnostics::EnvironmentLogger.collect_and_log! TODO: as a flush_completed subscriber when the TraceWriter TODO: instantiation code is implemented.



70
71
72
# File 'lib/datadog/tracing/workers/trace_writer.rb', line 70

def flush_completed
  @flush_completed ||= FlushCompleted.new
end

#flush_traces(traces) ⇒ Object



61
62
63
64
65
# File 'lib/datadog/tracing/workers/trace_writer.rb', line 61

def flush_traces(traces)
  transport.send_traces(traces).tap do |response|
    flush_completed.publish(response)
  end
end

#perform(traces) ⇒ Object

rubocop:enable Lint/MissingSuper



39
40
41
# File 'lib/datadog/tracing/workers/trace_writer.rb', line 39

def perform(traces)
  write_traces(traces)
end

#process_traces(traces) ⇒ Object



56
57
58
59
# File 'lib/datadog/tracing/workers/trace_writer.rb', line 56

def process_traces(traces)
  # Run traces through the processing pipeline
  Pipeline.process!(traces)
end

#write(trace) ⇒ Object



43
44
45
# File 'lib/datadog/tracing/workers/trace_writer.rb', line 43

def write(trace)
  write_traces([trace])
end

#write_traces(traces) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/datadog/tracing/workers/trace_writer.rb', line 47

def write_traces(traces)
  traces = process_traces(traces)
  flush_traces(traces)
rescue => e
  logger.warn(
    "Error while writing traces: dropped #{traces.length} items. Cause: #{e} Location: #{Array(e.backtrace).first}"
  )
end