Coder Social home page Coder Social logo

log_spy's Introduction

LogSpy

LogSpy is a Rack middleware sending request log to Amazon SQS on each request.

How it works

After each request, log_spy opens a new thread and sends the request log payload as a json string onto AWS SQS.

Why not use Papertrail or other log collector?

Logspy does not intend to replace the log collectors like Papertrail or something similar. The purpose of Logspy is to record each request and its params so that we can easily analyse even replay requests within a certain period.

Installation

Add this line to your application's Gemfile:

gem 'log_spy'

And then execute:

$ bundle

Or install it yourself as:

$ gem install log_spy

Usage

require and use the middleware:

  • Bare Rack:
require 'log_spy'
use LogSpy::Spy, 'aws-sqs-url'
  • Rails:
# config/application.rb
config.middleware.use LogSpy::Spy, 'aws-sqs-url', :reigon => 'ap-southeast-1',
                                                  :access_key_id => 'the-key-id',
                                                  :secret_access_key => 'the-secret'

API Documents:

to use the middleware:

  • usage: use LogSpy::Spy, <aws-sqs-url>[, <options>]
  • params:
    • aws-sqs-url(required): the Queue URL of SQS, which identifies the queue.
    • options(optional): if given, log_spy would pass it to initialize Aws::SQS

the payload format sends to AWS SQS:

{
  "path": "/the/request/path",
  "status": 200,
  "execution_time": 145.3, // in ms
  "controller_action": "users#show", // if env['action_dispatch.request.parameters'] exists
  "request": {
    "content_type": "application/json",
    "request_method": "post",
    "ip": "123.1.1.1",
    "query_string": "query-key=query-val&hello=world",
    "body": "body-key=body-val",
    "cookies": {
      "cookie_key": "cookie_val"
    }
  },

  // if got exception
  "error": {
    "message": "the exception message",
    "backtrace": [ "exception back trace" ]
  }
}
  • error: error would not be included in the payload if no exception was raised
  • request.body: if the request Content-Type is of multipart, the body would be an empty string

Testing:

$ bundle install $ bundle exec rspec spec/

Contributing

  1. Fork it ( https://github.com/[my-github-username]/log_spy/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

log_spy's People

Contributors

mz026 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.