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.
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 98 99 100 101 |
# File 'lib/opencensus/trace/exporters/stackdriver.rb', line 73 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
107 108 109 |
# File 'lib/opencensus/trace/exporters/stackdriver.rb', line 107 def project_id @project_id end |
Instance Method Details
#export(spans) ⇒ Object
Export spans to Stackdriver asynchronously.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/opencensus/trace/exporters/stackdriver.rb', line 115 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.
178 179 180 181 |
# File 'lib/opencensus/trace/exporters/stackdriver.rb', line 178 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.
137 138 139 |
# File 'lib/opencensus/trace/exporters/stackdriver.rb', line 137 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.
167 168 169 170 |
# File 'lib/opencensus/trace/exporters/stackdriver.rb', line 167 def shutdown @executor.shutdown self end |
#shutdown? ⇒ boolean
Returns true if this exporter has finished shutting down and all pending spans have been sent.
147 148 149 |
# File 'lib/opencensus/trace/exporters/stackdriver.rb', line 147 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.
158 159 160 |
# File 'lib/opencensus/trace/exporters/stackdriver.rb', line 158 def shuttingdown? @executor.shuttingdown? end |
#wait_for_termination(timeout = nil) ⇒ boolean
Wait for the exporter to finish shutting down.
191 192 193 |
# File 'lib/opencensus/trace/exporters/stackdriver.rb', line 191 def wait_for_termination timeout = nil @executor.wait_for_termination timeout end |