Class: Tasker::Types::TelemetryConfig
- Inherits:
-
BaseConfig
- Object
- Dry::Struct
- BaseConfig
- Tasker::Types::TelemetryConfig
- Defined in:
- lib/tasker/types/telemetry_config.rb
Overview
Configuration type for telemetry and observability settings
This configuration handles telemetry, logging, and observability settings for Tasker. It provides the same functionality as the original TelemetryConfiguration but with dry-struct type safety and immutability.
Instance Attribute Summary collapse
-
#config ⇒ Hash
readonly
Advanced configuration options.
-
#correlation_id_header ⇒ String
readonly
Header name for correlation ID.
-
#enabled ⇒ Boolean
readonly
Whether telemetry is enabled.
-
#event_sampling_rate ⇒ Float
readonly
Sampling rate for events.
-
#filter_mask ⇒ String
readonly
Filter mask string.
-
#filter_parameters ⇒ Array<Symbol, String, Regexp>
readonly
Parameters to filter.
-
#filtered_events ⇒ Array<String>
readonly
List of event names to skip.
-
#log_format ⇒ String
readonly
Log format (json, pretty_json, logfmt).
-
#log_level ⇒ String
readonly
Log level (debug, info, warn, error, fatal).
-
#max_stored_samples ⇒ Integer
readonly
Maximum stored samples.
-
#memory_threshold_mb ⇒ Integer
readonly
Memory threshold in megabytes.
-
#metrics_auth_required ⇒ Boolean
readonly
Whether metrics endpoint requires auth.
-
#metrics_enabled ⇒ Boolean
readonly
Whether metrics collection is enabled.
-
#metrics_endpoint ⇒ String
readonly
Path for metrics endpoint.
-
#metrics_format ⇒ String
readonly
Metrics format (prometheus, json).
-
#metrics_retention_hours ⇒ Integer
readonly
Retention period in hours.
-
#performance_monitoring_enabled ⇒ Boolean
readonly
Whether performance monitoring is enabled.
-
#prometheus ⇒ Hash
readonly
Prometheus export configuration.
-
#service_name ⇒ String
readonly
Service name for telemetry.
-
#service_version ⇒ String
readonly
Service version for telemetry.
-
#slow_query_threshold_seconds ⇒ Float
readonly
Slow query threshold in seconds.
-
#structured_logging_enabled ⇒ Boolean
readonly
Whether structured logging is enabled.
Class Method Summary collapse
-
.default_filter_parameters ⇒ Array<Symbol>
Get the default filter parameters from Rails or use a default set.
-
.default_prometheus_config ⇒ Hash
Get default Prometheus configuration.
-
.default_telemetry_config ⇒ Hash
Get default telemetry configuration.
Instance Method Summary collapse
-
#batching_enabled? ⇒ Boolean
Check if telemetry batching is enabled.
-
#configure_telemetry(options = {}) ⇒ TelemetryConfig
Update telemetry configuration with custom options.
-
#parameter_filter ⇒ ActiveSupport::ParameterFilter?
Get or create a parameter filter for sensitive data.
Methods inherited from BaseConfig
Constructor Details
This class inherits a constructor from Tasker::Types::BaseConfig
Instance Attribute Details
#config ⇒ Hash (readonly)
Returns Advanced configuration options.
161 |
# File 'lib/tasker/types/telemetry_config.rb', line 161 attribute :config, Types::Hash.default(proc { default_telemetry_config }.freeze, shared: true) |
#correlation_id_header ⇒ String (readonly)
Returns Header name for correlation ID.
71 |
# File 'lib/tasker/types/telemetry_config.rb', line 71 attribute :correlation_id_header, Types::String.default('X-Correlation-ID') |
#enabled ⇒ Boolean (readonly)
Returns Whether telemetry is enabled.
32 |
# File 'lib/tasker/types/telemetry_config.rb', line 32 attribute :enabled, Types::Bool.default(true) |
#event_sampling_rate ⇒ Float (readonly)
Returns Sampling rate for events.
131 |
# File 'lib/tasker/types/telemetry_config.rb', line 131 attribute :event_sampling_rate, Types::Float.default(1.0) |
#filter_mask ⇒ String (readonly)
Returns Filter mask string.
59 |
# File 'lib/tasker/types/telemetry_config.rb', line 59 attribute :filter_mask, Types::String.default('[FILTERED]') |
#filter_parameters ⇒ Array<Symbol, String, Regexp> (readonly)
Returns Parameters to filter.
51 52 53 |
# File 'lib/tasker/types/telemetry_config.rb', line 51 attribute :filter_parameters, Types::Array.of(Types.Interface(:to_s)).default(proc { default_filter_parameters }.freeze, shared: true) |
#filtered_events ⇒ Array<String> (readonly)
Returns List of event names to skip.
137 |
# File 'lib/tasker/types/telemetry_config.rb', line 137 attribute :filtered_events, Types::Array.of(Types::String).default([].freeze) |
#log_format ⇒ String (readonly)
Returns Log format (json, pretty_json, logfmt).
83 |
# File 'lib/tasker/types/telemetry_config.rb', line 83 attribute :log_format, Types::String.default('json') |
#log_level ⇒ String (readonly)
Returns Log level (debug, info, warn, error, fatal).
77 |
# File 'lib/tasker/types/telemetry_config.rb', line 77 attribute :log_level, Types::String.default('info') |
#max_stored_samples ⇒ Integer (readonly)
Returns Maximum stored samples.
143 |
# File 'lib/tasker/types/telemetry_config.rb', line 143 attribute :max_stored_samples, Types::Integer.default(1000) |
#memory_threshold_mb ⇒ Integer (readonly)
Returns Memory threshold in megabytes.
125 |
# File 'lib/tasker/types/telemetry_config.rb', line 125 attribute :memory_threshold_mb, Types::Integer.default(100) |
#metrics_auth_required ⇒ Boolean (readonly)
Returns Whether metrics endpoint requires auth.
107 |
# File 'lib/tasker/types/telemetry_config.rb', line 107 attribute :metrics_auth_required, Types::Bool.default(false) |
#metrics_enabled ⇒ Boolean (readonly)
Returns Whether metrics collection is enabled.
89 |
# File 'lib/tasker/types/telemetry_config.rb', line 89 attribute :metrics_enabled, Types::Bool.default(true) |
#metrics_endpoint ⇒ String (readonly)
Returns Path for metrics endpoint.
95 |
# File 'lib/tasker/types/telemetry_config.rb', line 95 attribute :metrics_endpoint, Types::String.default('/tasker/metrics') |
#metrics_format ⇒ String (readonly)
Returns Metrics format (prometheus, json).
101 |
# File 'lib/tasker/types/telemetry_config.rb', line 101 attribute :metrics_format, Types::String.default('prometheus') |
#metrics_retention_hours ⇒ Integer (readonly)
Returns Retention period in hours.
149 |
# File 'lib/tasker/types/telemetry_config.rb', line 149 attribute :metrics_retention_hours, Types::Integer.default(24) |
#performance_monitoring_enabled ⇒ Boolean (readonly)
Returns Whether performance monitoring is enabled.
113 |
# File 'lib/tasker/types/telemetry_config.rb', line 113 attribute :performance_monitoring_enabled, Types::Bool.default(true) |
#prometheus ⇒ Hash (readonly)
Returns Prometheus export configuration.
155 |
# File 'lib/tasker/types/telemetry_config.rb', line 155 attribute :prometheus, Types::Hash.default(proc { default_prometheus_config }.freeze, shared: true) |
#service_name ⇒ String (readonly)
Returns Service name for telemetry.
38 |
# File 'lib/tasker/types/telemetry_config.rb', line 38 attribute :service_name, Types::String.default('tasker') |
#service_version ⇒ String (readonly)
Returns Service version for telemetry.
44 |
# File 'lib/tasker/types/telemetry_config.rb', line 44 attribute :service_version, Types::String.default('0.1.0', shared: true) |
#slow_query_threshold_seconds ⇒ Float (readonly)
Returns Slow query threshold in seconds.
119 |
# File 'lib/tasker/types/telemetry_config.rb', line 119 attribute :slow_query_threshold_seconds, Types::Float.default(1.0) |
#structured_logging_enabled ⇒ Boolean (readonly)
Returns Whether structured logging is enabled.
65 |
# File 'lib/tasker/types/telemetry_config.rb', line 65 attribute :structured_logging_enabled, Types::Bool.default(true) |
Class Method Details
.default_filter_parameters ⇒ Array<Symbol>
Get the default filter parameters from Rails or use a default set
166 167 168 169 170 171 172 |
# File 'lib/tasker/types/telemetry_config.rb', line 166 def self.default_filter_parameters if defined?(Rails) && Rails.application&.config&.filter_parameters&.any? Rails.application.config.filter_parameters.dup else %i[passw email secret token _key crypt salt certificate otp ssn] end end |
.default_prometheus_config ⇒ Hash
Get default Prometheus configuration
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/tasker/types/telemetry_config.rb', line 177 def self.default_prometheus_config { # Prometheus remote write endpoint (nil disables Prometheus export) endpoint: nil, # e.g., 'http://localhost:9090/api/v1/write' # Basic authentication for Prometheus endpoint username: nil, password: nil, # Job configuration job_timeout: 5.minutes, export_timeout: 2.minutes, retry_attempts: 3, # Export scheduling retention_window: 5.minutes, safety_margin: 1.minute, # Metric naming metric_prefix: 'tasker', include_instance_labels: true, # Performance tuning compression: 'snappy', # 'snappy', 'gzip', or nil batch_size: 1000, # Test/development mode skip_if_unavailable: true # Don't fail if Prometheus is unreachable }.freeze end |
.default_telemetry_config ⇒ Hash
Get default telemetry configuration
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/tasker/types/telemetry_config.rb', line 211 def self.default_telemetry_config { # Batch processing options batch_events: false, # Set to true to enable event batching buffer_size: 100, # Maximum events to buffer before flushing flush_interval: 5, # Maximum time between flushes (in seconds) # Event filtering options filtered_events: [], # List of event names to skip recording # Performance options enable_memoization: true, # Cache frequently accessed attributes # Production optimizations async_processing: false, # Process events asynchronously (future enhancement) sampling_rate: 1.0 # Sample rate for events (1.0 = 100%, 0.1 = 10%) }.freeze end |
Instance Method Details
#batching_enabled? ⇒ Boolean
Check if telemetry batching is enabled
245 246 247 |
# File 'lib/tasker/types/telemetry_config.rb', line 245 def batching_enabled? config[:batch_events] || false end |
#configure_telemetry(options = {}) ⇒ TelemetryConfig
Update telemetry configuration with custom options
This method creates a new instance with merged configuration. Since dry-struct types are immutable, this returns a new instance.
237 238 239 240 |
# File 'lib/tasker/types/telemetry_config.rb', line 237 def configure_telemetry( = {}) new_config = config.merge() self.class.new(to_h.merge(config: new_config)) end |
#parameter_filter ⇒ ActiveSupport::ParameterFilter?
Get or create a parameter filter for sensitive data
252 253 254 255 256 257 258 |
# File 'lib/tasker/types/telemetry_config.rb', line 252 def parameter_filter return nil unless filter_parameters.any? return unless defined?(ActiveSupport::ParameterFilter) ActiveSupport::ParameterFilter.new(filter_parameters, mask: filter_mask) end |