From 3167157833b0930dad3a4c6bfef4fd30433db7cb Mon Sep 17 00:00:00 2001 From: Erdos Balint Date: Mon, 20 Nov 2023 17:25:21 +0900 Subject: [PATCH] Add usage explanation --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index 3605dc6..798063f 100644 --- a/README.md +++ b/README.md @@ -39,3 +39,22 @@ Utility function that builds Datadog headers for distributed tracing. By adding ;; (:require [sleepy.dog :as datadog]) (merge (datadog/http-headers) headers) ``` + +### `report-error!` + +Used to manually report caught exceptions (without relying on the automatic reporting from `with-tracing` or `defn-traced`). This can be useful for example in a Ring handler that catches all escaped exceptions are responds with a well-formed 500 error. + +```clj +(defn wrap-exception + [handler] + (fn exception-catcher + [request] + (try + (handler request) + (catch Throwable ex + (let [span (datadog/active-span!)] + (datadog/report-error! span ex) + (when-let [root (datadog/root-of span)] + (datadog/report-error! root ex))) + {:status 500 :body (.getMessage ex)})))) +```