Class: ActiveAgents::Telemetry::Configuration
- Inherits:
-
Object
- Object
- ActiveAgents::Telemetry::Configuration
- Defined in:
- lib/activeagents/telemetry/configuration.rb
Overview
Where traces go and how they get there.
Every adapter takes one of these, so an app configures the destination once and each adapter inherits it:
ActiveAgents::Telemetry.configure do |config|
config.api_key = ENV["ACTIVEAGENTS_API_KEY"]
config.service_name = "my-app"
config.environment = Rails.env
end
A self-hosted ActiveAgent dashboard is the same thing with a different endpoint — point it at "https://your-app.example.com/active_agent/api/traces".
Constant Summary collapse
- DEFAULT_ENDPOINT =
The hosted platform. Self-hosters override
endpoint. "https://api.activeagents.ai/v1/traces"- LOCAL_ENDPOINT_PATH =
Path a mounted ActiveAgent::Dashboard::Engine serves traces on.
"/active_agent/api/traces"- DEFAULT_REDACT_ATTRIBUTES =
Attribute keys scrubbed from spans before delivery. Name-based — a secret inside free text is not caught; see the wiki's privacy page.
%w[password secret token key credential api_key].freeze
- FLOAT_SETTINGS =
%w[sample_rate].freeze
- INTEGER_SETTINGS =
%w[batch_size flush_interval timeout open_timeout error_message_limit].freeze
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#async ⇒ Object
Returns the value of attribute async.
-
#batch_size ⇒ Object
Returns the value of attribute batch_size.
-
#capture_bodies ⇒ Object
Returns the value of attribute capture_bodies.
-
#enabled ⇒ Object
Returns the value of attribute enabled.
-
#endpoint ⇒ Object
Returns the value of attribute endpoint.
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#error_message_limit ⇒ Object
Returns the value of attribute error_message_limit.
-
#flush_interval ⇒ Object
Returns the value of attribute flush_interval.
-
#local_store ⇒ Object
Returns the value of attribute local_store.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
-
#redact_attributes ⇒ Object
Returns the value of attribute redact_attributes.
-
#resource_attributes ⇒ Object
Returns the value of attribute resource_attributes.
-
#sample_rate ⇒ Object
Returns the value of attribute sample_rate.
-
#service_name ⇒ Object
Returns the value of attribute service_name.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
- #async? ⇒ Boolean
- #capture_bodies? ⇒ Boolean
-
#configured? ⇒ Boolean
Traces are only sent when there is somewhere to send them: an endpoint plus something to authenticate with, or a local store that bypasses HTTP entirely.
-
#enabled? ⇒ Boolean
An explicit kill-switch over and above configured?.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#load_from_hash(hash) ⇒ Object
Loads settings from a hash — how config/*.yml files reach here.
-
#local_store? ⇒ Boolean
A callable (trace_hash, sdk_hash) that persists traces in-process — the ActiveAgent dashboard wires this to its TelemetryTrace model.
- #resolved_environment ⇒ Object
- #resolved_logger ⇒ Object
-
#resolved_service_name ⇒ Object
Falls back to the Rails application name, then to a generic label, so traces are attributable even when the app never sets one.
-
#sample? ⇒ Boolean
(also: #should_sample?)
Head-based sampling: decided once per trace, at report time.
- #to_h ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/activeagents/telemetry/configuration.rb', line 35 def initialize @enabled = true @endpoint = DEFAULT_ENDPOINT @api_key = nil @service_name = nil @environment = nil @resource_attributes = {} @logger = nil @timeout = 10 @open_timeout = 10 @async = true @sample_rate = 1.0 @error_message_limit = 200 @batch_size = 100 @flush_interval = 5 @capture_bodies = false @redact_attributes = DEFAULT_REDACT_ATTRIBUTES.dup @local_store = nil end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
29 30 31 |
# File 'lib/activeagents/telemetry/configuration.rb', line 29 def api_key @api_key end |
#async ⇒ Object
Returns the value of attribute async.
29 30 31 |
# File 'lib/activeagents/telemetry/configuration.rb', line 29 def async @async end |
#batch_size ⇒ Object
Returns the value of attribute batch_size.
29 30 31 |
# File 'lib/activeagents/telemetry/configuration.rb', line 29 def batch_size @batch_size end |
#capture_bodies ⇒ Object
Returns the value of attribute capture_bodies.
29 30 31 |
# File 'lib/activeagents/telemetry/configuration.rb', line 29 def capture_bodies @capture_bodies end |
#enabled ⇒ Object
Returns the value of attribute enabled.
29 30 31 |
# File 'lib/activeagents/telemetry/configuration.rb', line 29 def enabled @enabled end |
#endpoint ⇒ Object
Returns the value of attribute endpoint.
29 30 31 |
# File 'lib/activeagents/telemetry/configuration.rb', line 29 def endpoint @endpoint end |
#environment ⇒ Object
Returns the value of attribute environment.
29 30 31 |
# File 'lib/activeagents/telemetry/configuration.rb', line 29 def environment @environment end |
#error_message_limit ⇒ Object
Returns the value of attribute error_message_limit.
29 30 31 |
# File 'lib/activeagents/telemetry/configuration.rb', line 29 def @error_message_limit end |
#flush_interval ⇒ Object
Returns the value of attribute flush_interval.
29 30 31 |
# File 'lib/activeagents/telemetry/configuration.rb', line 29 def flush_interval @flush_interval end |
#local_store ⇒ Object
Returns the value of attribute local_store.
29 30 31 |
# File 'lib/activeagents/telemetry/configuration.rb', line 29 def local_store @local_store end |
#logger ⇒ Object
Returns the value of attribute logger.
29 30 31 |
# File 'lib/activeagents/telemetry/configuration.rb', line 29 def logger @logger end |
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
29 30 31 |
# File 'lib/activeagents/telemetry/configuration.rb', line 29 def open_timeout @open_timeout end |
#redact_attributes ⇒ Object
Returns the value of attribute redact_attributes.
29 30 31 |
# File 'lib/activeagents/telemetry/configuration.rb', line 29 def redact_attributes @redact_attributes end |
#resource_attributes ⇒ Object
Returns the value of attribute resource_attributes.
29 30 31 |
# File 'lib/activeagents/telemetry/configuration.rb', line 29 def resource_attributes @resource_attributes end |
#sample_rate ⇒ Object
Returns the value of attribute sample_rate.
29 30 31 |
# File 'lib/activeagents/telemetry/configuration.rb', line 29 def sample_rate @sample_rate end |
#service_name ⇒ Object
Returns the value of attribute service_name.
29 30 31 |
# File 'lib/activeagents/telemetry/configuration.rb', line 29 def service_name @service_name end |
#timeout ⇒ Object
Returns the value of attribute timeout.
29 30 31 |
# File 'lib/activeagents/telemetry/configuration.rb', line 29 def timeout @timeout end |
Instance Method Details
#async? ⇒ Boolean
79 80 81 |
# File 'lib/activeagents/telemetry/configuration.rb', line 79 def async? @async == true end |
#capture_bodies? ⇒ Boolean
75 76 77 |
# File 'lib/activeagents/telemetry/configuration.rb', line 75 def capture_bodies? @capture_bodies == true end |
#configured? ⇒ Boolean
Traces are only sent when there is somewhere to send them: an endpoint plus something to authenticate with, or a local store that bypasses HTTP entirely.
58 59 60 |
# File 'lib/activeagents/telemetry/configuration.rb', line 58 def configured? local_store? || (!endpoint.to_s.empty? && !api_key.to_s.empty?) end |
#enabled? ⇒ Boolean
An explicit kill-switch over and above configured?. Defaults to true — for adapters, the presence of an api_key remains the effective switch; frameworks that want opt-in default this to false.
65 66 67 |
# File 'lib/activeagents/telemetry/configuration.rb', line 65 def enabled? @enabled == true end |
#load_from_hash(hash) ⇒ Object
Loads settings from a hash — how config/*.yml files reach here. Unknown keys are ignored, so a newer config file works on an older gem; numeric settings are coerced because ERB-interpolated YAML values arrive as strings.
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/activeagents/telemetry/configuration.rb', line 99 def load_from_hash(hash) (hash || {}).each do |key, value| writer = "#{key}=" next unless respond_to?(writer) value = value.to_f if FLOAT_SETTINGS.include?(key.to_s) value = value.to_i if INTEGER_SETTINGS.include?(key.to_s) public_send(writer, value) end self end |
#local_store? ⇒ Boolean
A callable (trace_hash, sdk_hash) that persists traces in-process — the ActiveAgent dashboard wires this to its TelemetryTrace model.
71 72 73 |
# File 'lib/activeagents/telemetry/configuration.rb', line 71 def local_store? !@local_store.nil? end |
#resolved_environment ⇒ Object
117 118 119 |
# File 'lib/activeagents/telemetry/configuration.rb', line 117 def resolved_environment @environment || rails_env || ENV.fetch("RACK_ENV", "production") end |
#resolved_logger ⇒ Object
121 122 123 |
# File 'lib/activeagents/telemetry/configuration.rb', line 121 def resolved_logger @logger || rails_logger || Logger.new(File::NULL) end |
#resolved_service_name ⇒ Object
Falls back to the Rails application name, then to a generic label, so traces are attributable even when the app never sets one.
113 114 115 |
# File 'lib/activeagents/telemetry/configuration.rb', line 113 def resolved_service_name @service_name || rails_app_name || "ruby" end |
#sample? ⇒ Boolean Also known as: should_sample?
Head-based sampling: decided once per trace, at report time.
84 85 86 87 88 89 |
# File 'lib/activeagents/telemetry/configuration.rb', line 84 def sample? return true if sample_rate >= 1.0 return false if sample_rate <= 0.0 rand < sample_rate end |
#to_h ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/activeagents/telemetry/configuration.rb', line 125 def to_h { enabled: enabled, endpoint: endpoint, api_key: api_key ? "[REDACTED]" : nil, service_name: resolved_service_name, environment: resolved_environment, sample_rate: sample_rate, async: async, batch_size: batch_size, flush_interval: flush_interval, capture_bodies: capture_bodies, local_store: local_store? ? "[CALLABLE]" : nil } end |