traceattrs: Functions for the commonly-used OCI-related attributes

We have a number of trace attributes that we use across all of our OCI
Distribution-based functionality, so this centralizes their definitions
in package traceattrs.

This intentionally ignores a few additional attribute names that are used
only in the code that interacts with Docker-style credential helpers,
because all of those are used only in a single function and so adding
indirection for those doesn't have enough benefit to offset the cost of
additional indirection.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
This commit is contained in:
Martin Atkins
2025-10-31 13:14:26 -07:00
parent 35cd016693
commit 93d095c67e
6 changed files with 100 additions and 29 deletions

View File

@@ -221,8 +221,8 @@ func (g *ociDistributionGetter) resolveManifestDescriptor(ctx context.Context, r
ctx, span := tracing.Tracer().Start(
ctx, "Resolve reference",
tracing.SpanAttributes(
traceattrs.String("opentofu.oci.registry.domain", ref.Registry),
traceattrs.String("opentofu.oci.repository.name", ref.Repository),
traceattrs.OpenTofuOCIRegistryDomain(ref.Registry),
traceattrs.OpenTofuOCIRepositoryName(ref.Repository),
),
)
defer span.End()
@@ -279,7 +279,7 @@ func (g *ociDistributionGetter) resolveManifestDescriptor(ctx context.Context, r
// If we're starting with a tag name then we need to query the
// repository to find out which digest is currently selected.
span.SetAttributes(
traceattrs.String("opentofu.oci.reference.tag", wantTag),
traceattrs.OpenTofuOCIReferenceTag(wantTag),
)
desc, err = store.Resolve(ctx, wantTag)
if err != nil {
@@ -294,7 +294,7 @@ func (g *ociDistributionGetter) resolveManifestDescriptor(ctx context.Context, r
// and so we can't exercise this specific case from unit tests
// using in-memory or on-disk fakes. :(
span.SetAttributes(
traceattrs.String("opentofu.oci.reference.digest", wantDigest.String()),
traceattrs.OpenTofuOCIReferenceDigest(wantDigest.String()),
)
desc, err = store.Resolve(ctx, wantDigest.String())
if err != nil {
@@ -304,8 +304,8 @@ func (g *ociDistributionGetter) resolveManifestDescriptor(ctx context.Context, r
span.SetAttributes(
traceattrs.OCIManifestDigest(desc.Digest.String()),
traceattrs.String("opentofu.oci.manifest.media_type", desc.MediaType),
traceattrs.Int64("opentofu.oci.manifest.size", desc.Size),
traceattrs.OpenTofuOCIManifestMediaType(desc.MediaType),
traceattrs.OpenTofuOCIManifestSize(desc.Size),
)
// The initial request is only required to return a "plain" descriptor,
@@ -328,7 +328,7 @@ func fetchOCIImageManifest(ctx context.Context, desc ociv1.Descriptor, store OCI
ctx, "Fetch manifest",
tracing.SpanAttributes(
traceattrs.OCIManifestDigest(desc.Digest.String()),
traceattrs.Int64("opentofu.oci.manifest.size", desc.Size),
traceattrs.OpenTofuOCIManifestSize(desc.Size),
),
)
defer span.End()
@@ -356,8 +356,8 @@ func fetchOCIImageManifest(ctx context.Context, desc ociv1.Descriptor, store OCI
}
span.SetAttributes(
traceattrs.String("opentofu.oci.manifest.media_type", desc.MediaType),
traceattrs.String("opentofu.oci.manifest.artifact_type", desc.ArtifactType),
traceattrs.OpenTofuOCIManifestMediaType(desc.MediaType),
traceattrs.OpenTofuOCIManifestArtifactType(desc.ArtifactType),
)
// Now we'll make sure that what we decoded seems vaguely sensible before we
@@ -455,9 +455,9 @@ func fetchOCIBlobToTemporaryFile(ctx context.Context, desc ociv1.Descriptor, sto
ctx, span := tracing.Tracer().Start(
ctx, "Fetch module package",
tracing.SpanAttributes(
traceattrs.String("opentofu.oci.blob.digest", desc.Digest.String()),
traceattrs.String("opentofu.oci.blob.media_type", desc.MediaType),
traceattrs.Int64("opentofu.oci.blob.size", desc.Size),
traceattrs.OpenTofuOCIBlobDigest(desc.Digest.String()),
traceattrs.OpenTofuOCIBlobMediaType(desc.MediaType),
traceattrs.OpenTofuOCIBlobSize(desc.Size),
),
)
defer span.End()