Skip to content

Commit 78c307b

Browse files
committed
Add Sentry tracing and supporting ring middleware.
Big thanks to @karuta0825 for the tracing functionality! Update Sentry Java SDK to 5.7.1. Various library updates. Fixes #32. -=david=-
1 parent 357f775 commit 78c307b

File tree

19 files changed

+543
-46
lines changed

19 files changed

+543
-46
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ jobs:
1616
runs-on: ubuntu-latest
1717
strategy:
1818
matrix:
19-
java: [ '8', '17']
19+
java: ['8', '17']
2020
steps:
2121
- uses: actions/checkout@v3
2222

2323
- name: Setup Cache
24-
uses: actions/cache@v2
24+
uses: actions/cache@v3
2525
with:
2626
path: |
2727
~/.m2

CHANGELOG.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ commits since the beginning of this repository.
1616
### Added
1717
### Removed
1818

19+
## [5.7.172]
20+
21+
### Added
22+
23+
- The ability to use tracing with Sentry. Big thanks to @karuta0825. There is an example in the `examples` directory.
24+
25+
### Changed
26+
27+
- Update Sentry Java SDK to 5.7.1.
28+
- Various library updates.
29+
- Update github workers cache to v3
30+
1931
## [5.7.171]
2032

2133
### Changed
@@ -256,7 +268,8 @@ commits since the beginning of this repository.
256268
compatible with Sentry 10.0.1 and below. If you wish to use those
257269
versions, please continue to use sentry-clj 1.7.30.
258270

