Skip to content

Commit

Permalink
Merge pull request #699 from bugsnag/tms/ignore-system-anrs
Browse files Browse the repository at this point in the history
Ignore system-generated ANRs
  • Loading branch information
twometresteve authored Nov 7, 2024
2 parents fca5038 + 447f9e3 commit 502ac90
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 9.18.0 - 2024/11/07

## Enhancements

- Ignore system generated ANRs on Android [699](https://github.com/bugsnag/maze-runner/pull/699)

# 9.17.0 - 2024/11/06

## Enhancements
Expand Down
1 change: 1 addition & 0 deletions lib/features/support/internal_hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
output_received_requests('traces')
output_received_requests('builds')
output_received_requests('logs')
output_received_requests('ignored requests')
output_received_requests('invalid requests')
end

Expand Down
2 changes: 1 addition & 1 deletion lib/maze.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Glues the various parts of MazeRunner together that need to be accessed globally,
# providing an alternative to the proliferation of global variables or singletons.
module Maze
VERSION = '9.17.0'
VERSION = '9.18.0'

class << self
attr_accessor :check, :driver, :internal_hooks, :mode, :start_time, :dynamic_retry, :public_address,
Expand Down
2 changes: 1 addition & 1 deletion lib/maze/maze_output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def write_requests
path = output_folder
FileUtils.makedirs(path)

request_types = %w[errors sessions builds uploads logs sourcemaps traces invalid reflections]
request_types = %w[errors sessions builds uploads logs sourcemaps traces ignored invalid reflections]
request_types << 'sampling requests'

request_types.each do |request_type|
Expand Down
7 changes: 7 additions & 0 deletions lib/maze/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ def list_for(type)
sourcemaps
when 'reflect', 'reflects', 'reflection', 'reflections'
reflections
when 'ignored', 'ignored requests'
ignored_requests
when 'invalid', 'invalid requests'
invalid_requests
else
Expand Down Expand Up @@ -186,6 +188,10 @@ def commands
@commands ||= RequestList.new
end

def ignored_requests
@ignored_requests ||= RequestList.new
end

# Whether the server thread is running
# An array of any invalid requests received.
# Each request is hash consisting of:
Expand Down Expand Up @@ -297,6 +303,7 @@ def reset!
sampling_requests.clear
traces.clear
logs.clear
ignored_requests.clear
invalid_requests.clear
reflections.clear
end
Expand Down
20 changes: 19 additions & 1 deletion lib/maze/servlets/servlet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,25 @@ def do_OPTIONS(request, response)
private

def add_request(request)
Server.list_for(@request_type).add(request)
if @request_type == :errors and system_generated_anr?(request)
$logger.info 'Ignoring system-generated ANR'
Server.list_for('ignored').add(request)
else
Server.list_for(@request_type).add(request)
end
end

def system_generated_anr?(request)
body = request[:body]
error_class = Maze::Helper.read_key_path(body, 'events.0.exceptions.0.errorClass')
return false unless error_class == 'ANR'

stack_trace = Maze::Helper.read_key_path(body, 'events.0.exceptions.0.stacktrace')
return false unless stack_trace.kind_of?(Array)

method_1 = stack_trace.any? { |frame| frame['method'] == 'android.os.BinderProxy.transact' }
method_2 = stack_trace.any? { |frame| frame['method'] == 'android.app.IActivityManager$Stub$Proxy.handleApplicationCrash' }
method_1 && method_2
end

def log_request(request)
Expand Down

0 comments on commit 502ac90

Please sign in to comment.