1- # Akita HTTP Archive (HAR) logger for Rack applications
1+ # Akita HTTP Archive (HAR) logger for Rack/Rails applications
22
3- This provides Rack middleware for logging HTTP request–response pairs to a HAR
4- file.
3+ This provides Rack middleware and a Rails ` ActionController ` filter for logging
4+ HTTP request–response pairs to a HAR file.
55
66
77## Installation
@@ -23,24 +23,59 @@ Or install it yourself as:
2323
2424## Usage
2525
26- To instrument your Rack application, add ` Akita::HarLogger::Middleware ` to the
27- top of your middleware stack. For convenience, you can use
28- ` Akita::HarLogger.instrument ` , as follows.
29-
30- 1 . In your main ` application.rb ` , make ` Akita::HarLogger ` available:
31- ``` ruby
32- require ' akita/har_logger'
33- ```
34- 2 . Add the following line to the bottom of your ` Rails::Application`
35- subclass. Specifying the output file is optional; if not given, it defaults
36- to ` akita_trace_{timestamp}.har` .
37- ` ` ` ruby
38- Akita::HarLogger.instrument(config, '/path/to/output/har_file.har')
39- ` ` `
40-
41- Now , when you run your Rack application, all HTTP requests and responses will
42- be logged to the HAR file that you' ve specified. You can then upload this HAR
43- file to Akita for analysis.
26+ There are two options for instrumenting your Rack/Rails application. The first
27+ is to use the HAR logger as Rack middleware. The second is to use it as a Rails
28+ ` ActionController ` filter.
29+
30+ Depending on the framework you're using, one or both options may be available
31+ to you. If you are interested in logging RSpec tests, the filter option will
32+ capture traffic for both controller and request specs, whereas the middleware
33+ option only captures request specs.
34+
35+ Once your application is instrumented, when you run the application, HTTP
36+ requests and responses will be logged to the HAR file that you've specified.
37+ You can then upload this HAR file to Akita for analysis.
38+
39+ ### Middleware
40+
41+ To instrument with middleware, add ` Akita::HarLogger::Middleware ` to the top of
42+ your middleware stack. For convenience, you can call
43+ ` Akita::HarLogger.instrument ` to do this. We recommend adding this call to the
44+ bottom of ` config/environments/test.rb ` to add the middleware just to your test
45+ environment.
46+
47+ Here is a sample configuration for a test environment that just adds the
48+ instrumentation.
49+
50+ ``` ruby
51+ Rails .application.configure.do
52+ # Other configuration for the Rails application...
53+
54+ # Put the HAR logger at the top of the middleware stack, and optionally
55+ # give an output HAR file to save your trace. If not specified, this defaults
56+ # to `akita_trace_{timestamp}.har`.
57+ Akita ::HarLogger .instrument(config, " akita_trace.har" )
58+ end
59+ ```
60+
61+ ### ` ActionController ` filter
62+
63+ To instrument with a filter, add an instance of ` Akita::HarLogger::Filter ` as
64+ an ` around_action ` filter to your ` ActionController ` implementation. Here is an
65+ example of a bare-bones ` app/controllers/application_controller.rb ` with this
66+ instrumentation.
67+
68+ ``` ruby
69+ class ApplicationController < ActionController ::API
70+ include Response
71+ include ExceptionHandler
72+
73+ # Add the HAR logger as an `around_action` filter. Optionally give an output
74+ # HAR file to save your trace. If not specified, this defaults to
75+ # `akita_trace_{timestamp}.har`.
76+ around_action Akita ::HarLogger ::Filter .new (" akita_trace.har" )
77+ end
78+ ```
4479
4580
4681## Development
0 commit comments