Class: OpenTrace::Client
- Inherits:
-
Object
show all
- Defined in:
- lib/opentrace/client.rb
Defined Under Namespace
Classes: UnixSocketResponse
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 =
2
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(config, sampler: nil) ⇒ Client
Returns a new instance of Client.
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/opentrace/client.rb', line 19
def initialize(config, sampler: nil)
@config = config
@sampler = sampler
@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
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
69
70
71
|
# File 'lib/opentrace/client.rb', line 69
def auth_suspended?
@auth_suspended
end
|
#circuit_state ⇒ Object
65
66
67
|
# File 'lib/opentrace/client.rb', line 65
def circuit_state
@circuit_breaker.state
end
|
#enqueue(payload) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/opentrace/client.rb', line 38
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?
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
61
62
63
|
# File 'lib/opentrace/client.rb', line 61
def queue_size
@queue.size
end
|
#shutdown(timeout: 5) ⇒ Object
86
87
88
89
|
# File 'lib/opentrace/client.rb', line 86
def shutdown(timeout: 5)
@queue.close
@thread&.join(timeout)
end
|
#stats_snapshot ⇒ Object
73
74
75
76
77
78
79
80
|
# File 'lib/opentrace/client.rb', line 73
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
82
83
84
|
# File 'lib/opentrace/client.rb', line 82
def supports?(capability)
@server_capabilities&.include?(capability.to_s)
end
|