259-
[Unreleased]: https://github.com/getsentry/sentry-clj/compare/5.7.171...HEAD
271+
[Unreleased]: https://github.com/getsentry/sentry-clj/compare/5.7.172...HEAD
272+
[5.7.172]: https://github.com/getsentry/sentry-clj/compare/5.7.171...5.7.172
260273
[5.7.171]: https://github.com/getsentry/sentry-clj/compare/5.6.170...5.7.171
261274
[5.6.170]: https://github.com/getsentry/sentry-clj/compare/5.6.169...5.6.170
262275
[5.6.169]: https://github.com/getsentry/sentry-clj/compare/5.6.166...5.6.169

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ If you want an interpolated message, you need to provide the full map, i.e.,
7777
| | [More Information](https://docs.sentry.io/platforms/java/enriching-events/breadcrumbs/) |
7878
| `:contexts` | A map of key/value pairs to attach to every Event that is sent. |
7979
| | [More Information)(https://docs.sentry.io/platforms/java/enriching-events/context/) |
80+
| `:traces-sample-rate` | Set a uniform sample rate(a number of between 0.0 and 1.0) for all transactions for tracing |
81+
| `:traces-sample-fn` | A function (taking a custom sample context and a transaction context) enables you to control trace transactions |
8082

8183
Some examples:
8284

deps.edn

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
;;
55
;;
66
;;
7-
io.sentry/sentry {:mvn/version "5.7.0"}
7+
io.sentry/sentry {:mvn/version "5.7.1"}
88
ring/ring-core {:mvn/version "1.9.5"}}
99

1010
:aliases {:build {:deps {io.github.seancorfield/build-clj {:git/tag "v0.8.0"
@@ -13,7 +13,7 @@
1313

1414
:test {:extra-paths ["test"]
1515
:extra-deps {cheshire/cheshire {:mvn/version "5.10.2"}
16-
com.github.seancorfield/expectations {:mvn/version "2.0.157"}
16+
com.github.seancorfield/expectations {:mvn/version "2.0.160"}
1717
lambdaisland/kaocha {:mvn/version "1.64.1010"}
1818
lambdaisland/kaocha-cloverage {:mvn/version "1.0.75"}
1919
lambdaisland/kaocha-junit-xml {:mvn/version "0.0.76"}
@@ -24,6 +24,7 @@
2424
org.slf4j/slf4j-nop {:mvn/version "1.7.36"}}
2525
:exec-fn antq.tool/outdated
2626
:exec-args {:directory ["."]
27+
:exclude [org.clojure/clojure]
2728
:skip ["pom"]
2829
:verbose true
2930
:upgrade true

examples/README.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,7 @@ as:
3333
`bin/run -d DSN`
3434

3535
Where `DSN` is your DSN URL.
36+
37+
== Tracing
38+
39+
This example shows how to perform tracing with Ring.

examples/basic/deps.edn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
;;
66
;;
77
ch.qos.logback/logback-classic {:mvn/version "1.2.11"}
8-
io.sentry/sentry {:mvn/version "5.7.0"}
9-
io.sentry/sentry-clj {:mvn/version "5.7.171"}
8+
io.sentry/sentry {:mvn/version "5.7.1"}
9+
io.sentry/sentry-clj {:local/root "../../../sentry-clj"}
1010
org.clojure/tools.cli {:mvn/version "1.0.206"}
1111
org.clojure/tools.logging {:mvn/version "1.2.4"}
1212
org.slf4j/jcl-over-slf4j {:mvn/version "1.7.36"}

examples/basic/src/basic/main.clj

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
(ns basic.main
2-
(:require
3-
[clojure.tools.logging :as log]
4-
[sentry-clj.core :as sentry]))
2+
(:require
3+
[clojure.tools.logging :as log]
4+
[sentry-clj.core :as sentry]))
55

66
(defn ^:private create-sentry-logger
77
"Create a Sentry Logger using the supplied `dsn`.
8-
98
If no `dsn` is supplied, simply log the `event` to a `logger`."
109
[{:keys [dsn] :as config}]
1110
(if dsn
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{:paths ["src" "resources"]
2+
3+
:deps {org.clojure/clojure {:mvn/version "1.10.3"}
4+
;;
5+
;;
6+
;;
7+
ch.qos.logback/logback-classic {:mvn/version "1.2.11"}
8+
integrant/integrant {:mvn/version "0.8.0"}
9+
integrant/repl {:mvn/version "0.3.2"}
10+
io.sentry/sentry {:mvn/version "5.7.1"}
11+
io.sentry/sentry-clj {:local/root "../../../sentry-clj"}
12+
org.clojure/tools.cli {:mvn/version "1.0.206"}
13+
org.clojure/tools.logging {:mvn/version "1.2.4"}
14+
org.slf4j/jcl-over-slf4j {:mvn/version "1.7.36"}
15+
org.slf4j/jul-to-slf4j {:mvn/version "1.7.36"}
16+
org.slf4j/log4j-over-slf4j {:mvn/version "1.7.36"}
17+
org.slf4j/slf4j-api {:mvn/version "1.7.36"}
18+
ring/ring-core {:mvn/version "1.9.5"}
19+
ring/ring-jetty-adapter {:mvn/version "1.9.5"}
20+
ring/ring-json {:mvn/version "0.5.1"}}}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration scan="true" scanPeriod="10 seconds">
3+
4+
<statusListener class="ch.qos.logback.core.status.NopStatusListener" />
5+
6+
<contextName>examples.basic</contextName>
7+
8+
<variable name="ROOT_LOG_LEVEL" value="${ROOT_LOG_LEVEL:-info}" />
9+
10+
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
11+
<encoder>
12+
<Pattern>[%boldWhite(%d)] --- [%boldBlue(%-5level)][%boldGreen(%-25.25logger{25})] - %msg%n%rEx</Pattern>
13+
</encoder>
14+
</appender>
15+
16+
<root level="${ROOT_LOG_LEVEL}">
17+
<appender-ref ref="CONSOLE"/>
18+
</root>
19+
20+
</configuration>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
(ns ring-with-tracing.main
2+
(:require
3+
[integrant.core :as ig]
4+
[ring.adapter.jetty :refer [run-jetty]]
5+
[ring.middleware.json :refer [wrap-json-params wrap-json-response]]
6+
[ring.middleware.keyword-params :refer [wrap-keyword-params]]
7+
[sentry-clj.core :as sentry]
8+
[sentry-clj.ring :refer [wrap-report-exceptions wrap-sentry-tracing]]
9+
[sentry-clj.tracing :refer [with-start-child-span]]))
10+
11+
(def config
12+
{:adapter/jetty {:port 8080, :handler (ig/ref :handler/router)}
13+
:handler/router {:app (ig/ref :handler/hello)}
14+
:handler/hello {:name "Sentry"}})
15+
16+
(defmethod ig/init-key :adapter/jetty [_ {:keys [handler] :as opts}]
17+
(run-jetty handler (-> opts (dissoc :handler) (assoc :join? false))))
18+
19+
(defmethod ig/init-key :handler/hello [_ {:keys [name]}]
20+
(fn [request]
21+
22+
(with-start-child-span "task" "my-child-operation"
23+
(Thread/sleep 1000))
24+
25+
{:status 200
26+
:headers {"Content-type" "application/json"}
27+
:body (str "Hi " name)}))
28+
29+
(defmethod ig/init-key :handler/router [_ {:keys [app]}]
30+
;; set your dsn
31+
(let [dsn "https://abcdefg@localhost:9000/2"]
32+
(sentry/init! dsn {:dsn dsn
33+
:environment "local"
34+
:traces-sample-rate 1.0
35+
:debug true}))
36+
37+
(-> app
38+
(wrap-report-exceptions {})
39+
wrap-sentry-tracing
40+
wrap-keyword-params
41+
wrap-json-params
42+
wrap-json-response))
43+
44+
(defmethod ig/halt-key! :adapter/jetty [_ server]
45+
(.stop server))
46+
47+
(defn -main
48+
[& _]
49+
(-> config
50+
ig/init))

0 commit comments

Comments
 (0)