Class: CloseYourIt::LogEvent

Inherits:
Event
  • Object
show all
Defined in:
lib/closeyourit/events/log_event.rb

Overview

Voce di log strutturata spedita all'ingest /logs (NON formato Sentry: i log sono uno stream con message/level/attributes/logger). Gli attributes passano dallo Scrubber (denylist). trace_id è preso dallo Scope corrente (popolato per richiesta) → correlazione log↔errori della stessa request.

Constant Summary collapse

LEVELS =

Livelli canonici del backend (enum) + alias dei nomi stile ::Logger. Normalizzati QUI (fonte unica) così ogni costruzione — via CloseYourIt.log, .logger o diretta — produce un livello valido.

%w[debug info warning error fatal].freeze
LEVEL_ALIASES =
{ "warn" => "warning", "err" => "error", "unknown" => "fatal" }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(message, level:, attributes:, configuration:, logger: nil) ⇒ LogEvent

Returns a new instance of LogEvent.



15
16
17
18
19
20
21
# File 'lib/closeyourit/events/log_event.rb', line 15

def initialize(message, level:, attributes:, configuration:, logger: nil)
  super(configuration)
  @message = message
  @level = normalize_level(level)
  @attributes = attributes || {}
  @logger = logger
end

Instance Method Details

#ingest_path(project_id) ⇒ Object



38
39
40
# File 'lib/closeyourit/events/log_event.rb', line 38

def ingest_path(project_id)
  "/api/v1/projects/#{project_id}/logs"
end

#to_hObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/closeyourit/events/log_event.rb', line 23

def to_h
  compact(
    "event_id" => SecureRandom.uuid.delete("-"),
    "timestamp" => @occurred_at,
    "level" => @level,
    "message" => @message.to_s,
    "attributes" => scrubbed_attributes,
    "logger" => @logger,
    "trace_id" => CloseYourIt::Scope.current.trace_id,
    "environment" => environment,
    "release" => @configuration.release,
    "sdk" => sdk
  )
end