Skip to content

Commit

Permalink
Update Sentry Java SDK to 6.28.0
Browse files Browse the repository at this point in the history
Add the ability to enable or disable Sentry via the `enabled` key (defaults to true)
Allow for a single-arity to sentry-options (which then uses the default values)

-=david=-
  • Loading branch information
dharrigan committed Aug 5, 2023
1 parent d90af71 commit e239928
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 101 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.md
Expand Up @@ -10,9 +10,15 @@ 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.

## [6.28.200]

- Update Sentry Java SDK to 6.28.0
- Add the ability to enable or disable Sentry via the `enabled` key (defaults to true)
- Allow for a single-arity to sentry-options (which then uses the default values)

## [6.26.199]

- Update Sentry Java SDK to 6.24.0
- Update Sentry Java SDK to 6.26.0

## [6.24.198]

Expand Down Expand Up @@ -361,7 +367,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/6.26.199...HEAD
[Unreleased]: https://github.com/getsentry/sentry-clj/compare/6.28.200...HEAD
[6.28.200]: https://github.com/getsentry/sentry-clj/compare/6.26.199...6.28.200
[6.26.199]: https://github.com/getsentry/sentry-clj/compare/6.24.198...6.26.199
[6.24.198]: https://github.com/getsentry/sentry-clj/compare/6.21.196...6.24.198
[6.21.196]: https://github.com/getsentry/sentry-clj/compare/6.19.195...6.21.196
Expand Down
2 changes: 1 addition & 1 deletion deps.edn
Expand Up @@ -4,7 +4,7 @@
;;
;;
;;
io.sentry/sentry {:mvn/version "6.26.0"}
io.sentry/sentry {:mvn/version "6.28.0"}
ring/ring-core {:mvn/version "1.10.0"}}

:aliases {:build {:deps {io.github.seancorfield/build-clj {:git/tag "v0.9.2"
Expand Down
4 changes: 2 additions & 2 deletions examples/basic/deps.edn
Expand Up @@ -4,8 +4,8 @@
;;
;;
;;
ch.qos.logback/logback-classic {:mvn/version "1.4.8"}
io.sentry/sentry {:mvn/version "6.26.0"}
ch.qos.logback/logback-classic {:mvn/version "1.4.9"}
io.sentry/sentry {:mvn/version "6.28.0"}
io.sentry/sentry-clj {:local/root "../../../sentry-clj"}
org.clojure/tools.cli {:mvn/version "1.0.219"}
org.clojure/tools.logging {:mvn/version "1.2.4"}
Expand Down
4 changes: 2 additions & 2 deletions examples/ring_with_tracing/deps.edn
Expand Up @@ -4,10 +4,10 @@
;;
;;
;;
ch.qos.logback/logback-classic {:mvn/version "1.4.8"}
ch.qos.logback/logback-classic {:mvn/version "1.4.9"}
integrant/integrant {:mvn/version "0.8.1"}
integrant/repl {:mvn/version "0.3.3"}
io.sentry/sentry {:mvn/version "6.26.0"}
io.sentry/sentry {:mvn/version "6.28.0"}
io.sentry/sentry-clj {:local/root "../../../sentry-clj"}
org.clojure/tools.cli {:mvn/version "1.0.219"}
org.clojure/tools.logging {:mvn/version "1.2.4"}
Expand Down
4 changes: 2 additions & 2 deletions examples/uncaught/deps.edn
Expand Up @@ -4,8 +4,8 @@
;;
;;
;;
ch.qos.logback/logback-classic {:mvn/version "1.4.8"}
io.sentry/sentry {:mvn/version "6.26.0"}
ch.qos.logback/logback-classic {:mvn/version "1.4.9"}
io.sentry/sentry {:mvn/version "6.28.0"}
io.sentry/sentry-clj {:local/root "../../../sentry-clj"}
org.clojure/tools.cli {:mvn/version "1.0.219"}
org.clojure/tools.logging {:mvn/version "1.2.4"}
Expand Down
2 changes: 1 addition & 1 deletion scripts/build.clj
Expand Up @@ -3,7 +3,7 @@
[clojure.tools.build.api :as b]
[org.corfield.build :as bb]))

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

(defn run-tests
Expand Down
183 changes: 95 additions & 88 deletions src/sentry_clj/core.clj
Expand Up @@ -144,100 +144,106 @@
:debug false ;; Java SDK default
:enable-uncaught-exception-handler true ;; Java SDK default
:trace-options-requests true ;; Java SDK default
:serialization-max-depth 5}) ;; default to 5, adjust lower if a circular reference loop occurs.
:serialization-max-depth 5 ;; default to 5, adjust lower if a circular reference loop occurs.
:enabled true})

