Skip to content

Commit

Permalink
Record exception class name
Browse files Browse the repository at this point in the history
If an exception happens during instrumentation with ActiveSupport the
payload will have a key :exception.

Report the exception class name as tag. Will make it possible to measure
"potential" problems. Potential as we don't know if the exception will
be handled higher up in the call chain.
  • Loading branch information
hennevogel committed Jul 20, 2020
1 parent b51ea56 commit fa151dc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ For the full commit log, [see here](https://github.com/influxdata/influxdb-rails
- Implement `perform_start.active_job` subscriber (https://guides.rubyonrails.org/active_support_instrumentation.html#perform-start-active-job)
- Implement `perform.active_job` subscriber (https://guides.rubyonrails.org/active_support_instrumentation.html#perform-active-job)
- Implement block instrumentation `InfluxDB::Rails.instrument do; 1 + 1; end`
- Record unhandled exceptions as tags for process_action.action_controller

## v1.0.0, released 2019-10-23
The Final release, no code changes.
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,15 @@ Reported tags:
method: "PostsController#index",
http_method: "GET",
format: "html",
status: "200"
status: ["200", ""]
exception: ["", "ArgumentError"]
}
```

*Note*: If an exception happens during that particular instrumentation the
`status` will be blank and the tag `exception` will contain the name of the
exception class.

### Action View

Reported ActiveSupport instrumentation hooks:
Expand Down
1 change: 1 addition & 0 deletions lib/influxdb/rails/middleware/request_subscriber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def tags(payload)
status: payload[:status],
format: payload[:format],
http_method: payload[:method],
exception: payload[:exception]&.first,
}
end

Expand Down
5 changes: 3 additions & 2 deletions spec/requests/action_controller_metrics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@

expect_metric(
tags: a_hash_including(
method: "ExceptionsController#index",
hook: "process_action"
method: "ExceptionsController#index",
hook: "process_action",
exception: "ZeroDivisionError"
)
)
end
Expand Down

0 comments on commit fa151dc

Please sign in to comment.