Class: Datadog::Core::Telemetry::Event::Log Private

Inherits:
Base
  • Object
show all
Defined in:
lib/datadog/core/telemetry/event/log.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Telemetry class for the ‘logs’ event. Logs with the same content are deduplicated at flush time.

Constant Summary collapse

LEVELS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

{
  error: 'ERROR',
  warn: 'WARN',
}.freeze
LEVELS_STRING =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

LEVELS.values.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message:, level:, stack_trace: nil, count: 1) ⇒ Log

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Log.

Parameters:

  • message (String)

    the log message

  • level (Symbol, String)

    the log level. Either :error, :warn, ‘ERROR’, or ‘WARN’.

  • stack_trace (String, nil) (defaults to: nil)

    the stack trace

  • count (Integer) (defaults to: 1)

    the number of times the log was emitted. Used for deduplication.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/datadog/core/telemetry/event/log.rb', line 29

def initialize(message:, level:, stack_trace: nil, count: 1)
  super()
  @message = message
  @stack_trace = stack_trace

  if level.is_a?(String) && LEVELS_STRING.include?(level)
    # String level is used during object copy for deduplication
    @level = level
  elsif level.is_a?(Symbol)
    # Symbol level is used by the regular log emitter user
    @level = LEVELS.fetch(level) { |k| raise ArgumentError, "Invalid log level :#{k}" }
  else
    raise ArgumentError, "Invalid log level #{level}"
  end

  @count = count
end

Instance Attribute Details

#countObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



19
20
21
# File 'lib/datadog/core/telemetry/event/log.rb', line 19

def count
  @count
end

#levelObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



19
20
21
# File 'lib/datadog/core/telemetry/event/log.rb', line 19

def level
  @level
end

#messageObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



19
20
21
# File 'lib/datadog/core/telemetry/event/log.rb', line 19

def message
  @message
end

#stack_traceObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



19
20
21
# File 'lib/datadog/core/telemetry/event/log.rb', line 19

def stack_trace
  @stack_trace
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

override equality to allow for deduplication



61
62
63
64
65
# File 'lib/datadog/core/telemetry/event/log.rb', line 61

def ==(other)
  other.is_a?(Log) &&
    other.message == @message &&
    other.level == @level && other.stack_trace == @stack_trace && other.count == @count
end

#hashObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



69
70
71
# File 'lib/datadog/core/telemetry/event/log.rb', line 69

def hash
  [self.class, @message, @level, @stack_trace, @count].hash
end

#payloadObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/datadog/core/telemetry/event/log.rb', line 47

def payload
  {
    logs: [
      {
        message: @message,
        level: @level,
        stack_trace: @stack_trace,
        count: @count,
      }.compact
    ]
  }
end

#typeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



21
22
23
# File 'lib/datadog/core/telemetry/event/log.rb', line 21

def type
  'logs'
end