add SpanAttribute

Signed-off-by: Swagat Bora <sbora@amazon.com>
This commit is contained in:
Swagat Bora
2022-11-03 16:50:50 +00:00
parent 3b87d46ce2
commit ee64926a72
11 changed files with 114 additions and 96 deletions

View File

@@ -36,7 +36,6 @@ import (
"github.com/containerd/imgcrypt"
"github.com/containerd/imgcrypt/images/encryption"
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
"go.opentelemetry.io/otel/attribute"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
"github.com/containerd/containerd"
@@ -137,8 +136,8 @@ func (c *criService) PullImage(ctx context.Context, r *runtime.PullImageRequest)
}
log.G(ctx).Debugf("PullImage %q with snapshotter %s", ref, snapshotter)
span.SetAttributes(
attribute.String("image.ref", ref),
attribute.String("snapshotter.name", snapshotter),
tracing.SpanAttribute("image.ref", ref),
tracing.SpanAttribute("snapshotter.name", snapshotter),
)
pullOpts := []containerd.RemoteOpt{

View File

@@ -23,7 +23,6 @@ import (
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/images"
"github.com/containerd/containerd/tracing"
"go.opentelemetry.io/otel/attribute"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
)
@@ -45,7 +44,7 @@ func (c *criService) RemoveImage(ctx context.Context, r *runtime.RemoveImageRequ
}
return nil, fmt.Errorf("can not resolve %q locally: %w", r.GetImage().GetImage(), err)
}
span.SetAttributes(attribute.String("image.id", image.ID))
span.SetAttributes(tracing.SpanAttribute("image.id", image.ID))
// Remove all image references.
for i, ref := range image.References {
var opts []images.DeleteOpt

View File

@@ -25,7 +25,6 @@ import (
"github.com/containerd/containerd/log"
imagestore "github.com/containerd/containerd/pkg/cri/store/image"
"github.com/containerd/containerd/tracing"
"go.opentelemetry.io/otel/attribute"
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
@@ -45,7 +44,7 @@ func (c *criService) ImageStatus(ctx context.Context, r *runtime.ImageStatusRequ
}
return nil, fmt.Errorf("can not resolve %q locally: %w", r.GetImage().GetImage(), err)
}
span.SetAttributes(attribute.String("image.id", image.ID))
span.SetAttributes(tracing.SpanAttribute("image.id", image.ID))
// TODO(random-liu): [P0] Make sure corresponding snapshot exists. What if snapshot
// doesn't exist?

View File

@@ -36,7 +36,6 @@ import (
"github.com/containerd/imgcrypt"
"github.com/containerd/imgcrypt/images/encryption"
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
"go.opentelemetry.io/otel/attribute"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
"github.com/containerd/containerd"
@@ -137,8 +136,8 @@ func (c *criService) PullImage(ctx context.Context, r *runtime.PullImageRequest)
}
log.G(ctx).Debugf("PullImage %q with snapshotter %s", ref, snapshotter)
span.SetAttributes(
attribute.String("image.ref", ref),
attribute.String("snapshotter.name", snapshotter),
tracing.SpanAttribute("image.ref", ref),
tracing.SpanAttribute("snapshotter.name", snapshotter),
)
pullOpts := []containerd.RemoteOpt{
containerd.WithSchema1Conversion, //nolint:staticcheck // Ignore SA1019. Need to keep deprecated package for compatibility.

View File

@@ -23,7 +23,6 @@ import (
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/images"
"github.com/containerd/containerd/tracing"
"go.opentelemetry.io/otel/attribute"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
)
@@ -45,7 +44,7 @@ func (c *criService) RemoveImage(ctx context.Context, r *runtime.RemoveImageRequ
}
return nil, fmt.Errorf("can not resolve %q locally: %w", r.GetImage().GetImage(), err)
}
span.SetAttributes(attribute.String("image.id", image.ID))
span.SetAttributes(tracing.SpanAttribute("image.id", image.ID))
// Remove all image references.
for i, ref := range image.References {
var opts []images.DeleteOpt

View File

@@ -25,7 +25,6 @@ import (
"github.com/containerd/containerd/log"
imagestore "github.com/containerd/containerd/pkg/cri/store/image"
"github.com/containerd/containerd/tracing"
"go.opentelemetry.io/otel/attribute"
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
@@ -45,7 +44,7 @@ func (c *criService) ImageStatus(ctx context.Context, r *runtime.ImageStatusRequ
}
return nil, fmt.Errorf("can not resolve %q locally: %w", r.GetImage().GetImage(), err)
}
span.SetAttributes(attribute.String("image.id", image.ID))
span.SetAttributes(tracing.SpanAttribute("image.id", image.ID))
// TODO(random-liu): [P0] Make sure corresponding snapshot exists. What if snapshot
// doesn't exist?

View File

@@ -42,7 +42,6 @@ import (
"github.com/opencontainers/image-spec/identity"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/sirupsen/logrus"
"go.opentelemetry.io/otel/attribute"
"golang.org/x/sync/errgroup"
"golang.org/x/sync/semaphore"
)
@@ -166,8 +165,8 @@ func (u *Unpacker) Unpack(h images.Handler) images.Handler {
ctx, span := tracing.StartSpan(ctx, "pkg.unpack.unpacker.UnpackHandler")
defer span.End()
span.SetAttributes(
attribute.String("descriptor.media.type", desc.MediaType),
attribute.String("descriptor.digest", desc.Digest.String()))
tracing.SpanAttribute("descriptor.media.type", desc.MediaType),
tracing.SpanAttribute("descriptor.digest", desc.Digest.String()))
unlock, err := u.lockBlobDescriptor(ctx, desc)
if err != nil {
return nil, err
@@ -186,7 +185,7 @@ func (u *Unpacker) Unpack(h images.Handler) images.Handler {
// the config
for i, child := range children {
span.SetAttributes(
attribute.StringSlice("descriptor.child."+strconv.Itoa(i), []string{child.MediaType, child.Digest.String()}),
tracing.SpanAttribute("descriptor.child."+strconv.Itoa(i), []string{child.MediaType, child.Digest.String()}),
)
if images.IsLayerType(child.MediaType) {
manifestLayers = append(manifestLayers, child)
@@ -412,9 +411,9 @@ func (u *Unpacker) unpack(
for i, desc := range layers {
_, layerSpan := tracing.StartSpan(ctx, "pkg.unpack.unpacker.unpackLayer")
layerSpan.SetAttributes(
attribute.String("layer.media.type", desc.MediaType),
attribute.Int64("layer.media.size", desc.Size),
attribute.String("layer.media.digest", desc.Digest.String()),
tracing.SpanAttribute("layer.media.type", desc.MediaType),
tracing.SpanAttribute("layer.media.size", desc.Size),
tracing.SpanAttribute("layer.media.digest", desc.Digest.String()),
)
if err := doUnpackFn(i, desc); err != nil {
layerSpan.RecordError(err)
@@ -448,9 +447,9 @@ func (u *Unpacker) fetch(ctx context.Context, h images.Handler, layers []ocispec
for i, desc := range layers {
ctx2, layerSpan := tracing.StartSpan(ctx2, "pkg.unpack.unpacker.fetchLayer")
layerSpan.SetAttributes(
attribute.String("layer.media.type", desc.MediaType),
attribute.Int64("layer.media.size", desc.Size),
attribute.String("layer.media.digest", desc.Digest.String()),
tracing.SpanAttribute("layer.media.type", desc.MediaType),
tracing.SpanAttribute("layer.media.size", desc.Size),
tracing.SpanAttribute("layer.media.digest", desc.Digest.String()),
)
desc := desc
i := i