(defn ^:private sentry-options
^SentryOptions
[dsn config]
(let [{:keys [environment
debug
logger
diagnostic-level
release
dist
server-name
shutdown-timeout-millis
in-app-includes
in-app-excludes
ignored-exceptions-for-type
enable-uncaught-exception-handler
before-send-fn
before-breadcrumb-fn
serialization-max-depth
traces-sample-rate
traces-sample-fn
trace-options-requests
instrumenter
event-processors]} (merge sentry-defaults config)
sentry-options (SentryOptions.)]
([dsn] (sentry-options dsn {}))
([dsn config]
(let [{:keys [environment
debug
logger
diagnostic-level
release
dist
server-name
shutdown-timeout-millis
in-app-includes
in-app-excludes
ignored-exceptions-for-type
enable-uncaught-exception-handler
before-send-fn
before-breadcrumb-fn
serialization-max-depth
traces-sample-rate
traces-sample-fn
trace-options-requests
instrumenter
event-processors
enabled]} (merge sentry-defaults config)
sentry-options (SentryOptions.)]

(.setDsn sentry-options dsn)
(.setDsn sentry-options dsn)

(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 release
(.setRelease sentry-options release))
(when dist
(.setDist sentry-options dist))
(when server-name
(.setServerName sentry-options ^String server-name))
(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]
(.addInAppExclude sentry-options in-app-exclude))
(doseq [ignored-exception-for-type ignored-exceptions-for-type]
(try
(let [clazz (Class/forName ignored-exception-for-type)]
(when (isa? clazz Throwable)
(.addIgnoredExceptionForType sentry-options ^Throwable clazz)))
(catch Exception _))) ; just ignore it.
(when before-send-fn
(.setBeforeSend sentry-options ^SentryEvent
(reify io.sentry.SentryOptions$BeforeSendCallback
(execute [_ event hint]
(before-send-fn event hint)))))
(when before-breadcrumb-fn
(.setBeforeBreadcrumb sentry-options ^Breadcrumb
(reify io.sentry.SentryOptions$BeforeBreadcrumbCallback
(execute [_ breadcrumb hint]
(before-breadcrumb-fn breadcrumb hint)))))
(when traces-sample-rate
(.setTracesSampleRate sentry-options traces-sample-rate))
(when traces-sample-fn
(.setTracesSampler sentry-options ^io.sentry.SentryOptions$TracesSamplerCallback
(reify io.sentry.SentryOptions$TracesSamplerCallback
(sample [_ ctx]
(traces-sample-fn {:custom-sample-context (-> ctx
.getCustomSamplingContext
.getData)
:transaction-context (.getTransactionContext ctx)})))))
(when-let [instrumenter (case instrumenter
:sentry Instrumenter/SENTRY
:otel Instrumenter/OTEL
nil)]
(.setInstrumenter sentry-options ^Instrumenter instrumenter))
(doseq [event-processor event-processors]
(.addEventProcessor sentry-options ^EventProcessor event-processor))
(.setDebug sentry-options debug)
(.setLogger sentry-options logger)
(.setDiagnosticLevel sentry-options (keyword->level diagnostic-level))
(.setTraceOptionsRequests sentry-options trace-options-requests)
(.setEnableUncaughtExceptionHandler sentry-options enable-uncaught-exception-handler)
(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 release
(.setRelease sentry-options release))
(when dist
(.setDist sentry-options dist))
(when server-name
(.setServerName sentry-options ^String server-name))
(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]
(.addInAppExclude sentry-options in-app-exclude))
(doseq [ignored-exception-for-type ignored-exceptions-for-type]
(try
(let [clazz (Class/forName ignored-exception-for-type)]
(when (isa? clazz Throwable)
(.addIgnoredExceptionForType sentry-options ^Throwable clazz)))
(catch Exception _))) ; just ignore it.
(when before-send-fn
(.setBeforeSend sentry-options ^SentryEvent
(reify io.sentry.SentryOptions$BeforeSendCallback
(execute [_ event hint]
(before-send-fn event hint)))))
(when before-breadcrumb-fn
(.setBeforeBreadcrumb sentry-options ^Breadcrumb
(reify io.sentry.SentryOptions$BeforeBreadcrumbCallback
(execute [_ breadcrumb hint]
(before-breadcrumb-fn breadcrumb hint)))))
(when traces-sample-rate
(.setTracesSampleRate sentry-options traces-sample-rate))
(when traces-sample-fn
(.setTracesSampler sentry-options ^io.sentry.SentryOptions$TracesSamplerCallback
(reify io.sentry.SentryOptions$TracesSamplerCallback
(sample [_ ctx]
(traces-sample-fn {:custom-sample-context (-> ctx
.getCustomSamplingContext
.getData)
:transaction-context (.getTransactionContext ctx)})))))
(when-let [instrumenter (case instrumenter
:sentry Instrumenter/SENTRY
:otel Instrumenter/OTEL
nil)]
(.setInstrumenter sentry-options ^Instrumenter instrumenter))

(doseq [event-processor event-processors]
(.addEventProcessor sentry-options ^EventProcessor event-processor))

(.setDebug sentry-options debug)
(.setLogger sentry-options logger)
(.setDiagnosticLevel sentry-options (keyword->level diagnostic-level))
(.setTraceOptionsRequests sentry-options trace-options-requests)
(.setEnableUncaughtExceptionHandler sentry-options enable-uncaught-exception-handler)
(.setEnabled sentry-options enabled)

sentry-options))
sentry-options)))

