-
Notifications
You must be signed in to change notification settings - Fork 2.6k
[otel-tracing] Added Tracing to Base package (driver) #4196
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
[otel-tracing] Added Tracing to Base package (driver) #4196
Conversation
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.
There is nothing about the instrumentation added to the filesystem driver in this PR which is specific to the filesystem driver. These spans should live in base.Base
so that all drivers can benefit. Feel free to rewrite dcontext.WithTrace
or throw it out; OpenTelemetry tracing is superior and could also be wired up to log traces to logrus.
@@ -28,6 +31,10 @@ const ( | |||
minThreads = uint64(25) | |||
) | |||
|
|||
// tracer is the OpenTelemetry tracer utilized for tracing operations within | |||
// this package's code. | |||
var tracer trace.Tracer |
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.
var tracer trace.Tracer | |
var tracer = otel.Tracer("github.com/distribution/distribution/v3/registry/storage/driver/filesystem") |
} | ||
ctx, span := tracer.Start( | ||
ctx, | ||
fmt.Sprintf("%s:%s", driverName, "GetContent"), |
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 wonder if the driver name would be better encoded as a span attribute than as part of the span name. It would require fewer string concatenations at runtime when the tracing logic is lifted into base.Base
, at least.
@@ -118,6 +126,15 @@ func (d *driver) Name() string { | |||
|
|||
// GetContent retrieves the content stored at "path" as a []byte. | |||
func (d *driver) GetContent(ctx context.Context, path string) ([]byte, error) { | |||
attrs := []attribute.KeyValue{ | |||
attribute.String("Path", path), |
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.
Hi @corhere , thx for your review.
You mentioned the possibility of replacing
If maintaining this format is important, I believe developing a On the other hand, using the stdouttrace exporter presents a challenge in preserving our current log structure. The stdouttrace exporter outputs the entire span as a pre-formatted string, typically in JSON, which might not easily allow for parsing specific fields. What are your thoughts on this? Would you prefer adherence to the current log format, or is there flexibility for change in the structure of our logs? |
It's a new major version, which gives us permission to make breaking changes. And I doubt anyone has written automation to parse the trace logs. If anyone has, I imagine they'd be thrilled to replace it with off-the-shelf OpenTelemetry tooling. I had also considered suggesting a custom What do you think @milosgajdos? |
Hi @corhere and @milosgajdos, I hope this message finds you well. I wanted to follow up on my PR. I've addressed the comments received and requested another review. Since there hasn't been any activity for the past few weeks, I'm reaching out to ensure that this PR hasn't been overlooked. If there are any additional changes or information needed from my side to move forward with the review process, please let me know. I'm eager to contribute and would appreciate any further guidance you can provide. Thanks in advance! |
Sorry, I'm currently on sabbatical only accessing GH from my phone from random locations around the world so won't be able to give much proper feedback for a while I'm afraid 😞 |
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.
The code itself looks good; it's just the span and attribute names which need some more attention.
registry/storage/driver/base/base.go
Outdated
} | ||
ctx, span := tracer.Start( | ||
ctx, | ||
"get_content", |
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.
The span name is not an attribute. The guidance is a little vague on the recommended format for span names in general, though it does mention the name of a function as an example choice of span name. I think we should name these spans after the function names exactly how they're spelled in code.
"get_content", | |
"GetContent", |
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.
Agreed, this was also on my mind. Utilizing the precise function names as span names significantly improves the clarity and consistency within our telemetry data. Moreover, it facilitates tracing by simplifying the process of correlating spans to the specific functions from which they originate.
registry/storage/driver/base/base.go
Outdated
attribute.String("driver.name", base.Name()), | ||
attribute.String("path", path), |
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.
For new names, perhaps io.cncf.distribution
would be a good choice of prefix?
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.
Done.
5b64082
to
d973883
Compare
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.
Almost there! And could you please squash down to a single commit so your PR branch is ready to merge?
registry/registry.go
Outdated
@@ -155,6 +155,7 @@ func NewRegistry(ctx context.Context, config *configuration.Configuration) (*Reg | |||
} | |||
|
|||
err = tracing.InitOpenTelemetry(app.Context) | |||
|
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.
Stray newline snuck into a file that is not otherwise touched by this PR.
registry/storage/driver/base/base.go
Outdated
attrs := []attribute.KeyValue{ | ||
attribute.String(tracing.AttributePrefix+"driver.name", base.Name()), | ||
attribute.String(tracing.AttributePrefix+"path", path), | ||
attribute.Int("content.length", len(content)), |
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 don't see an attribute with that name in the OTEL semantic conventions. Did you mean to prefix it with tracing.AttributePrefix
?
5f73866
to
f86fbdb
Compare
@corhere Done! Thank you for the reviews and guidance. |
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.
LGTM! 🎉
Thank you so much for working on tracing and putting up with all the review rounds. We really appreciate your efforts ❤️
ctx, done := dcontext.WithTrace(ctx) | ||
defer done("%s.GetContent(%q)", base.Name(), path) | ||
attrs := []attribute.KeyValue{ | ||
attribute.String(tracing.AttributePrefix+"storage.driver.name", base.Name()), |
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.
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.
Thanks for this, can you please make the go.mod
changes I've suggested? Then we're good to go.
go.mod
Outdated
@@ -82,10 +82,10 @@ require ( | |||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.21.0 // indirect | |||
go.opentelemetry.io/otel/exporters/prometheus v0.44.0 // indirect | |||
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v0.44.0 // indirect | |||
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.21.0 // indirect | |||
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.21.0 |
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.
Can you please move this direct dependency to the list of direct deps?
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.
Done.
go.mod
Outdated
go.opentelemetry.io/otel/metric v1.21.0 // indirect | ||
go.opentelemetry.io/otel/sdk/metric v1.21.0 // indirect | ||
go.opentelemetry.io/otel/trace v1.21.0 // indirect | ||
go.opentelemetry.io/otel/trace v1.21.0 |
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.
Same comment as above
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.
Done.
5e036fd
to
5a02422
<
E544
a href="/distribution/distribution/compare/5e036fdad8f89907c13df91b9fb20851d4f66f46..5a02422357882727845c76f148c656193dedcf9e" data-hydro-click="{"event_type":"force_push_timeline_diff.click","payload":{"pull_request_id":1649305233,"repository_id":28366058,"event_id":11996524526,"originating_url":"https://github.com/distribution/distribution/pull/4196","user_id":null}}" data-hydro-click-hmac="51721293d4643581204cc21e46459699a9e5e6a9dc2fa43381123b8172998a74" data-view-component="true" class="Button--invisible Button--small Button Button--invisible-noVisuals float-right ml-2">
Compare
Hi @milosgajdos , it's done. |
Thanks, one more thing, mind squashing @gotgelf ? |
Signed-off-by: gotgelf <gotgelf@gmail.com>
5fbedac
to
f690b3e
Compare
Of course, done. |
This PR introduces
OpenTelemetry
tracing capabilities into the base(storage driver) component.