Skip to content

Commit

Permalink
Update Sentry Java SDK to 6.3.1
Browse files Browse the repository at this point in the history
Added new entries for serialization-max-depth and renamed
shutdown-timeout to shutdown-timeout-millis (to align with the Java SDK)

fixes #31, fixes #48

-=david=-
  • Loading branch information
dharrigan committed Aug 8, 2022
1 parent 72ecd65 commit 15dee99
Show file tree
Hide file tree
Showing 18 changed files with 102 additions and 97 deletions.
18 changes: 10 additions & 8 deletions .clj-kondo/config.edn
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
;;
;;
;;
{:skip-comments true
:linters
{:single-key-in true
:unsorted-required-namespaces {:level :warning}
:unresolved-symbol {:exclude [(expectations.clojure.test/defexpect)]}
:unused-binding {:exclude-destructured-as true}
:unused-referred-var {:exclude {clojure.test [is deftest testing]
expectations.clojure.test [defexpect]}}
:lint-as {expectations.clojure.test/defexpect clojure.test/deftest}}}
:linters {:single-key-in {:level :warning}
:unsorted-required-namespaces {:level :warning}
:unresolved-symbol {:exclude [(expectations.clojure.test/defexpect)]}
:unused-binding {:exclude-destructured-as true}
:unused-referred-var {:exclude {clojure.test [is deftest testing]
expectations.clojure.test [defexpect]}}}
:lint-as {expectations.clojure.test/defexpect clojure.test/deftest}}
6 changes: 6 additions & 0 deletions .lsp/config.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{:clean {:ns-inner-blocks-indentation :next-line
:sort {:import-classes {:classes-per-line -1}
:refer {:max-line-length 256}}}
:hover {:arity-on-same-line? true
:hide-file-location? true}
:use-metadata-for-privacy? true}
12 changes: 7 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ endeavour to be non-breaking (by moving to new names rather than by
breaking existing names). COMMITS is an ever-increasing counter of
commits since the beginning of this repository.

## [Unreleased]
## [6.3.181]

### Changed
### Added
### Removed
- Update Sentry Java SDK to 6.3.1.
- shutdown-timeout renamed to shutdown-timeout-millis in keeping with the Java SDK changes
- added `serialization-max-depth` to work around circular reference errors when performing serialization of throwables
- defaults to 5, although you can adjust lower if a circular reference loop occurs

## [5.7.180]

Expand Down Expand Up @@ -288,7 +289,8 @@ commits since the beginning of this repository.
compatible with Sentry 10.0.1 and below. If you wish to use those
versions, please continue to use sentry-clj 1.7.30.

[Unreleased]: https://github.com/getsentry/sentry-clj/compare/5.7.180...HEAD
[Unreleased]: https://github.com/getsentry/sentry-clj/compare/6.3.181...HEAD
[6.3.181]: https://github.com/getsentry/sentry-clj/compare/5.7.180...6.3.181
[5.7.180]: https://github.com/getsentry/sentry-clj/compare/5.7.178...5.7.180
[5.7.178]: https://github.com/getsentry/sentry-clj/compare/5.7.177...5.7.178
[5.7.177]: https://github.com/getsentry/sentry-clj/compare/5.7.176...5.7.177
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ If you want an interpolated message, you need to provide the full map, i.e.,
| `:release` | All events are assigned to a particular release |
| `:dist` | Set the application distribution that will be sent with each event |
| `:server-name` | Set the server name that will be sent with each event |
| `:shutdown-timeout` | Wait up to X milliseconds before shutdown if there are events to send | 2000ms
| `:shutdown-timeout-millis` | Wait up to X milliseconds before shutdown if there are events to send | 2000ms
| `:in-app-includes` | A seqable collection (vector for example) containing package names to include when sending events |
| `:in-app-excludes` | A seqable collection (vector for example) containing package names to ignore when sending events |
| `:ignored-exceptions-for-type` | Set exceptions that will be filtered out before sending to Sentry (a set of Classnames as Strings) |
Expand All @@ -81,7 +81,8 @@ If you want an interpolated message, you need to provide the full map, i.e.,
| `:contexts` | A map of key/value pairs to attach to every Event that is sent. |
| | [More Information](https://docs.sentry.io/platforms/java/enriching-events/context/) |
| `:traces-sample-rate` | Set a uniform sample rate(a number of between 0.0 and 1.0) for all transactions for tracing |
| `:traces-sample-fn` | A function (taking a custom sample context and a transaction context) enables you to control trace transactions |
| `:traces-sample-fn` | A function (taking a custom sample context and a transaction context) enables you to control trace transactions |
| `:serialization-max-depth` | Set to a lower number, i.e., 2, if you experience circular reference errors when sending events | 5

Some examples:

Expand Down Expand Up @@ -189,6 +190,6 @@ Each key is optional.

## License

Copyright © 2021 Coda Hale, Sentry
Copyright © 2022 Coda Hale, Sentry

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.
20 changes: 9 additions & 11 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,27 @@
;;
;;
;;
io.sentry/sentry {:mvn/version "5.7.4"}
io.sentry/sentry {:mvn/version "6.3.1"}
ring/ring-core {:mvn/version "1.9.5"}}

