Class: OpenCensus::Trace::Exporters::Stackdriver

Inherits:
Object
  • Object
show all
Defined in:
lib/opencensus/trace/exporters/stackdriver.rb,
lib/opencensus/trace/exporters/stackdriver/converter.rb

Overview

The Stackdriver exporter for OpenCensus Trace exports captured spans to a Google Stackdriver project. It calls the Stackdriver Trace API in a background thread pool.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_id: nil, credentials: nil, scope: nil, timeout: nil, client_config: nil, max_queue: 1000, max_threads: 1, auto_terminate_time: 10, mock_client: nil) ⇒ Stackdriver

Create a Stackdriver exporter.



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/opencensus/trace/exporters/stackdriver.rb', line 72

def initialize \
    project_id: nil,
    credentials: nil,
    scope: nil,
    timeout: nil,
    client_config: nil, # rubocop:disable Lint/UnusedMethodArgument
    max_queue: 1000,
    max_threads: 1,
    auto_terminate_time: 10,
    mock_client: nil
  @project_id = project_id ||
                ENV["GOOGLE_CLOUD_PROJECT"] ||
                Google::Cloud.env.project_id
  @executor = create_executor max_threads, max_queue
  if auto_terminate_time
    terminate_at_exit! @executor, auto_terminate_time
  end

  if mock_client
    @client_promise =
      Concurrent::Promise.fulfill mock_client, executor: @executor
  else
    @client_promise = create_client_promise \
      @executor, credentials, scope, timeout
  end
end

Instance Attribute Details

#project_idString (readonly)

The project ID



103
104
105
# File 'lib/opencensus/trace/exporters/stackdriver.rb', line 103

def project_id
  @project_id
end

Instance Method Details

#export(spans) ⇒ Object

Export spans to Stackdriver asynchronously.



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/opencensus/trace/exporters/stackdriver.rb', line 111

def export spans
  raise "Exporter is no longer running" unless @executor.running?

  return nil if spans.nil? || spans.empty?

  @client_promise.execute
  export_promise = @client_promise.then do |client|
    export_as_batch(client, spans)
  end
  export_promise.on_error do |reason|
    warn "Unable to export to Stackdriver because: #{reason}"
  end

  nil
end

#killObject

Begin shutting down the exporter forcefully. After this operation is performed, the exporter will no longer accept export requests, and will finish any currently running export requests, but will cancel all requests that are still pending in the queue.



174
175
176
177
# File 'lib/opencensus/trace/exporters/stackdriver.rb', line 174

def kill
  @executor.kill
  self
end

#running?boolean

Returns true if this exporter is running and will accept further export requests. Returns false once the exporter begins shutting down.



133
134
135
# File 'lib/opencensus/trace/exporters/stackdriver.rb', line 133

def running?
  @executor.running?
end

#shutdownObject

Begin shutting down the exporter gracefully. After this operation is performed, the exporter will no longer accept export requests, but will finish any pending requests in the background.



163
164
165
166
# File 'lib/opencensus/trace/exporters/stackdriver.rb', line 163

def shutdown
  @executor.shutdown
  self
end

#shutdown?boolean

Returns true if this exporter has finished shutting down and all pending spans have been sent.



143
144
145
# File 'lib/opencensus/trace/exporters/stackdriver.rb', line 143

def shutdown?
  @executor.shutdown?
end

#shuttingdown?boolean

Returns true if this exporter has begun shutting down and is no longer accepting export requests, but is still running queued requests in the background.



154
155
156
# File 'lib/opencensus/trace/exporters/stackdriver.rb', line 154

def shuttingdown?
  @executor.shuttingdown?
end

#wait_for_termination(timeout = nil) ⇒ boolean

Wait for the exporter to finish shutting down.



187
188
189
# File 'lib/opencensus/trace/exporters/stackdriver.rb', line 187

def wait_for_termination timeout = nil
  @executor.wait_for_termination timeout
end