Class: Logtide::Event
- Inherits:
-
Object
- Object
- Logtide::Event
- 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
-
#level ⇒ Object
readonly
Returns the value of attribute level.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#service ⇒ Object
readonly
Returns the value of attribute service.
-
#session_id ⇒ Object
readonly
Returns the value of attribute session_id.
-
#span_id ⇒ Object
readonly
Returns the value of attribute span_id.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
-
#trace_id ⇒ Object
readonly
Returns the value of attribute trace_id.
Instance Method Summary collapse
-
#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
constructor
A new instance of Event.
-
#to_wire ⇒ Object
Build the JSON-ready Hash sent on the wire.
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 = @time = time || Time.now.utc @metadata = || {} @reserved = { "tags" => , "user" => user, "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
#level ⇒ Object (readonly)
Returns the value of attribute level.
19 20 21 |
# File 'lib/logtide/event.rb', line 19 def level @level end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
19 20 21 |
# File 'lib/logtide/event.rb', line 19 def @message end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
19 20 21 |
# File 'lib/logtide/event.rb', line 19 def @metadata end |
#service ⇒ Object (readonly)
Returns the value of attribute service.
19 20 21 |
# File 'lib/logtide/event.rb', line 19 def service @service end |
#session_id ⇒ Object (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_id ⇒ Object (readonly)
Returns the value of attribute span_id.
19 20 21 |
# File 'lib/logtide/event.rb', line 19 def span_id @span_id end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
19 20 21 |
# File 'lib/logtide/event.rb', line 19 def time @time end |
#trace_id ⇒ Object (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_wire ⇒ Object
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 |