Open dolmen opened 1 year ago
Cc: @mknyszek
What about Helper(int) to specify how many levels to skip?
To keep traceback costs (the dominating cost) low, Helper
would probably be implemented as a trace event that marks a function by name, and the filtering could be applied lazily in the trace parser.
But I also wonder if we could just do something to make the runtime/trace
region API more ergonomic to begin with. I'm not certain generics are powerful enough to cover every case. One possible approach could be to annotate a function (e.g. //go:traceRegion <regionType>
) and have the compiler generate a wrapper (which is a fairly straightforward transformation) assuming the first argument is a context.Context
. Though, I'm not sure we'd want to add more special annotations of this form.
Just thinking out loud; this needs more thought.
Add an
Helper()
function to allow clients of theruntime/trace
region API to create helpers but hide them from the stack traces. The API would be similar totesting.Helper()
.Use case
The region API (
trace.WithRegion
,trace.StartRegion
) is quite intrusive: to enhance existing code with regions, one must wrap the existing block in afunc()
. It is even more verbose if the existing block returned values to use after the block (ex: error).To limit the verbosity, I used generics to write wrappers around the
trace.StartRegion
API (see below).Unfortunately, with Go 1.20 the
go tool trace
output shows the helper function as the encapsulated code instead of the real user's code. This makes the tracing annotations much less useful.It would be helpful to have a way to declare a caller of the
trace.StartRegion
as an helper. Thetesting
package hasHelper()
which would be a good inspiration (but a different API might be needed asruntime/trace
performance is critical).Example helpers
Example wrappers in user code that would be declared as helpers: