Class: Logtide::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/logtide/event.rb

Overview

A single log entry in the LogTide wire format (spec 003).

The wire format is strict: the backend keeps only the top-level fields time|service|level|message|metadata|trace_id|span_id|session_id and silently strips everything else, so all extra data is nested under metadata.

Constant Summary collapse

SDK_NAME =
"logtide-ruby"
RESERVED_KEYS =

Reserved metadata keys the SDK populates from structured inputs (003 section 3). ‘sdk` is handled separately: a caller-provided value wins, so it is never namespaced.

%w[exception breadcrumbs tags user event_id release environment server_name].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service:, level:, message:, metadata: nil, time: nil, tags: nil, user: nil, breadcrumbs: nil, exception: nil, event_id: nil, release: nil, environment: nil, server_name: nil, trace_id: nil, span_id: nil, session_id: nil) ⇒ Event

Returns a new instance of Event.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/logtide/event.rb', line 22

def initialize(service:, level:, message:, metadata: nil, time: nil,
               tags: nil, user: nil, breadcrumbs: nil, exception: nil,
               event_id: nil, release: nil, environment: nil, server_name: nil,
               trace_id: nil, span_id: nil, session_id: nil)
  @service = service
  @level = level.to_s
  @message = message
  @time = time || Time.now.utc
  @metadata =  || {}
  @reserved = {
    "tags" => tags, "user" => user, "breadcrumbs" => breadcrumbs,
    "exception" => exception, "event_id" => event_id, "release" => release,
    "environment" => environment, "server_name" => server_name
  }.compact
  @trace_id = trace_id
  @span_id = span_id
  @session_id = session_id
end

Instance Attribute Details

#levelObject (readonly)

Returns the value of attribute level.



19
20
21
# File 'lib/logtide/event.rb', line 19

def level
  @level
end

#messageObject (readonly)

Returns the value of attribute message.



19
20
21
# File 'lib/logtide/event.rb', line 19

def message
  @message
end

#metadataObject (readonly)

Returns the value of attribute metadata.



19
20
21
# File 'lib/logtide/event.rb', line 19

def 
  @metadata
end

#serviceObject (readonly)

Returns the value of attribute service.



19
20
21
# File 'lib/logtide/event.rb', line 19

def service
  @service
end

#session_idObject (readonly)

Returns the value of attribute session_id.



19
20
21
# File 'lib/logtide/event.rb', line 19

def session_id
  @session_id
end

#span_idObject (readonly)

Returns the value of attribute span_id.



19
20
21
# File 'lib/logtide/event.rb', line 19

def span_id
  @span_id
end

#timeObject (readonly)

Returns the value of attribute time.



19
20
21
# File 'lib/logtide/event.rb', line 19

def time
  @time
end

#trace_idObject (readonly)

Returns the value of attribute trace_id.



19
20
21
# File 'lib/logtide/event.rb', line 19

def trace_id
  @trace_id
end

Instance Method Details

#to_wireObject

Build the JSON-ready Hash sent on the wire.



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/logtide/event.rb', line 42

def to_wire
  wire = {
    "time" => format_time(@time),
    "service" => @service,
    "level" => @level,
    "message" => @message,
    "metadata" => 
  }
  wire["trace_id"] = @trace_id if @trace_id
  wire["span_id"] = @span_id if @span_id
  wire["session_id"] = @session_id if @session_id
  wire
end