Code Monkey home page Code Monkey logo

clj-airbrake's Introduction

clj-airbrake

Clojure client for the Airbrake API

Usage

(require '[clj-airbrake.core :as airbrake])

(def request {:url "http://example.com" :component "foo" :action "bar"
             :cgi-data {"SERVER_NAME" "nginx", "HTTP_USER_AGENT" "Mozilla"}
             :params {"city" "LA", "state" "CA"}
             :session {"user-id" "23"}})

(def exception (try (throw (Exception. "Foo")) (catch Exception e e)) ; throw to get a stacktrace

;; send in blocking style using the JDK's http libs
(airbrake/notify "my-api-key" "production" "/app/dir" exception request)
=> {:error-id 42 :id 100 :url "http://sub.airbrakeapp.com/errors/42/notices/100"}


;; send async using http-kit and callbacks
(airbrake/notify-async (fn [resp] ...) "my-api-key" "production" "/app/dir" exception request)

;; the notify and notify-async fns are also dynamic vars if you wish to swap them out for
;; a different implementation using the same XML request helpers in clj-airbrake.core

Note that the request is one-to-one with Airbrake's API and not a Ring request. If you are using ring please see below about the provided ring middleware.

The request is optional but is the only way the Airbrake API allows you to pass in additonal information. So, if you are using the client out of the context of a web application you can use the request to send in enviromental variables or anything else that may help in troubleshooting. Note, that url in the request is required if you do provide a request hashmap.

Additional Configuration

If you need to change the host name where the errors are sent you you can use the #'set-host! function:

(require '[clj-airbrake.core :as airbrake])

(airbrake/set-host! "api.airbrake.io")

Installation

clj-airbrake is available as a Maven artifact Clojars.

Leiningen:

:dependencies
  [[clj-airbrake "2.4.3"] ...]

Maven:

<dependency>
  <groupId>clj-airbrake</groupId>
  <artifactId>clj-airbrake</artifactId>
  <version>2.4.3</version>
</dependency>

Development

Running the tests:

$ lein deps
$ lein test

Ring Middleware

Basic support for Ring is provided in the clj-airbrake.ring namespace: request parameters and session information are passed to Airbrake. A simple ring example:

(use 'ring.adapter.jetty)
(use 'ring.middleware.params)
(use 'ring.middleware.stacktrace)
(use 'clj-airbrake.ring)

(defn app [req]
  {:status  200
   :headers {"Content-Type" "text/html"}
   :body    (throw (Exception. "Testing"))})

(run-jetty (-> app
               (wrap-params)
               (wrap-airbrake "MY-API-KEY")
               (wrap-stacktrace))
           {:port 8080})

A typical application of Airbrake is recording any errors that happen in a script. You can do this with the with-airbrake wrapper. It will pass through exceptions happening inside and notify Airbrake.

(use 'clj-airbrake.core')

(defn -main
  [& args]
  (with-airbrake "MY-API-KEY"
                 "production"
                 (System/getProperty "user.dir")
                 {:component "scripts", :action "my-script"}
                 ;; your code goes here
                 ))

TODO

  • Param filtering. (e.g. automatically filter out any 'password' params)
  • Allow for certain environments to be ignored... defaulting to #{"test" "development"}
  • Configuartion management? i.e. set api-key once

License

Copyright (C) 2010 LeadTune and Ben Mabey

Released under the MIT License: http://www.opensource.org/licenses/mit-license.php

clj-airbrake's People

Contributors

bmabey avatar pingles avatar christianblunden avatar arohner avatar leonid-shevtsov avatar martintrojer avatar duey-sonian avatar gja avatar thiagotnunes avatar tgk avatar

Watchers

James Christie avatar James Cloos 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.