-
Notifications
You must be signed in to change notification settings - Fork 377
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# frozen_string_literal: true | ||
|
||
module Datadog | ||
module AppSec | ||
# Stack trace | ||
class StackTrace | ||
attr_reader :id, :message, :frames | ||
|
||
def initialize(id, stack_trace, message: nil) | ||
@id = id | ||
@message = message | ||
@frames = stack_trace.each_with_index.map do |frame, index| | ||
Frame.new( | ||
index, | ||
text: frame.to_s, | ||
file: frame.absolute_path, # path will show 'main' instead of the actual file | ||
line: frame.lineno, | ||
function: frame.base_label # label will show 'block in function' instead of just 'function' | ||
) | ||
end | ||
end | ||
|
||
def to_h | ||
@to_h ||= { | ||
language: 'ruby', | ||
id: @id, | ||
message: @message, | ||
frames: @frames.map(&:to_h) | ||
} | ||
end | ||
|
||
# Stack frame | ||
class Frame | ||
attr_reader :id, :text, :file, :line, :function | ||
|
||
def initialize(id, text: nil, file: nil, line: nil, function: nil) | ||
@id = id | ||
@text = text | ||
@file = file | ||
@line = line | ||
@function = function | ||
end | ||
|
||
def to_h | ||
@to_h ||= { | ||
id: @id, | ||
text: @text, | ||
file: @file, | ||
line: @line, | ||
function: @function | ||
} | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Datadog | ||
module AppSec | ||
class StackTrace | ||
attr_reader id: ::String | ||
attr_reader message: ::String? | ||
attr_reader frames: ::Array[Frame] | ||
|
||
@to_h: ::Hash[::Symbol, untyped] | ||
|
||
def initialize: (::String id, ::Array[::Thread::Backtrace::Location] stack_trace, ?message: ::String?) -> void | ||
|
||
class Frame | ||
attr_reader id: ::Integer | ||
attr_reader text: ::String? | ||
attr_reader file: ::String? | ||
attr_reader line: ::Integer? | ||
attr_reader function: ::String? | ||
|
||
@to_h: ::Hash[::Symbol, untyped] | ||
|
||
def initialize: (::Integer id, ?text: ::String?, ?file: ::String?, ?line: ::Integer?, ?function: ::String?) -> void | ||
|
||
def to_h: () -> ::Hash[::Symbol, untyped] | ||
end | ||
end | ||
end | ||
end |