Class: OpenTrace::Client
- Inherits:
-
Object
- Object
- OpenTrace::Client
- Defined in:
- lib/opentrace/client.rb
Constant Summary collapse
- MAX_QUEUE_SIZE =
1000- PAYLOAD_MAX_BYTES =
256 KB (default; use config.max_payload_bytes to override)
262_144- MAX_RATE_LIMIT_BACKOFF =
Cap Retry-After at 60 seconds
60- API_VERSION =
1
Instance Attribute Summary collapse
-
#stats ⇒ Object
readonly
Returns the value of attribute stats.
Instance Method Summary collapse
- #auth_suspended? ⇒ Boolean
- #circuit_state ⇒ Object
- #enqueue(payload) ⇒ Object
-
#initialize(config) ⇒ Client
constructor
A new instance of Client.
- #queue_size ⇒ Object
- #shutdown(timeout: 5) ⇒ Object
- #stats_snapshot ⇒ Object
- #supports?(capability) ⇒ Boolean
Constructor Details
#initialize(config) ⇒ Client
Returns a new instance of Client.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/opentrace/client.rb', line 19 def initialize(config) @config = config @queue = Thread::Queue.new @mutex = Mutex.new @thread = nil @pid = Process.pid @circuit_breaker = CircuitBreaker.new( failure_threshold: config.circuit_breaker_threshold, recovery_timeout: config.circuit_breaker_timeout ) @rate_limit_until = nil @auth_suspended = false @auth_failure_warned = false @stats = Stats.new @compatibility_checked = false @server_capabilities = nil end |
Instance Attribute Details
#stats ⇒ Object (readonly)
Returns the value of attribute stats.
17 18 19 |
# File 'lib/opentrace/client.rb', line 17 def stats @stats end |
Instance Method Details
#auth_suspended? ⇒ Boolean
68 69 70 |
# File 'lib/opentrace/client.rb', line 68 def auth_suspended? @auth_suspended end |
#circuit_state ⇒ Object
64 65 66 |
# File 'lib/opentrace/client.rb', line 64 def circuit_state @circuit_breaker.state end |
#enqueue(payload) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/opentrace/client.rb', line 37 def enqueue(payload) return unless @config.enabled? if @auth_suspended @stats.increment(:dropped_auth_suspended) fire_on_drop(1, :auth_suspended) return end reset_after_fork! if forked? # Drop newest if queue is full if @queue.size >= MAX_QUEUE_SIZE @stats.increment(:dropped_queue_full) fire_on_drop(1, :queue_full) return end @queue.push(payload) @stats.increment(:enqueued) ensure_thread_running end |
#queue_size ⇒ Object
60 61 62 |
# File 'lib/opentrace/client.rb', line 60 def queue_size @queue.size end |
#shutdown(timeout: 5) ⇒ Object
85 86 87 88 |
# File 'lib/opentrace/client.rb', line 85 def shutdown(timeout: 5) @queue.close @thread&.join(timeout) end |
#stats_snapshot ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/opentrace/client.rb', line 72 def stats_snapshot @stats.to_h.merge( queue_size: queue_size, circuit_state: circuit_state, auth_suspended: @auth_suspended, server_capabilities: @server_capabilities ) end |
#supports?(capability) ⇒ Boolean
81 82 83 |
# File 'lib/opentrace/client.rb', line 81 def supports?(capability) @server_capabilities&.include?(capability.to_s) end |