Skip to content

Commit 48f5ef6

Browse files
authored
Merge pull request #254 from instana/hm/stack-trace
Clean up #add_stack
2 parents 63180c3 + d67aac9 commit 48f5ef6

File tree

1 file changed

+10
-28
lines changed

1 file changed

+10
-28
lines changed

lib/instana/tracing/span.rb

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -80,34 +80,16 @@ def initialize(name, parent_ctx: nil, start_time: ::Instana::Util.now_in_ms)
8080
# @param limit [Integer] Limit the backtrace to the top <limit> frames
8181
#
8282
def add_stack(limit: 30, stack: Kernel.caller)
83-
frame_count = 0
84-
sanitized_stack = []
85-
@data[:stack] = []
86-
limit = 40 if limit > 40
87-
88-
stack.each do |i|
89-
# If the stack has the full instana gem version in it's path
90-
# then don't include that frame. Also don't exclude the Rack module.
91-
if !i.match(/instana\/instrumentation\/rack.rb/).nil? ||
92-
(i.match(::Instana::VERSION_FULL).nil? && i.match('lib/instana/').nil?)
93-
94-
x = i.split(':')
95-
96-
sanitized_stack << {
97-
:c => x[0],
98-
:n => x[1],
99-
:m => x[2]
100-
}
101-
end
102-
end
103-
104-
if sanitized_stack.length > limit
105-
# (limit * -1) gives us negative form of <limit> used for
106-
# slicing from the end of the list. e.g. stack[-30, 30]
107-
@data[:stack] = sanitized_stack[limit*-1, limit]
108-
else
109-
@data[:stack] = sanitized_stack
110-
end
83+
@data[:stack] = stack
84+
.map do |call|
85+
file, line, *method = call.split(':')
86+
87+
{
88+
c: file,
89+
n: line,
90+
m: method.join(' ')
91+
}
92+
end.take(limit > 40 ? 40 : limit)
11193
end
11294

11395
# Log an error into the span

0 commit comments

Comments
 (0)