Class: OpenCensus::Trace::Exporters::Datadog

Inherits:
Object
  • Object
show all
Defined in:
lib/opencensus/trace/exporters/datadog.rb,
lib/opencensus/trace/exporters/datadog/buffer.rb,
lib/opencensus/trace/exporters/datadog/worker.rb,
lib/opencensus/trace/exporters/datadog/converter.rb,
lib/opencensus/trace/exporters/datadog/transport.rb

Defined Under Namespace

Classes: Converter, SpanBuffer, Transport, Worker

Constant Summary collapse

DEFAULT_SERVICE =
'opencensus-app'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Datadog



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/opencensus/trace/exporters/datadog.rb', line 23

def initialize(options = {})
  # create HTTP client for sending spans do Datadog Agent
  agent_hostname = options.fetch(:agent_hostname, nil)
  port = options.fetch(:port, nil)
  @transport = Transport.new(agent_hostname, port)

  # worker parameters
  @max_buffer_size = options.fetch(:buffer_size, 1000)
  @flush_interval = options.fetch(:flush_interval, 1)

  # traces metadata
  @service_name = options.fetch(:service, DEFAULT_SERVICE)

  # each processes have one worker thread
  @mutex_after_fork = Mutex.new
  @pid = nil
  @worker = nil
end

Class Method Details

.logObject



15
16
17
18
19
20
21
# File 'lib/opencensus/trace/exporters/datadog.rb', line 15

def self.log
  unless defined? @logger
    @logger = ::Logger.new(STDOUT)
    @logger.level = ::Logger::WARN
  end
  @logger
end

Instance Method Details

#export(spans) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/opencensus/trace/exporters/datadog.rb', line 53

def export(spans)
  return nil if spans.nil? || spans.empty?

  # create worker thread if not exist in this process
  pid = Process.pid
  if pid != @pid
    @mutex_after_fork.synchronize do
      start() if pid != @pid
    end
  end

  spans.each do |span|
    @worker.enqueue(span)
  end
end

#shutdown!Object



48
49
50
51
# File 'lib/opencensus/trace/exporters/datadog.rb', line 48

def shutdown!
  return if @worker.nil?
  @worker.stop
end

#startObject



42
43
44
45
46
# File 'lib/opencensus/trace/exporters/datadog.rb', line 42

def start
  @pid = Process.pid
  @worker = Worker.new(@transport, @max_buffer_size, @flush_interval, @service_name)
  @worker.start()
end