-
Notifications
You must be signed in to change notification settings - Fork 344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(tracing): improved tracing for persisters and requests #878
Conversation
@@ -41,6 +41,9 @@ func (RelationTuple) TableName(_ context.Context) string { | |||
} | |||
|
|||
func (r *RelationTuple) toInternal(ctx context.Context, nm namespace.Manager, p *Persister) (*relationtuple.InternalRelationTuple, error) { | |||
ctx, span := p.d.Tracer(ctx).Tracer().Start(ctx, "persistence.sql.toInternal") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that we are repeating the package and function name in this and other functions. I wonder if it would make sense to ask the runtime for that information instead, so that this information does not get out-of-sync in case we rename or move the functions. WDYT?
func spanNameOfCurrentFunction() string {
pc, _, _, ok := runtime.Caller(0)
if !ok {
return "unknown"
}
if f := runtime.FuncForPC(pc); f != nil {
return f.Name()
}
return "unknown"
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nifty, but am I using it correctly? (Looks to be returning its own name): https://go.dev/play/p/Aa0yIFb3cjq
I remember experimenting with this idea previously, this was my PoC:
func spanName() {
pc := make([]uintptr, 15)
n := runtime.Callers(2, pc)
frames := runtime.CallersFrames(pc[:n])
frame, _ := frames.Next()
fmt.Println(frame.Function)
}
// Prints:
// module/package.Foo
Perhaps I'll create a separate PR for it (should be in ory/x anyway).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, it should be runtime.Caller(1)
in your example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, just some minor questions.
Is there maybe a linter we can use to ensure the span name and function name are consistent?
This patch introduces tracing for persisters and requests.
Checklist
introduces a new feature.
contributing code guidelines.
vulnerability. If this pull request addresses a security. vulnerability, I
confirm that I got green light (please contact
[email protected]) from the maintainers to push
the changes.
works.