Open 2food opened 9 months ago
Hi @2food
thanks for reporting this, and apologies for the delay. I was traveling when you submitted this issue and I missed it on my return.
Please note that the API for capture
clearly states that it should return a map
The capture function is a function which takes one argument, the result of the evaluation and returns a map of key-value pairs which need to be added to the trace.
So I consider this a misuse of the API.
However, I will investigate the nested missing logs and maybe add a more explicit error.
Hi,
I often use trace with
:capture identity
like this:Which is nice, because you get whatever the result of the body was in the trace log. However, I just discovered that if the body returns a single value, rather than a map (or coll). The trace silently fails to log anything. So this:
Will not log anything. And, additionally, any logs nested inside the trace will also fail. So this:
Does not log anything, and does not throw an error either. Even if the `µ/log' happens deeper down in the call-stack of the body.
I think this behavior is quite unfortunate. If returning a non-map value in the capture function is invalid, it should throw an error, or log one, or maybe write the log without the captured value, or something else. But failing silently is not good.
Of course, the simple workaround would be to always wrap the returned value in a map, like this:
And I see that the doc for
µ/trace
does specify that the capture fn should return a map, but people don't always read the docs :smile: And even when they do, mistakes still happen.