Skip to content

Commit f67aaf6

Browse files
Add documentation for logs to README (#75)
* Add documentation for logs to README * Add docs for logback and all log level functions * Fix logs readme formatting * Fix options examples with logs * Fix generic log params description
1 parent 9cea5f7 commit f67aaf6

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

README.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ If you want an interpolated message, you need to provide the full map, i.e.,
8282
| | [More Information](https://docs.sentry.io/platforms/java/enriching-events/context/) |
8383
| `:traces-sample-rate` | Set a uniform sample rate(a number of between 0.0 and 1.0) for all transactions for tracing |
8484
| `:traces-sample-fn` | A function (taking a custom sample context and a transaction context) enables you to control trace transactions |
85+
| `:logs-enabled` | Enable Sentry structured logging integration | false
86+
| `:before-send-log-fn` | A function (taking a log event) to filter logs, or update them before they are sent to Sentry |
8587
| `:serialization-max-depth` | Set to a lower number, i.e., 2, if you experience circular reference errors when sending events | 5
8688
| `:trace-options-requests` | Set to enable or disable tracing of options requests. |true
8789
| `:instrumenter` | Sets instrumenter for tracing. (values - :sentry - for default Sentry instrumentation, :otel - OpenTelemetry instrumentation) | :sentry
@@ -113,6 +115,14 @@ Initialisation with additional options:
113115
(sentry/init! "https://public:[email protected]/1" {:contexts {:foo "bar" :baz "wibble"}})
114116
```
115117

118+
```clojure
119+
(sentry/init! "http://abcdefg@localhost:19000/2" {:logs-enabled true})
120+
```
121+
122+
```clojure
123+
(sentry/init! "http://abcdefg@localhost:19000/2" {:logs-enabled true :before-send-log-fn (fn [logEvent] (.setBody logEvent "new message body") logEvent)})
124+
```
125+
116126
## Supported event keys
117127

118128
[API Documentation](https://develop.sentry.dev/sdk/event-payloads/)
@@ -191,6 +201,101 @@ Each key is optional.
191201
- `:env` - A map containing key/value pairs of `Strings`, i.e., `{"a" "b" "c" "d"}`
192202
- `:other` - A map containing key/value pairs of `Strings`, i.e., `{"a" "b" "c" "d"}`
193203

204+
## Logs
205+
[API Documentation](https://docs.sentry.io/platforms/java/logs/)
206+
207+
### Usage example
208+
209+
```clojure
210+
(require '[sentry-clj.core :as sentry])
211+
(require '[sentry-clj.logging :as sentry-log])
212+
(import '[io.sentry SentryInstantDate])
213+
214+
(sentry/init! "https://public:[email protected]/1" {:logs-enabled true})
215+
216+
; Sending some logs using log level specific functions
217+
218+
(sentry-log/info "Test message")
219+
(sentry-log/warn "Test message: %s" "TEST")
220+
221+
; Sending generic logs with additional parameters
222+
223+
(sentry-log/log :info {:request-id "24dbaef3-1d75-4304-8dde-e8cd47212591"} "Generic log")
224+
(sentry-log/log :error {:operation "checkout"} "Generic %s log" "ERROR")
225+
(sentry-log/log :warn (SentryInstantDate.) "Delayed processing detected at %s" (System/currentTimeMillis))
226+
```
227+
228+
### Log levels
229+
230+
Level-specific logging functions that provide a convenient way to log messages at specific levels. Each function accepts a message string and optional format arguments.
231+
232+
- `trace` - Log at trace level
233+
- `debug` - Log at debug level
234+
- `info` - Log at info level
235+
- `warn` - Log at warning level
236+
- `error` - Log at error level
237+
- `fatal` - Log at fatal level
238+
239+
All level-specific functions accept the same parameters as `(info message arg1 arg2)`:
240+
- `message` - A `String` containing the log message, optionally with format placeholders
241+
- `& args` - Optional format arguments for message interpolation
242+
243+
### Generic log
244+
245+
The `log` function provides flexible logging with support for structured attributes and custom timestamps. It accepts a log level keyword followed by various argument combinations.
246+
247+
**Parameters:**
248+
- `level` - A `keyword` specifying the log level (`:trace`, `:debug`, `:info`, `:warn`, `:error`, `:fatal`)
249+
- `data` - Optional `map` of attributes or `SentryDate`, to add structured data to the log entry
250+
- `message` - A `String` containing the log message, optionally with format placeholders
251+
- `& args` - Optional format arguments for message interpolation
252+
253+
### Using with Logback
254+
255+
[API Documentation](https://docs.sentry.io/platforms/java/guides/logback/logs/)
256+
257+
If you are using Logback, you can add the Sentry appender to your logback configuration and include the `io.sentry/sentry-logback {:mvn/version "RELEASE"}` library in your `deps.edn`.
258+
259+
**Two configuration approaches:**
260+
261+
1. **With `sentry/init!` in your application**: If you initialize Sentry in your app using `sentry/init!`, you don't need to specify a DSN in the logback configuration.
262+
263+
```xml
264+
<configuration scan="true" scanPeriod="5 seconds">
265+
...
266+
<appender name="Sentry" class="io.sentry.logback.SentryAppender">
267+
<options>
268+
<sendDefaultPii>true</sendDefaultPii>
269+
</options>
270+
<!-- Optionally change minimum Event level. Default for Events is ERROR -->
271+
<minimumEventLevel>WARN</minimumEventLevel>
272+
<!-- Optionally change minimum Breadcrumbs level. Default for Breadcrumbs is INFO -->
273+
<minimumBreadcrumbLevel>DEBUG</minimumBreadcrumbLevel>
274+
<!-- Optionally change minimum Log level. Default for Log Events is INFO -->
275+
<minimumLevel>INFO</minimumLevel>
276+
</appender>
277+
...
278+
</configuration>
279+
```
280+
281+
2. **Standalone logback configuration**: If you don't start Sentry in your app at all, you can add `<dsn>${SENTRY_DSN}</dsn>` and logs configuration to the Sentry appender options. Logs will be sent to Sentry automatically, and error logs will become error events.
282+
283+
```xml
284+
<configuration scan="true" scanPeriod="5 seconds">
285+
...
286+
<appender name="Sentry" class="io.sentry.logback.SentryAppender">
287+
<options>
288+
<dsn>${SENTRY_DSN}</dsn>
289+
<logs>
290+
<enabled>true</enabled>
291+
</logs>
292+
<sendDefaultPii>true</sendDefaultPii>
293+
</options>
294+
</appender>
295+
...
296+
</configuration>
297+
```
298+
194299
## License
195300

196301
Copyright © 2022 Coda Hale, Sentry

0 commit comments

Comments
 (0)