lib/ddtrace/writer.rb
# enqueue the trace for submission to the API
enqueue the trace for submission to the API
enqueue the trace for submission to the API
def write(trace, services = nil)
      unless services.nil?
        Datadog::Patcher.do_once('Writerwrite') do
          Datadog.logger.warn(%(
            write: Writing services has been deprecated and no longer need to be provided.
            write(traces, services) can be updated to write(traces)
          ))
        end
      end
       This check ensures that if a process doesn't own the current +Writer+, async workers
       will be initialized again (but only once for each process).
      pid = Process.pid
      if pid != @pid  avoid using Mutex when pids are equal
        @mutex_after_fork.synchronize do
           we should start threads because the worker doesn't own this
          start if pid != @pid
        end
      end
       TODO: Remove this, and have the tracer pump traces directly to runtime metrics
             instead of working through the trace writer.
       Associate root span with runtime metrics
      if Datadog.configuration.runtime_metrics.enabled && !trace.empty?
        Datadog.runtime_metrics.associate_with_span(trace.first)
      end
      @worker.enqueue_trace(trace)
    end
def write ( trace , services = nil ) unless services . nil? Datadog :: Patcher . do_once ( 'Writer#write' ) do Datadog . logger . warn ( %(
            write: Writing services has been deprecated and no longer need to be provided.
            write(traces, services) can be updated to write(traces)
          ) ) end end pid = Process . pid if pid != @pid @mutex_after_fork . synchronize do start if pid != @pid end end if Datadog . configuration . runtime_metrics . enabled && ! trace . empty? Datadog . runtime_metrics . associate_with_span ( trace . first ) end @worker . enqueue_trace ( trace ) end
enqueue the trace for submission to the API
enqueue the trace for submission to the API
# In multiprocess environments, the main process initializes the +Writer+ instance and if # the process forks (i.e. a web server like Unicorn or Puma with multiple workers) the new # processes will share the same +Writer+ until the first write (COW). Because of that, # each process owns a different copy of the +@buffer+ after each write and so the # +AsyncTransport+ will not send data to the trace agent. # # This check ensures that if a process doesn't own the current +Writer+, async workers # will be initialized again (but only once for each process). # avoid using Mutex when pids are equal # we should start threads because the worker doesn't own this # TODO: Remove this, and have the tracer pump traces directly to runtime metrics #       instead of working through the trace writer. # Associate root span with runtime metrics
trace
<not_specific>
services
<not_specific>