Module: EzLogsAgent::EventBuilder
- Defined in:
- lib/ez_logs_agent/event_builder.rb
Overview
EventBuilder constructs valid Event hashes according to the Event Structure contract.
This is a pure, side-effect-free builder that:
-
Validates required fields
-
Validates enum values
-
Enforces conditional rules (outcome ↔ error_message)
-
Sanitizes sensitive data
-
Returns a valid Event hash
EventBuilder does NOT:
-
Buffer or send Events
-
Generate correlation IDs
-
Interact with Rails or ActiveRecord
-
Mutate global state
Constant Summary collapse
- SENSITIVE_KEYS =
Sensitive keys that should be filtered from source_data and context
%w[password token secret api_key credit_card].freeze
- VALID_SOURCE_TYPES =
Valid source types
%w[http_request background_job database_callback].freeze
- VALID_OUTCOMES =
Valid outcome values
%w[success failure].freeze
Class Method Summary collapse
-
.build(source_type:, source_data:, outcome:, correlation_id: nil, resource_ids: [], context: nil, duration_ms: nil, error_message: nil, timestamp: nil) ⇒ Hash
Builds a valid Event hash.
Class Method Details
.build(source_type:, source_data:, outcome:, correlation_id: nil, resource_ids: [], context: nil, duration_ms: nil, error_message: nil, timestamp: nil) ⇒ Hash
Builds a valid Event hash
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/ez_logs_agent/event_builder.rb', line 55 def self.build( source_type:, source_data:, outcome:, correlation_id: nil, resource_ids: [], context: nil, duration_ms: nil, error_message: nil, timestamp: nil ) # Validate and normalize inputs validated_source_type = validate_source_type!(source_type) validated_source_data = validate_source_data!(source_data) validated_outcome = validate_outcome!(outcome) = () validated_resource_ids = validate_resource_ids!(resource_ids) validated_context = validate_context!(context) validated_duration_ms = validate_duration_ms!(duration_ms) # Validate conditional rules validate_outcome_error_consistency!(validated_outcome, ) # Sanitize sensitive data sanitized_source_data = sanitize_hash(validated_source_data) sanitized_context = validated_context.nil? ? nil : sanitize_hash(validated_context) # Build and return Event hash { timestamp: , source_type: validated_source_type, source_data: sanitized_source_data, outcome: validated_outcome, correlation_id: correlation_id, resource_ids: validated_resource_ids, context: sanitized_context, duration_ms: validated_duration_ms, error_message: } end |