Class: Contrast::Utils::StackTraceUtils
- Defined in:
- lib/contrast/utils/stack_trace_utils.rb
Overview
Utilities for converting ruby stack trace into DTMs
Constant Summary collapse
- AGENT_CLASS_MARKER =
need lib here to separate from specs
'/lib/contrast/'
Class Method Summary collapse
-
.build_assess_stack_array(stack) ⇒ Array<Contrast::Api::Dtm::TraceStack]
Translate a caller array to an array of TraceStacks for TeamServer to display, excluding any Contrast code found.
-
.build_protect_stack_array ⇒ Array<Contrast::Api::Dtm::StackTraceElement]
Call and translate a caller_locations array to an array of StackTraceElement for TeamServer to display, excluding any Contrast code found.
-
.custom_code_context? ⇒ Boolean
Determine if this method is being invoked by application code or not based on the immediate caller of the code after Contrast.
Class Method Details
.build_assess_stack_array(stack) ⇒ Array<Contrast::Api::Dtm::TraceStack]
Translate a caller array to an array of TraceStacks for TeamServer to display, excluding any Contrast code found.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/contrast/utils/stack_trace_utils.rb', line 60 def build_assess_stack_array stack converted = [] return converted unless stack i = 0 while i < stack.length caller_location = stack[i] i += 1 next if caller_location.include?(AGENT_CLASS_MARKER) # To play nice with the way that TeamServer is rendering these # values, we only populate the file_name field with exactly what we # want them to display element = Contrast::Api::Dtm::TraceStack.new element.file_name = caller_location converted << element end converted end |
.build_protect_stack_array ⇒ Array<Contrast::Api::Dtm::StackTraceElement]
Call and translate a caller_locations array to an array of StackTraceElement for TeamServer to display, excluding any Contrast code found.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/contrast/utils/stack_trace_utils.rb', line 39 def build_protect_stack_array stack = caller(2, 20) return [] unless stack stack = reject_caller_entries(stack) i = 0 stack.map! do |entry| element = Contrast::Api::Dtm::StackTraceElement.new element = fill_protect_element(element, entry, i) i += 1 element end stack.compact! stack end |
.custom_code_context? ⇒ Boolean
Determine if this method is being invoked by application code or not based on the immediate caller of the code after Contrast.
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/contrast/utils/stack_trace_utils.rb', line 20 def custom_code_context? root_dir = Contrast::Agent.framework_manager.app_root stack = Kernel.caller(0, 15) i = 0 while i < stack.length stack_element = stack[i] i += 1 next if stack_element.include?('/contrast/') return stack_element.start_with?(root_dir) end end |