On Mittwoch, 15. Juni 2022 06:34:41 CEST Tamas (onetom) Herman wrote:
> What's the purpose of specifying a custom name?
> Is it just about stacktrace readability, or are there any other benefits
Easier-to-read stacktraces are the only benefit I know of.
> I do use such facility in high-order functions, like middlewares, for the
> exact same reason.
I use it when converting my structured log data into the format required by my
logging library (OpenTelemetry SDK):
(defmulti put-attribute-kv (fn [_ _ v]
(if-let [t (and (instance? List v)
(defmethod put-attribute-kv Keyword keyword-attribute [b k v]
(.put ^AttributesBuilder b (AttributeKey/stringKey (name k)) (name v)))
(defmethod put-attribute-kv String string-attribute [b k v]
(.put ^AttributesBuilder b (AttributeKey/stringKey (name k)) v))
(defn map->Attributes ^Attributes [m]
^AttributesBuilder (reduce-kv put-attribute-kv
In my case I could also determine which implementation the exception comes
from by looking at line numbers, but having the name in the stacktrace makes
it quite a bit more convenient.