Class: OpenTelemetry::SDK::Logs::LogRecord

Inherits:
Logs::LogRecord
  • Object
show all
Defined in:
lib/opentelemetry/sdk/logs/log_record.rb

Overview

Implementation of OpenTelemetry::Logs::LogRecord that records log events.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(timestamp: nil, observed_timestamp: nil, severity_text: nil, severity_number: nil, body: nil, attributes: nil, trace_id: nil, span_id: nil, trace_flags: nil, resource: nil, instrumentation_scope: nil, log_record_limits: nil) ⇒ LogRecord

Parameters:

  • timestamp (optional Time) (defaults to: nil)

    Time when the event occurred.

  • observed_timestamp (optional Time) (defaults to: nil)

    Time when the event was observed by the collection system. If nil, will first attempt to set to timestamp. If timestamp is nil, will set to Time.now.

  • span_context (optional OpenTelemetry::Trace::SpanContext)

    The OpenTelemetry::Trace::SpanContext to associate with the LogRecord.

  • severity_text (optional String) (defaults to: nil)

    The log severity, also known as log level.

  • severity_number (optional Integer) (defaults to: nil)

    The numerical value of the log severity.

  • body (optional String, Numeric, Boolean, Array<String, Numeric, Boolean>, Hash{String => String, Numeric, Boolean, Array<String, Numeric, Boolean>}) (defaults to: nil)
  • attributes (optional Hash{String => String, Numeric, Boolean, Array<String, Numeric, Boolean>}) (defaults to: nil)

    Attributes to associate with the OpenTelemetry::SDK::Logs::LogRecord.

  • trace_id (optional String) (defaults to: nil)

    The trace ID associated with the current context.

  • span_id (optional String) (defaults to: nil)

    The span ID associated with the current context.

  • trace_flags (optional OpenTelemetry::Trace::TraceFlags) (defaults to: nil)

    The trace flags associated with the current context.

  • resource (optional OpenTelemetry::SDK::Resources::Resource) (defaults to: nil)

    The source of the log, desrived from the LoggerProvider.

  • instrumentation_scope (optional OpenTelemetry::SDK::InstrumentationScope) (defaults to: nil)

    The instrumentation scope, derived from the emitting Logger

  • OpenTelemetry::SDK::LogRecordLimits] (optional)

    log_record_limits Attribute limits



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
# File 'lib/opentelemetry/sdk/logs/log_record.rb', line 61

def initialize(
  timestamp: nil,
  observed_timestamp: nil,
  severity_text: nil,
  severity_number: nil,
  body: nil,
  attributes: nil,
  trace_id: nil,
  span_id: nil,
  trace_flags: nil,
  resource: nil,
  instrumentation_scope: nil,
  log_record_limits: nil
)
  @timestamp = timestamp
  @observed_timestamp = observed_timestamp || timestamp || Time.now
  @severity_text = severity_text
  @severity_number = severity_number
  @body = body
  @attributes = attributes.nil? ? nil : Hash[attributes] # We need a mutable copy of attributes
  @trace_id = trace_id
  @span_id = span_id
  @trace_flags = trace_flags
  @resource = resource
  @instrumentation_scope = instrumentation_scope
  @log_record_limits = log_record_limits || LogRecordLimits::DEFAULT
  @total_recorded_attributes = @attributes&.size || 0

  trim_attributes(@attributes)
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



16
17
18
# File 'lib/opentelemetry/sdk/logs/log_record.rb', line 16

def attributes
  @attributes
end

#bodyObject

Returns the value of attribute body.



16
17
18
# File 'lib/opentelemetry/sdk/logs/log_record.rb', line 16

def body
  @body
end

#instrumentation_scopeObject

Returns the value of attribute instrumentation_scope.



16
17
18
# File 'lib/opentelemetry/sdk/logs/log_record.rb', line 16

def instrumentation_scope
  @instrumentation_scope
end

#observed_timestampObject

Returns the value of attribute observed_timestamp.



16
17
18
# File 'lib/opentelemetry/sdk/logs/log_record.rb', line 16

def observed_timestamp
  @observed_timestamp
end

#resourceObject

Returns the value of attribute resource.



16
17
18
# File 'lib/opentelemetry/sdk/logs/log_record.rb', line 16

def resource
  @resource
end

#severity_numberObject

Returns the value of attribute severity_number.



16
17
18
# File 'lib/opentelemetry/sdk/logs/log_record.rb', line 16

def severity_number
  @severity_number
end

#severity_textObject

Returns the value of attribute severity_text.



16
17
18
# File 'lib/opentelemetry/sdk/logs/log_record.rb', line 16

def severity_text
  @severity_text
end

#span_idObject

Returns the value of attribute span_id.



16
17
18
# File 'lib/opentelemetry/sdk/logs/log_record.rb', line 16

def span_id
  @span_id
end

#timestampObject

Returns the value of attribute timestamp.



16
17
18
# File 'lib/opentelemetry/sdk/logs/log_record.rb', line 16

def timestamp
  @timestamp
end

#trace_flagsObject

Returns the value of attribute trace_flags.



16
17
18
# File 'lib/opentelemetry/sdk/logs/log_record.rb', line 16

def trace_flags
  @trace_flags
end

#trace_idObject

Returns the value of attribute trace_id.



16
17
18
# File 'lib/opentelemetry/sdk/logs/log_record.rb', line 16

def trace_id
  @trace_id
end

Instance Method Details

#to_log_record_dataObject



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/opentelemetry/sdk/logs/log_record.rb', line 92

def to_log_record_data
  LogRecordData.new(
    to_integer_nanoseconds(@timestamp),
    to_integer_nanoseconds(@observed_timestamp),
    @severity_text,
    @severity_number,
    @body,
    @attributes,
    @trace_id,
    @span_id,
    @trace_flags,
    @resource,
    @instrumentation_scope,
    @total_recorded_attributes
  )
end