bracesdev / errtrace

An alternative to stack traces for your Go errors
https://pkg.go.dev/braces.dev/errtrace
BSD 3-Clause "New" or "Revised" License
709 stars 10 forks source link

Support key-value annotations on wrap #36

Open abhinav opened 7 months ago

abhinav commented 7 months ago

Based on @prashantv's suggestions. In the future, we should consider adding support for errtrace.Wrap to include key-value pairs as part of wrapping. These values can be shown next to the function call in the trace, e.g.

example.com/main.getUser name="foo"
    path/to/file:42

The API for this is undecided at this time.

akshayjshah commented 7 months ago

Is it reasonable to use slog fields for this, or would we want to design our own API for key-value pairs?

abhinav commented 7 months ago

This was a bit fuzzy in terms of details, but re-using slog fields was one of the options I was considering. I'm keeping this as a low priority item, though, so as not to increase scope of this project at this time.

StevenACoffman commented 2 months ago

cockroachdb/errors has a ton of useful functionality... but is a very heavyweight and complicated library.

In #106 I added an interface so that the main value proposition of this library is composable with external custom error types.

I hope that allows this particular project to maintain a tighter focus.

abhinav commented 2 months ago

@StevenACoffman Agreed! We're hoping to keep this library lightweight and focused, and not turn it into a general "error utils" library.

Whether this feature goes into this library is still up for discussion, and it would have to be lightweight and composable (similarly to #106) if it did. An argument can be made that this is a logging-specific concern and it should go in a logerr package; nothing about this in set in stone at this time.