Class: Datadog::Workers::TraceWriter
- Inherits:
-
Datadog::Worker
- Object
- Datadog::Worker
- Datadog::Workers::TraceWriter
- Defined in:
- lib/ddtrace/workers/trace_writer.rb
Overview
Writes traces to transport synchronously
Direct Known Subclasses
Defined Under Namespace
Classes: FlushCompleted
Instance Attribute Summary collapse
-
#transport ⇒ Object
readonly
Returns the value of attribute transport.
Attributes inherited from Datadog::Worker
Instance Method Summary collapse
-
#flush_completed ⇒ Object
TODO: Register ‘Datadog::Diagnostics::EnvironmentLogger.log!` TODO: as a flush_completed subscriber when the `TraceWriter` TODO: instantiation code is implemented.
- #flush_traces(traces) ⇒ Object
-
#initialize(options = {}) ⇒ TraceWriter
constructor
A new instance of TraceWriter.
- #inject_hostname!(traces) ⇒ Object
- #perform(traces) ⇒ Object
- #process_traces(traces) ⇒ Object
- #write(trace) ⇒ Object
- #write_traces(traces) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ TraceWriter
Returns a new instance of TraceWriter.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ddtrace/workers/trace_writer.rb', line 16 def initialize( = {}) = .fetch(:transport_options, {}) if .is_a?(Proc) = { on_build: } end [:hostname] = [:hostname] if .key?(:hostname) [:port] = [:port] if .key?(:port) @transport = .fetch(:transport) do Transport::HTTP.default() end end |
Instance Attribute Details
#transport ⇒ Object (readonly)
Returns the value of attribute transport.
13 14 15 |
# File 'lib/ddtrace/workers/trace_writer.rb', line 13 def transport @transport end |
Instance Method Details
#flush_completed ⇒ Object
TODO: Register ‘Datadog::Diagnostics::EnvironmentLogger.log!` TODO: as a flush_completed subscriber when the `TraceWriter` TODO: instantiation code is implemented.
78 79 80 |
# File 'lib/ddtrace/workers/trace_writer.rb', line 78 def flush_completed @flush_completed ||= FlushCompleted.new end |
#flush_traces(traces) ⇒ Object
58 59 60 61 62 |
# 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) ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# 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) ⇒ Object
31 32 33 |
# File 'lib/ddtrace/workers/trace_writer.rb', line 31 def perform(traces) write_traces(traces) end |
#process_traces(traces) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# 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) ⇒ Object
35 36 37 |
# File 'lib/ddtrace/workers/trace_writer.rb', line 35 def write(trace) write_traces([trace]) end |
#write_traces(traces) ⇒ Object
39 40 41 42 43 44 45 46 |
# 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 |