Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use prone to retrieve better frames #10

Merged
merged 1 commit into from May 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.5.1"]
[cheshire "5.0.1"]
[clj-http "3.0.1"]])
[clj-http "3.0.1"]
[prone "1.0.1"]])
39 changes: 27 additions & 12 deletions src/raven_clj/interfaces.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(ns raven-clj.interfaces)
(ns raven-clj.interfaces
(:require [prone.stacks :as stacks]))

(defn- make-http-info [req]
{:url (str (name (:scheme req))
Expand All @@ -17,17 +18,31 @@
(assoc event-map "sentry.interfaces.Http"
(alter-fn (make-http-info req))))

(defn- make-frame [^StackTraceElement element app-namespaces]
{:filename (.getFileName element)
:lineno (.getLineNumber element)
:function (str (.getClassName element) "." (.getMethodName element))
:in_app (boolean (some #(.startsWith (.getClassName element) %) app-namespaces))})
(defn file->source [file-path line-number]
(some-> (io/resource file-path)
slurp
(str/split #"\n")
(#(drop (- line-number 6) %))
(#(take 11 %))))

(defn- make-stacktrace-info [elements app-namespaces]
{:frames (reverse (map #(make-frame % app-namespaces) elements))})
(defn in-app [package app-namespaces]
(boolean (some #(.startsWith package %) app-namespaces)))

(defn frame->sentry [app-namespaces frame]
(let [source (file->source (:class-path-url frame) (:line-number frame))]
{:filename (:file-name frame)
:lineno (:line-number frame)
:function (str (:package frame) "/" (:method-name frame))
:in_app (in-app (:package frame) app-namespaces)
:context_line (nth source 5)
:pre_context (take 5 source)
:post_context (drop 6 source)}))

(defn stacktrace [event-map ^Exception e & [app-namespaces]]
(assoc event-map
:exception [{:stacktrace (make-stacktrace-info (.getStackTrace e) app-namespaces)
:type (str (class e))
:value (.getMessage e)}]))
(let [stacks (stacks/normalize-exception (stack/root-cause e))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is root-cause coming from here?

Copy link
Collaborator

@martinklepsch martinklepsch Jun 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it just clojure.stacktrace/root-cause?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! Sorry. :(

frames (map (partial frame->sentry app-namespaces)
(reverse (:frames stacks)))]
(assoc event-map
:exception [{:value (:message stacks)
:type (:type stacks)
:stacktrace {:frames frames}}])))