:aliases {:build {:deps {io.github.seancorfield/build-clj {:git/tag "v0.8.0"
:git/sha "9bd8b8a"}}
:aliases {:build {:deps {io.github.seancorfield/build-clj {:git/tag "v0.8.3"
:git/sha "7ac1f8d"}}
:ns-default scripts.build}

:test {:extra-paths ["test"]
:extra-deps {cheshire/cheshire {:mvn/version "5.10.2"}
:extra-deps {cheshire/cheshire {:mvn/version "5.11.0"}
com.github.seancorfield/expectations {:mvn/version "2.0.160"}
lambdaisland/kaocha {:mvn/version "1.66.1034"}
lambdaisland/kaocha-cloverage {:mvn/version "1.0.75"}
lambdaisland/kaocha-junit-xml {:mvn/version "0.0.76"}
lambdaisland/kaocha {:mvn/version "1.69.1069"}
lambdaisland/kaocha-junit-xml {:mvn/version "1.16.98"}
orchestra/orchestra {:mvn/version "2021.01.01-1"}
org.clojure/test.check {:mvn/version "1.1.1"}}}

:antq {:replace-deps {com.github.liquidz/antq {:mvn/version "1.6.2"}
:antq {:replace-deps {com.github.liquidz/antq {:mvn/version "1.9.874"}
org.slf4j/slf4j-nop {:mvn/version "1.7.36"}}
:exec-fn antq.tool/outdated
:exec-args {:directory ["."]
:exclude [org.clojure/clojure]
:skip ["pom"]
:exec-args {:skip ["pom"]
:verbose true
:upgrade true
:download true
:no-diff true
:force true}}}}
2 changes: 1 addition & 1 deletion examples/basic/deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
;;
;;
ch.qos.logback/logback-classic {:mvn/version "1.2.11"}
io.sentry/sentry {:mvn/version "5.7.4"}
io.sentry/sentry {:mvn/version "6.3.1"}
io.sentry/sentry-clj {:local/root "../../../sentry-clj"}
org.clojure/tools.cli {:mvn/version "1.0.206"}
org.clojure/tools.logging {:mvn/version "1.2.4"}
Expand Down
2 changes: 1 addition & 1 deletion examples/ring_with_tracing/deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
ch.qos.logback/logback-classic {:mvn/version "1.2.11"}
integrant/integrant {:mvn/version "0.8.0"}
integrant/repl {:mvn/version "0.3.2"}
io.sentry/sentry {:mvn/version "5.7.4"}
io.sentry/sentry {:mvn/version "6.3.1"}
io.sentry/sentry-clj {:local/root "../../../sentry-clj"}
org.clojure/tools.cli {:mvn/version "1.0.206"}
org.clojure/tools.logging {:mvn/version "1.2.4"}
Expand Down
2 changes: 1 addition & 1 deletion examples/ring_with_tracing/src/ring_with_tracing/main.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
(run-jetty handler (-> opts (dissoc :handler) (assoc :join? false))))

(defmethod ig/init-key :handler/hello [_ {:keys [name]}]
(fn [request]
(fn [_request]

(with-start-child-span "task" "my-child-operation"
(Thread/sleep 1000))
Expand Down
2 changes: 1 addition & 1 deletion examples/uncaught/deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
;;
;;
ch.qos.logback/logback-classic {:mvn/version "1.2.11"}
io.sentry/sentry {:mvn/version "5.7.4"}
io.sentry/sentry {:mvn/version "6.3.1"}
io.sentry/sentry-clj {:local/root "../../../sentry-clj"}
org.clojure/tools.cli {:mvn/version "1.0.206"}
org.clojure/tools.logging {:mvn/version "1.2.4"}
Expand Down
2 changes: 1 addition & 1 deletion examples/uncaught/src/uncaught/main.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[sentry-logger]
(Thread/setDefaultUncaughtExceptionHandler
(reify Thread$UncaughtExceptionHandler
(uncaughtException [_ thread ex]
(uncaughtException [_ _thread ex]
(log/warn ex "Uncaught Exception!")
(sentry-logger {:throwable ex})))))

Expand Down
2 changes: 1 addition & 1 deletion scripts/build.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[clojure.tools.build.api :as b]
[org.corfield.build :as bb]))

(def ^:private version (format "5.7.%s" (b/git-count-revs nil)))
(def ^:private version (format "6.3.%s" (b/git-count-revs nil)))
(def ^:private library 'io.sentry/sentry-clj)

(defn run-tests
Expand Down
45 changes: 31 additions & 14 deletions src/sentry_clj/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
(:import
[io.sentry Breadcrumb DateUtils Sentry SentryEvent SentryLevel SentryOptions]
[io.sentry.protocol Message Request SentryId User]
[java.util HashMap Map UUID Date]))
[java.util Date HashMap Map UUID]))

(set! *warn-on-reflection* true)

Expand All @@ -32,12 +32,11 @@
(if (map? v) [k (HashMap. ^Map v)] [k v])))]
(walk/postwalk (fn [x] (if (map? x) (into {} (map f x)) x)) m)))

