Clojure library for tracing (possibly async) applications with Datadog.
Available on Clojars.
[jp.studist/sleepydog "0.4.1"]
The public API is in the sleepy.dog namespace.
defn-tracedA drop-in replacement for Clojure's defn that instruments the function in question as a new Datadog span.
wrap-ring-traceA ring middleware that automatically instruments server requests.
Pass {:continue-trace? true} to continue the trace context in the request headers (in the propagation styles the
agent extracts, Datadog and W3C traceparent by default).
Enable it only for trusted callers, since headers from the internet can be forged.
(wrap-ring-trace handler {:continue-trace? true})
with-tracing "op-name"A macro that instruments the given body as a span labelled as operation "op-name".
set-resource!Sets the resource (subject) of the current span's operation.
(with-tracing "s3-upload"
(set-resource! "foo/bar/baz.jpg")
,,, ; prepare upload
(.putObject client put-request))
http-headersUtility function that builds Datadog headers for distributed tracing. By adding these headers to any outgoing (upstream) request, it's possible to connect traces across services.
;; (:require [sleepy.dog :as datadog])
(merge (datadog/http-headers) headers)
tag-span!Adds a custom tag to a span. Accepts String, Boolean, Number, or nil values.
(let [span (datadog/active-span!)]
(datadog/tag-span! span "user.id" user-id)
(datadog/tag-span! span "feature.enabled" true))
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 and responds with a well-formed 500 error.
If you want to mark an entire request as "errored", then combine this with root-of to mark the root span as error.
(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)}))))
You can enable tracing for the Carmine Redis library by using sleepy.dog.carmine/trace-carmine!. The traces will be reported mimicking the way how Datadog auto-instruments Jedis or the Ruby redis gem.
Can you improve this documentation? These fine people already did:
Erdos Balint, Shota Kudo (chaploud), valerauko & Jumpei YamakawaEdit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |