Skip to content
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(storage): trace span covers life of a Reader #8390

Merged
merged 3 commits into from
Aug 10, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions storage/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ func (o *ObjectHandle) NewReader(ctx context.Context) (*Reader, error) {
// that file will be served back whole, regardless of the requested range as
// Google Cloud Storage dictates.
func (o *ObjectHandle) NewRangeReader(ctx context.Context, offset, length int64) (r *Reader, err error) {
ctx = trace.StartSpan(ctx, "cloud.google.com/go/storage.Object.NewRangeReader")
defer func() { trace.EndSpan(ctx, err) }()
// This span covers the life of the reader. It is closed via the context
// in Reader.Close.
ctx = trace.StartSpan(ctx, "cloud.google.com/go/storage.Object.Reader")

if err := o.validate(); err != nil {
return nil, err
Expand Down Expand Up @@ -116,6 +117,7 @@ func (o *ObjectHandle) NewRangeReader(ctx context.Context, offset, length int64)
}

r, err = o.c.tc.NewRangeReader(ctx, params, opts...)
r.ctx = ctx
quartzmo marked this conversation as resolved.
Show resolved Hide resolved

return r, err
}
Expand Down Expand Up @@ -204,11 +206,14 @@ type Reader struct {
gotCRC uint32 // running crc

reader io.ReadCloser
ctx context.Context
}

// Close closes the Reader. It must be called when done reading.
func (r *Reader) Close() error {
return r.reader.Close()
err := r.reader.Close()
trace.EndSpan(r.ctx, err)
return err
}

func (r *Reader) Read(p []byte) (int, error) {
Expand Down