(defn ^:private ^Breadcrumb map->breadcrumb
(defn ^:private map->breadcrumb
"Converts a map into a Breadcrumb."
^Breadcrumb
[{:keys [type level message category data timestamp]}]
(let [breadcrumb (if timestamp
(Breadcrumb. ^Date timestamp)
(Breadcrumb.))]
(let [breadcrumb (if timestamp (Breadcrumb. ^Date timestamp) (Breadcrumb.))]
(when type
(.setType breadcrumb type))
(when level
Expand All @@ -51,8 +50,9 @@
(.setData breadcrumb k v)))
breadcrumb))

(defn ^:private ^User map->user
(defn ^:private map->user
"Converts a map into a User."
^User
[{:keys [email id username ip-address other]}]
(let [user (User.)]
(when email
Expand All @@ -67,8 +67,9 @@
(.setOthers user other))
user))

(defn ^:private ^Request map->request
(defn ^:private map->request
"Converts a map into a Request."
^Request
[{:keys [url method query-string data cookies headers env other]}]
(let [request (Request.)]
(when url
Expand All @@ -89,8 +90,9 @@
(.setOthers request (java-util-hashmappify-vals other)))
request))

(defn ^:private ^SentryEvent map->event
(defn ^:private map->event
"Converts a map into an event."
^SentryEvent
[{:keys [event-id message level release environment user request logger platform dist
tags breadcrumbs server-name extra fingerprints throwable transaction]}]
(let [sentry-event (SentryEvent. (DateUtils/getCurrentDateTime))
Expand Down Expand Up @@ -141,23 +143,26 @@
{:debug false
:environment "production"
:enable-uncaught-exception-handler true
:uncaught-handler-enabled true})
:uncaught-handler-enabled true
:serialization-max-depth 5}) ;; default to 5, adjust lower if a circular reference loop occurs.

(defn ^:private ^SentryOptions sentry-options
(defn ^:private sentry-options
^SentryOptions
[dsn config]
(let [{:keys [environment
debug
release
dist
server-name
shutdown-timeout
shutdown-timeout-millis
in-app-includes
in-app-excludes
ignored-exceptions-for-type
enable-uncaught-exception-handler ;; deprecated
uncaught-handler-enabled
before-send-fn
before-breadcrumb-fn
serialization-max-depth
traces-sample-rate
traces-sample-fn]} (merge sentry-defaults config)
sentry-options (SentryOptions.)]
Expand All @@ -166,6 +171,17 @@

(when environment
(.setEnvironment sentry-options environment))
;;
;; When serializing out an object, say a Throwable, sometimes it happens
;; that the serialization goes into a circular reference loop and just locks up
;;
;; Turning on `{:debug true}` when initializing Sentry should expose the issue on your logs
;;
;; If you experience this issue, try adjusting the maximum depth to a low
;; number, such as 2 and see if that works for you.
;;
(when serialization-max-depth
(.setMaxDepth sentry-options serialization-max-depth)) ;; defaults to 100 in the SDK, but we default it to 5.
(when debug
(.setDebug sentry-options debug)) ;; already set to `false` in the SDK.
(when release
Expand All @@ -174,8 +190,8 @@
(.setDist sentry-options dist))
(when server-name
(.setServerName sentry-options ^String server-name))
(when shutdown-timeout
(.setShutdownTimeout sentry-options shutdown-timeout)) ;; already set to 2000ms in the SDK
(when shutdown-timeout-millis
(.setShutdownTimeoutMillis sentry-options shutdown-timeout-millis)) ;; already set to 2000ms in the SDK
(doseq [in-app-include in-app-includes]
(.addInAppInclude sentry-options in-app-include))
(doseq [in-app-exclude in-app-excludes]
Expand Down Expand Up @@ -223,7 +239,7 @@
| `:release` | All events are assigned to a particular release |
| `:dist` | Set the application distribution that will be sent with each event |
| `:server-name` | Set the server name that will be sent with each event |
| `:shutdown-timeout` | Wait up to X milliseconds before shutdown if there are events to send | 2000ms
| `:shutdown-timeout-millis` | Wait up to X milliseconds before shutdown if there are events to send | 2000ms
| `:in-app-includes` | A seqable collection (vector for example) containing package names to include when sending events |
| `:in-app-excludes` | A seqable collection (vector for example) containing package names to ignore when sending events |
| `:ignored-exceptions-for-type | Set exceptions that will be filtered out before sending to Sentry (a set of Classnames as Strings) |
Expand All @@ -241,6 +257,7 @@
| | [More Information)(https://docs.sentry.io/platforms/java/enriching-events/context/) |
| `:traces-sample-rate` | Set a uniform sample rate(a number of between 0.0 and 1.0) for all transactions for tracing |
| `:traces-sample-fn` | A function (taking a custom sample context and a transaction context) enables you to control trace transactions |
| `:serialization-max-depth` | Set to a lower number, i.e., 2, if you experience circular reference errors when sending events | 5
Some examples:
Expand Down
8 changes: 4 additions & 4 deletions src/sentry_clj/ring.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
[sentry-clj.core :as sentry]
[sentry-clj.tracing :as st])
(:import
[io.sentry EventProcessor IHub Sentry SentryEvent SentryTraceHeader]
[io.sentry.protocol SentryTransaction Request]))
[io.sentry EventProcessor Hint IHub Sentry SentryEvent SentryTraceHeader]
[io.sentry.protocol Request SentryTransaction]))

(set! *warn-on-reflection* true)

Expand Down Expand Up @@ -105,12 +105,12 @@
[]
(reify EventProcessor
(^SentryEvent process
[_ ^SentryEvent event _]
[_ ^SentryEvent event ^Hint _hint]
(.setRuntime (.getContexts event) (compute-sentry-runtime))
event)

(^SentryTransaction process
[_ ^SentryTransaction tran _]
[_ ^SentryTransaction tran ^Hint _hint]
(.setRuntime (.getContexts tran) (compute-sentry-runtime))
tran)))

Expand Down
12 changes: 3 additions & 9 deletions src/sentry_clj/tracing.clj
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
(ns sentry-clj.tracing
(:import
[io.sentry
CustomSamplingContext
EventProcessor
Scope
Sentry
ITransaction
SpanStatus
TransactionContext]))
[io.sentry CustomSamplingContext EventProcessor ITransaction Scope Sentry SpanStatus TransactionContext]))

(def span-status
{:ok SpanStatus/OK
Expand All @@ -29,8 +22,9 @@
:data-loss SpanStatus/DATA_LOSS
:unauthenticated SpanStatus/UNAUTHENTICATED})

(defn ^CustomSamplingContext compute-custom-sampling-context
(defn compute-custom-sampling-context
"Compute a custom sampling context has key and info."
^CustomSamplingContext
[key info]
(let [csc (CustomSamplingContext.)]
(.set csc key info)
Expand Down
Loading

0 comments on commit 15dee99

Please sign in to comment.