Support "start" utility functions
Crocmagnon opened this issue · 6 comments
Describe the solution you'd like
Currently, it seems like spancheck
only looks for Start
methods called directly on the otel
package. It would be nice to be able to add custom start methods or packages.
Additional context
My company internally provides common tooling around tracing. One of these tools is a function to start a span. It's basically a thin wrapper around otel.Tracer("name").Start(ctx, name, opts...)
. Its implementation could be summarized as such:
package tracing
func Start(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span) {
return otel.Tracer("some-name").Start(ctx, name, opts...)
}
It's used like this:
ctx, span := tracing.Start(ctx, "spanName")
defer span.End()
These calls aren't detected by spancheck
@Crocmagnon this makes sense to me, and it's an oversight that I didn't think of this (which is only because I usually just use the tracer directly, as you said).
I'll noodle on this and try to support what you describe when I get a second. My first thought is another list of function signatures, like the ignore check, that would signal span creation
That's what I had in mind too, I believe it would make sense.
Related to this, it'd probably make sense to not run the linters within these start methods, eg of a false-positive here: https://github.com/ava-labs/avalanchego/pull/2714/files#diff-96ac4ca52daed5d45c9d309bb2f34ba18bb819beeda7c6a92bbd3962a2ab893c
Awesome! 👏🏻
Quick question: does the current implementation support methods, and if so what’s the configuration syntax?
I don’t have a use case for this, I just wondered while reading the documentation. If methods aren’t supported, maybe we could state that in the readme?
Awesome! 👏🏻 Quick question: does the current implementation support methods, and if so what’s the configuration syntax? I don’t have a use case for this, I just wondered while reading the documentation. If methods aren’t supported, maybe we could state that in the readme?
You need to adjust the regex to account for the receiver, so if we take the example from the readme (github.com/user/repo/telemetry/trace.Start:opentelemetry
), we can match on a method named Start
in the telemetry.tracing.TracingStruct
struct as follows: \(\*github.com/user/repo/telemetry/tracing/TracingStruct\).Start:opentelemetry
Cool! 🔥