@@ -3,13 +3,17 @@ package object
33import (
44 "bytes"
55 "context"
6+ "crypto/md5"
67 "errors"
78 "fmt"
89 "io"
910
11+ "github.com/aws/aws-sdk-go-v2/aws"
1012 s3manager "github.com/aws/aws-sdk-go-v2/feature/s3/manager"
1113 "github.com/aws/aws-sdk-go-v2/service/s3"
1214 "github.com/aws/aws-sdk-go-v2/service/s3/types"
15+ "go.opentelemetry.io/otel/attribute"
16+ "go.opentelemetry.io/otel/trace"
1317 "go.uber.org/fx"
1418 "go.uber.org/zap"
1519)
@@ -87,13 +91,31 @@ func (c *S3Client) Download(ctx context.Context, key string) ([]byte, error) {
8791
8892 return nil , err
8993 }
94+
95+ data := b .Bytes ()
96+ span := trace .SpanFromContext (ctx )
97+ span .SetAttributes (
98+ attribute .String ("r2.key" , key ),
99+ attribute .String ("r2.local_md5" , fmt .Sprintf (`"%x"` , md5 .Sum (data ))),
100+ )
101+
90102 return b .Bytes (), nil
91103}
92104
93105func (c * S3Client ) UploadStream (ctx context.Context , key string , data io.Reader ) error {
94106 req := & s3.PutObjectInput {Bucket : & c .bucket , Key : & key , Body : data }
95- _ , err := c .uploader .Upload (ctx , req )
96- return err
107+ res , err := c .uploader .Upload (ctx , req )
108+ if err != nil {
109+ return err
110+ }
111+
112+ span := trace .SpanFromContext (ctx )
113+ span .SetAttributes (
114+ attribute .String ("r2.etag" , aws .ToString (res .ETag )),
115+ attribute .String ("r2.versionId" , aws .ToString (res .VersionID )),
116+ attribute .String ("r2.key" , key ),
117+ )
118+ return nil
97119}
98120
99121// DownloadStream downloads a map and returns an io.ReadCloser that the caller is responsible for closing.
@@ -107,6 +129,7 @@ func (c *S3Client) DownloadStream(ctx context.Context, key string) (io.ReadClose
107129 }
108130 return nil , err
109131 }
132+
110133 // Return the Body directly - it's an io.ReadCloser
111134 // Caller is responsible for closing it
112135 return res .Body , nil // Body is an io.ReadCloser. The caller is responsible for closing it
0 commit comments