Class: OpenCensus::Trace::Exporters::Stackdriver
- Inherits:
-
Object
- Object
- OpenCensus::Trace::Exporters::Stackdriver
- 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
-
#project_id ⇒ String
readonly
The project ID.
Instance Method Summary collapse
-
#export(spans) ⇒ Object
Export spans to Stackdriver asynchronously.
-
#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
constructor
Create a Stackdriver exporter.
-
#kill ⇒ Object
Begin shutting down the exporter forcefully.
-
#running? ⇒ boolean
Returns true if this exporter is running and will accept further export requests.
-
#shutdown ⇒ Object
Begin shutting down the exporter gracefully.
-
#shutdown? ⇒ boolean
Returns true if this exporter has finished shutting down and all pending spans have been sent.
-
#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.
-
#wait_for_termination(timeout = nil) ⇒ boolean
Wait for the exporter to finish shutting down.
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.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/opencensus/trace/exporters/stackdriver.rb', line 66 def 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 @project_id = final_project_id 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 credentials = final_credentials credentials, scope scope ||= Google::Cloud.configure.trace.scope timeout ||= Google::Cloud.configure.trace.timeout client_config ||= Google::Cloud.configure.trace.client_config @client_promise = create_client_promise \ @executor, credentials, scope, client_config, timeout end end |
Instance Attribute Details
#project_id ⇒ String (readonly)
The project ID
100 101 102 |
# File 'lib/opencensus/trace/exporters/stackdriver.rb', line 100 def project_id @project_id end |
Instance Method Details
#export(spans) ⇒ Object
Export spans to Stackdriver asynchronously.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/opencensus/trace/exporters/stackdriver.rb', line 108 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 |
#kill ⇒ Object
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.
171 172 173 174 |
# File 'lib/opencensus/trace/exporters/stackdriver.rb', line 171 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.
130 131 132 |
# File 'lib/opencensus/trace/exporters/stackdriver.rb', line 130 def running? @executor.running? end |
#shutdown ⇒ Object
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.
160 161 162 163 |
# File 'lib/opencensus/trace/exporters/stackdriver.rb', line 160 def shutdown @executor.shutdown self end |
#shutdown? ⇒ boolean
Returns true if this exporter has finished shutting down and all pending spans have been sent.
140 141 142 |
# File 'lib/opencensus/trace/exporters/stackdriver.rb', line 140 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.
151 152 153 |
# File 'lib/opencensus/trace/exporters/stackdriver.rb', line 151 def shuttingdown? @executor.shuttingdown? end |
#wait_for_termination(timeout = nil) ⇒ boolean
Wait for the exporter to finish shutting down.
184 185 186 |
# File 'lib/opencensus/trace/exporters/stackdriver.rb', line 184 def wait_for_termination timeout = nil @executor.wait_for_termination timeout end |