forked from instana/go-sensor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopy.go
102 lines (87 loc) · 3.49 KB
/
copy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// (c) Copyright IBM Corp. 2021
// (c) Copyright Instana Inc. 2020
//go:build go1.11
// +build go1.11
package storage
import (
"context"
"github.com/instana/go-sensor/instrumentation/cloud.google.com/go/internal/tags"
"strings"
"cloud.google.com/go/storage"
"github.com/mier85/go-sensor/instrumentation/cloud.google.com/go/internal"
ot "github.com/opentracing/opentracing-go"
)
// CopierFrom returns an instrumented cloud.google.com/go/storage.Copier.
//
// See https://pkg.go.dev/cloud.google.com/go/storage?tab=doc#ObjectHandle.CopierFrom for further details on wrapped method.
func (o *ObjectHandle) CopierFrom(src *ObjectHandle) *Copier {
return &Copier{
Copier: o.ObjectHandle.CopierFrom(src.ObjectHandle),
SourceBucket: src.Bucket,
SourceName: src.Name,
DestinationBucket: o.Bucket,
DestinationName: o.Name,
}
}
// Copier is an instrumented wrapper for cloud.google.com/go/storage.Copier
// that traces calls made to Google Cloud Storage API.
//
// See https://pkg.go.dev/cloud.google.com/go/storage?tab=doc#Copier for further details on wrapped type.
type Copier struct {
*storage.Copier
SourceBucket, SourceName string
DestinationBucket, DestinationName string
}
// Run calls and traces the Run() method of the wrapped Copier.
//
// See https://pkg.go.dev/cloud.google.com/go/storage?tab=doc#Copier.Run for further details on wrapped method.
func (c *Copier) Run(ctx context.Context) (attrs *storage.ObjectAttrs, err error) {
ctx = internal.StartExitSpan(ctx, "gcs", ot.Tags{
tags.GcsOp: "objects.copy",
tags.GcsSourceBucket: c.SourceBucket,
tags.GcsSourceObject: c.SourceName,
tags.GcsDestinationBucket: c.DestinationBucket,
tags.GcsDestinationObject: c.DestinationName,
})
defer func() { internal.FinishSpan(ctx, err) }()
return c.Copier.Run(ctx)
}
// ComposerFrom returns an instrumented cloud.google.com/go/storage.Composer.
//
// See https://pkg.go.dev/cloud.google.com/go/storage?tab=doc#ObjectHandle.ComposerFrom for further details on wrapped method.
func (o *ObjectHandle) ComposerFrom(srcs ...*ObjectHandle) *Composer {
srcsCopy := make([]*storage.ObjectHandle, len(srcs))
sourceObjects := make([]string, len(srcs))
for i := range srcs {
srcsCopy[i] = srcs[i].ObjectHandle
sourceObjects[i] = srcs[i].Bucket + "/" + srcs[i].Name
}
return &Composer{
Composer: o.ObjectHandle.ComposerFrom(srcsCopy...),
DestinationBucket: o.Bucket,
DestinationName: o.Name,
SourceObjects: sourceObjects,
}
}
// Composer is an instrumented wrapper for cloud.google.com/go/storage.Composer.
// that traces calls made to Google Cloud Storage API
//
// See https://pkg.go.dev/cloud.google.com/go/storage?tab=doc#Composer for further details on wrapped type.
type Composer struct {
*storage.Composer
DestinationBucket, DestinationName string
SourceObjects []string
}
// Run calls and traces the Run() method of the wrapped cloud.google.com/go/storage.Composer.
//
// See https://pkg.go.dev/cloud.google.com/go/storage?tab=doc#Composer.Run for further details on wrapped method.
func (c *Composer) Run(ctx context.Context) (attrs *storage.ObjectAttrs, err error) {
ctx = internal.StartExitSpan(ctx, "gcs", ot.Tags{
tags.GcsOp: "objects.compose",
tags.GcsDestinationBucket: c.DestinationBucket,
tags.GcsDestinationObject: c.DestinationName,
tags.GcsSourceObjects: strings.Join(c.SourceObjects, ","),
})
defer func() { internal.FinishSpan(ctx, err) }()
return c.Composer.Run(ctx)
}