Class: Tasker::Telemetry::EventMapping
- Inherits:
-
Tasker::Types::BaseConfig
- Object
- Dry::Struct
- Tasker::Types::BaseConfig
- Tasker::Telemetry::EventMapping
- Defined in:
- lib/tasker/telemetry/event_mapping.rb
Overview
EventMapping represents a single event→telemetry routing configuration
This class defines how a specific event should be routed to telemetry backends. It uses dry-struct for immutability and type safety, following the established pattern from Tasker::Types configuration classes.
Instance Attribute Summary collapse
-
#backends ⇒ Array<Symbol>
readonly
List of backend types (:trace, :metrics, :logs).
-
#enabled ⇒ Boolean
readonly
True if this mapping should be processed.
-
#event_name ⇒ String
readonly
Event name in dot notation (e.g., 'task.completed').
-
#metadata ⇒ Hash
readonly
Additional configuration data.
-
#priority ⇒ Symbol
readonly
Priority level (:low, :normal, :high, :critical).
-
#sampling_rate ⇒ Float
readonly
Sampling rate (1.0 = 100%, 0.1 = 10%).
Instance Method Summary collapse
-
#active? ⇒ Boolean
Check if this mapping is active (enabled and should be sampled).
-
#description ⇒ String
Get a description of this mapping for debugging.
-
#initialize ⇒ EventMapping
constructor
Override initialize to ensure backends array is frozen.
-
#routes_to_logs? ⇒ Boolean
Check if this mapping routes to logs.
-
#routes_to_metrics? ⇒ Boolean
Check if this mapping routes to metrics.
-
#routes_to_traces? ⇒ Boolean
Check if this mapping routes to traces.
-
#should_sample? ⇒ Boolean
Check if this event should be sampled.
Constructor Details
#initialize ⇒ EventMapping
Override initialize to ensure backends array is frozen
47 48 49 50 51 |
# File 'lib/tasker/telemetry/event_mapping.rb', line 47 def initialize(*) super backends.freeze # Don't freeze here - BaseConfig already freezes the object end |
Instance Attribute Details
#backends ⇒ Array<Symbol> (readonly)
Returns List of backend types (:trace, :metrics, :logs).
44 |
# File 'lib/tasker/telemetry/event_mapping.rb', line 44 attribute :backends, Tasker::Types::Array.of(Tasker::Types::Symbol).default([:trace].freeze) |
#enabled ⇒ Boolean (readonly)
Returns True if this mapping should be processed.
57 |
# File 'lib/tasker/telemetry/event_mapping.rb', line 57 attribute :enabled, Tasker::Types::Bool.default(true) |
#event_name ⇒ String (readonly)
Returns Event name in dot notation (e.g., 'task.completed').
38 |
# File 'lib/tasker/telemetry/event_mapping.rb', line 38 attribute :event_name, Tasker::Types::String |
#metadata ⇒ Hash (readonly)
Returns Additional configuration data.
75 |
# File 'lib/tasker/telemetry/event_mapping.rb', line 75 attribute :metadata, Tasker::Types::Hash.default({}.freeze) |
Instance Method Details
#active? ⇒ Boolean
Check if this mapping is active (enabled and should be sampled)
114 115 116 |
# File 'lib/tasker/telemetry/event_mapping.rb', line 114 def active? enabled && should_sample? end |
#description ⇒ String
Get a description of this mapping for debugging
121 122 123 |
# File 'lib/tasker/telemetry/event_mapping.rb', line 121 def description "#{event_name} → #{backends.join(', ')} (#{(sampling_rate * 100).round(1)}% sampled)" end |
#routes_to_logs? ⇒ Boolean
Check if this mapping routes to logs
94 95 96 |
# File 'lib/tasker/telemetry/event_mapping.rb', line 94 def routes_to_logs? backends.include?(:logs) end |
#routes_to_metrics? ⇒ Boolean
Check if this mapping routes to metrics
87 88 89 |
# File 'lib/tasker/telemetry/event_mapping.rb', line 87 def routes_to_metrics? backends.include?(:metrics) end |
#routes_to_traces? ⇒ Boolean
Check if this mapping routes to traces
80 81 82 |
# File 'lib/tasker/telemetry/event_mapping.rb', line 80 def routes_to_traces? backends.include?(:trace) end |
#should_sample? ⇒ Boolean
Check if this event should be sampled
Uses a simple random sampling approach. For production, you might want to implement more sophisticated sampling strategies.
104 105 106 107 108 109 |
# File 'lib/tasker/telemetry/event_mapping.rb', line 104 def should_sample? return true if sampling_rate >= 1.0 return false if sampling_rate <= 0.0 Random.rand <= sampling_rate end |