Class: ActiveAgents::Telemetry::Configuration

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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_keyObject

Returns the value of attribute api_key.



29
30
31
# File 'lib/activeagents/telemetry/configuration.rb', line 29

def api_key
  @api_key
end

#asyncObject

Returns the value of attribute async.



29
30
31
# File 'lib/activeagents/telemetry/configuration.rb', line 29

def async
  @async
end

#batch_sizeObject

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_bodiesObject

Returns the value of attribute capture_bodies.



29
30
31
# File 'lib/activeagents/telemetry/configuration.rb', line 29

def capture_bodies
  @capture_bodies
end

#enabledObject

Returns the value of attribute enabled.



29
30
31
# File 'lib/activeagents/telemetry/configuration.rb', line 29

def enabled
  @enabled
end

#endpointObject

Returns the value of attribute endpoint.



29
30
31
# File 'lib/activeagents/telemetry/configuration.rb', line 29

def endpoint
  @endpoint
end

#environmentObject

Returns the value of attribute environment.



29
30
31
# File 'lib/activeagents/telemetry/configuration.rb', line 29

def environment
  @environment
end

#error_message_limitObject

Returns the value of attribute error_message_limit.



29
30
31
# File 'lib/activeagents/telemetry/configuration.rb', line 29

def error_message_limit
  @error_message_limit
end

#flush_intervalObject

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_storeObject

Returns the value of attribute local_store.



29
30
31
# File 'lib/activeagents/telemetry/configuration.rb', line 29

def local_store
  @local_store
end

#loggerObject

Returns the value of attribute logger.



29
30
31
# File 'lib/activeagents/telemetry/configuration.rb', line 29

def logger
  @logger
end

#open_timeoutObject

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_attributesObject

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_attributesObject

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_rateObject

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_nameObject

Returns the value of attribute service_name.



29
30
31
# File 'lib/activeagents/telemetry/configuration.rb', line 29

def service_name
  @service_name
end

#timeoutObject

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

Returns:

  • (Boolean)


79
80
81
# File 'lib/activeagents/telemetry/configuration.rb', line 79

def async?
  @async == true
end

#capture_bodies?Boolean

Returns:

  • (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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


71
72
73
# File 'lib/activeagents/telemetry/configuration.rb', line 71

def local_store?
  !@local_store.nil?
end

#resolved_environmentObject



117
118
119
# File 'lib/activeagents/telemetry/configuration.rb', line 117

def resolved_environment
  @environment || rails_env || ENV.fetch("RACK_ENV", "production")
end

#resolved_loggerObject



121
122
123
# File 'lib/activeagents/telemetry/configuration.rb', line 121

def resolved_logger
  @logger || rails_logger || Logger.new(File::NULL)
end

#resolved_service_nameObject

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.

Returns:

  • (Boolean)


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_hObject



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