Don't include fields from context that are not known by log schema

Put stacktraces in :trace under :error
parent 452332e9
......@@ -118,13 +118,14 @@ find there. If you are seeing some components not using `envelope`, try using
### Context
`Timbre`'s `with-context` is exposed as a top-level symbol in `Envelope`. Any
fields on the context map will converted to camel case and included in the log
entry when using ELK format logging. You will need to make sure that any value
you put in the context map is a legal value according to the NSD ELK schema when
using ELK format logging.
fields present in the NSD ELK schema and in the context map will converted to
camel case and included in the log entry when using ELK format logging. Please
note that there is not schema validation done on the context *values*.
The default non-elk (console) format will print the x-request-id field from the
context when present. Consider the following:
context when present and ignore any other context values.
Consider the following:
```clojure
(ns no.nsd.your-app
......
(defproject no.nsd/envelope "0.1.5"
(defproject no.nsd/envelope "0.1.6"
:description "A thin wrapper around taoensso.timbre with built in settings for logging to NSD's ELK stack"
:url "https://gitlab.nsd.no/clojure/envelope"
:license {:name "Eclipse Public License"
......
......@@ -29,10 +29,36 @@
(assoc :serviceStack (force (:service-stack config)))
?err
(assoc :err (timbre/stacktrace ?err {:stacktrace-fonts {}})))]
(json/write-str (reduce #(assoc %1 (->camelCase %2) (get context %2))
output-data
(keys context)))))
(assoc :error {:stack (timbre/stacktrace ?err {:stacktrace-fonts {}})}))]
(json/write-str (select-keys (reduce #(assoc %1 (->camelCase %2) (get context %2))
output-data
(keys context))
["@timestamp"
:serviceName
:serviceVersion
:schemaVersion
:levelName
:message
:serviceStack
:xRequestId
:thread
:process
:file
:line
:userId
:loggerName
:tags
:host
:port
:data
:url
:responseTime
:statusCode
:method
:error
:request
:response]))))
(defn local-console-format-fn [data]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment