Class: Datadog::AppSec::ActionsHandler::SerializableBacktrace

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/appsec/actions_handler/serializable_backtrace.rb

Overview

Encapsulates serialisation of caller locations.

It serializes part of the stack: up to 32 frames (configurable) keeping frames from top and bottom of the stack (75% to 25%, configurable).

It represents the stack trace that is added to span metastruct field.

Constant Summary collapse

CLASS_AND_FUNCTION_NAME_REGEX =
/\b((?:\w+::)*\w+)?[#.]?\b(\w+)\z/.freeze

Instance Method Summary collapse

Constructor Details

#initialize(locations:, stack_id:) ⇒ SerializableBacktrace

Returns a new instance of SerializableBacktrace.



16
17
18
19
# File 'lib/datadog/appsec/actions_handler/serializable_backtrace.rb', line 16

def initialize(locations:, stack_id:)
  @stack_id = stack_id
  @locations = locations
end

Instance Method Details

#to_h ⇒ Object



28
29
30
31
32
33
34
# File 'lib/datadog/appsec/actions_handler/serializable_backtrace.rb', line 28

def to_h
  {
    "id" => @stack_id.encode("UTF-8"),
    "language" => "ruby".encode("UTF-8"),
    "frames" => build_serializable_frames,
  }
end

#to_msgpack(packer = nil) ⇒ Object



21
22
23
24
25
26
# File 'lib/datadog/appsec/actions_handler/serializable_backtrace.rb', line 21

def to_msgpack(packer = nil)
  # JRuby doesn't pass the packer
  packer ||= MessagePack::Packer.new
  packer.write(to_h)
  packer
end