This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-03-11
Channels
- # announcements (15)
- # aws (11)
- # babashka (13)
- # babashka-sci-dev (2)
- # beginners (63)
- # calva (20)
- # cider (9)
- # clj-kondo (27)
- # clojars (3)
- # clojure (34)
- # clojure-art (4)
- # clojure-europe (21)
- # clojure-filipino (1)
- # clojure-indonesia (1)
- # clojure-my (1)
- # clojure-nl (11)
- # clojure-norway (10)
- # clojure-sg (1)
- # clojure-spec (4)
- # clojure-uk (4)
- # clojurescript (5)
- # cursive (8)
- # deps-new (2)
- # events (1)
- # exercism (2)
- # fulcro (44)
- # graphql (6)
- # gratitude (1)
- # introduce-yourself (1)
- # jobs (3)
- # leiningen (5)
- # lsp (26)
- # membrane (18)
- # missionary (9)
- # off-topic (1)
- # pedestal (5)
- # portal (1)
- # quil (24)
- # re-frame (17)
- # reagent (5)
- # remote-jobs (2)
- # reveal (3)
- # spacemacs (4)
- # tools-build (1)
- # tools-deps (12)
hey all, what's the best way to set the *mdc-context*
so that the value is reflect in every interceptor in the chain? basically i would like to set some metadata at the start of a request, so that logging in the rest of the interceptors in the chain have this metadata.
Not sure about that particular dynvar, but if an interceptor returns a context with :bindings , they will be active through further interceptors http://pedestal.io/reference/context-map
I'm also trying to manipulate the *mdc-context*
via an interceptor, in order to set a correlation-id per request.
I tried binding *mdc-context*
to something using pedestal's :bindings
but found it wasn't enough to actually get the new context to register.
After some debugging I realized that one still needs to "install" the new context in the MDC.
I'm thinking something like this will do the trick:
{:name ::cid
:enter (fn [context]
(let [new-mdc-context (merge .... io.pedestal.log/*mdc-context*)]
(io.pedestal.log/-put-mdc (MDC/getMDCAdapter)
io.pedestal.log/mdc-context-key
(pr-str (dissoc new-mdc-context
:io.pedestal.log/formatter
:io.pedestal.log/mdc)))
(-> context
(update context
:bindings
assoc
#'io.pedestal.log/*mdc-context*
new-mdc-context)
(assoc ::old-mdc-context io.pedestal.log/*mdc-context*))))
:leave (fn [context]
(when-let [old-mdc-context (::old-mdc-context context)]
;; go back to old MDC
(io.pedestal.log/-put-mdc (MDC/getMDCAdapter)
io.pedestal.log/mdc-context-key
(pr-str (dissoc old-mdc-context
:io.pedestal.log/formatter
:io.pedestal.log/mdc))))
context)}
wanted to share if that helps others with similar issue