#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn init!
Expand All @@ -248,6 +254,7 @@
| key | description | default
| ------------------------------------ | ------------------------------------------------------------------------------------------------------------------ | -------
| `:environment` | Set the environment on which Sentry events will be logged, e.g., \"production\" | production
| `:enabled` | Enable or disable sentry. | true
| `:debug` | Enable SDK logging at the debug level | false
| `:logger` | Instance of `io.sentry.ILogger` (only applies when `:debug` is on) | `io.sentry.SystemOutLogger`
| `:diagnostic-level` | Log messages at or above this level (only applies when `:debug` is on) | `:debug`
Expand Down
21 changes: 18 additions & 3 deletions test/sentry_clj/core_test.clj
Expand Up @@ -307,8 +307,8 @@
:enable-uncaught-exception-handler false
:trace-options-requests false
:instrumenter :otel
:event-processors [(SomeEventProcessor.)]})]
(println (.getEventProcessors sentry-options))
:event-processors [(SomeEventProcessor.)]
:enabled false})]
(expect "http://www.example.com" (.getDsn sentry-options))
(expect "production" (.getEnvironment sentry-options))
(expect "1.1" (.getRelease sentry-options))
Expand All @@ -325,4 +325,19 @@
(expect false (.isEnableUncaughtExceptionHandler sentry-options))
(expect false (.isTraceOptionsRequests sentry-options))
(expect Instrumenter/OTEL (.getInstrumenter sentry-options))
(expect (instance? SomeEventProcessor (last (.getEventProcessors sentry-options)))))))
(expect (instance? SomeEventProcessor (last (.getEventProcessors sentry-options))))
(expect false (.isEnabled sentry-options)))))

(defexpect sentry-enabled-tests
(expecting
"sentry is enabled by default"
(let [sentry-options ^SentryOptions (sentry-options "http://www.example.com")]
(expect true (.isEnabled sentry-options))))
(expecting
"sentry is enabled"
(let [sentry-options ^SentryOptions (sentry-options "http://www.example.com" {:enabled true})]
(expect true (.isEnabled sentry-options))))
(expecting
"sentry is disabled"
(let [sentry-options ^SentryOptions (sentry-options "http://www.example.com" {:enabled false})]
(expect false (.isEnabled sentry-options)))))

0 comments on commit e239928

Please sign in to comment.