-
Notifications
You must be signed in to change notification settings - Fork 201
/
bundle.go
37 lines (29 loc) · 987 Bytes
/
bundle.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
package cnab
import (
"bytes"
"context"
"encoding/json"
"github.com/cnabio/cnab-to-oci/relocation"
"github.com/opencontainers/go-digest"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
)
type BundleReference struct {
Reference OCIReference
Digest digest.Digest
Definition ExtendedBundle
RelocationMap relocation.ImageRelocationMap
}
func (r BundleReference) String() string {
return r.Reference.String()
}
// AddToTrace appends the bundle reference attributes to the current span.
func (r BundleReference) AddToTrace(cxt context.Context) {
span := trace.SpanFromContext(cxt)
span.SetAttributes(attribute.String("reference", r.String()))
var bunJson bytes.Buffer
_, _ = r.Definition.WriteTo(&bunJson)
span.SetAttributes(attribute.String("bundleDefinition", bunJson.String()))
relocationMappingJson, _ := json.Marshal(r.RelocationMap)
span.SetAttributes(attribute.String("relocationMapping", string(relocationMappingJson)))
}