|
37 | 37 | ;; pass a context map to add structured data to the message |
38 | 38 | (log/info "hi!" {:foo "bar" :baz "qux"}) |
39 | 39 |
|
40 | | -;; context can be set |
| 40 | +;; context can be set |
41 | 41 | (log/with-context {:action "vibe-check"} |
42 | 42 | (log/debug "checking the vibes") |
43 | 43 | (let [are-you-ok? (do-the-vibe-check)] |
@@ -70,7 +70,7 @@ Second part of ensuring that right things are logged and we keep a good performa |
70 | 70 |
|
71 | 71 | ### How does it work? |
72 | 72 |
|
73 | | -Mokujin wraps `clojure.tools.logging` and injects SLF4J's MDC into logging events, if provided. |
| 73 | +Mokujin wraps `clojure.tools.logging` and injects SLF4J's MDC into logging events, if provided. |
74 | 74 | Keep in mind that `infof` (and friends) variants are present, but do not support passing the MDC (more on that later). |
75 | 75 |
|
76 | 76 |
|
@@ -138,7 +138,7 @@ Second difference is that only 1- and 2-arity (or in case of `log/error` 3-arity |
138 | 138 | (log/info "hello" "there" "world") |
139 | 139 | ``` |
140 | 140 |
|
141 | | -To help with migration and good log hygine Mokujin ships with custom hooks for `clj-kondo` and |
| 141 | +To help with migration and good log hygine Mokujin ships with custom hooks for `clj-kondo` and |
142 | 142 | report warnings in case of suspicious or incompatible call styles are detected. |
143 | 143 |
|
144 | 144 |
|
@@ -271,6 +271,32 @@ This way we can delegate things like redacting MDC or async appenders to Logback |
271 | 271 |
|
272 | 272 | Check `:mokujin.logback/json-async` configuration preset for a good example of how to set up async appenders with MDC support. |
273 | 273 |
|
| 274 | + |
| 275 | +#### Open Telemetry |
| 276 | + |
| 277 | + |
| 278 | +Open Telemetry supports automatic instrumentation of logging frameworks including Logback. To enable it, you need to: |
| 279 | + |
| 280 | +- start your application with the Open Telemetry Java agent |
| 281 | +- ensure that following environement variables are set: |
| 282 | + |
| 283 | +``` |
| 284 | +export OTEL_INSTRUMENTATION_LOGBACK_APPENDER_EXPERIMENTAL_CAPTURE_LOGGER_CONTEXT_ATTRIBUTES=true |
| 285 | +export OTEL_INSTRUMENTATION_LOGBACK_APPENDER_EXPERIMENTAL_CAPTURE_MDC_ATTRIBUTES=* |
| 286 | +``` |
| 287 | + |
| 288 | +alternatively, you can set these properties via JVM options: |
| 289 | + |
| 290 | +``` |
| 291 | +-Dotel.instrumentation.logback.appender.experimental.capture.logger.context.attributes=true |
| 292 | +-Dotel.instrumentation.logback.appender.experimental.capture.mdc.attributes=* |
| 293 | +``` |
| 294 | + |
| 295 | + |
| 296 | +From there, Open Telemetry will automatically capture MDC attributes and attach them to spans, inject trace IDs etc. |
| 297 | + |
| 298 | + |
| 299 | + |
274 | 300 | ## TODO |
275 | 301 |
|
276 | 302 | - [x] Maven release |
|
0 commit comments