Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pkg/imageverifier/bindir/bindir.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (

"github.com/containerd/containerd/v2/internal/tomlext"
Comment thread
just1not2 marked this conversation as resolved.
"github.com/containerd/containerd/v2/pkg/imageverifier"
"github.com/containerd/containerd/v2/pkg/tracing"
"github.com/containerd/log"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)
Expand Down Expand Up @@ -123,6 +124,14 @@ func (v *ImageVerifier) runVerifier(ctx context.Context, bin string, imageName s

cmd := exec.CommandContext(ctx, binPath, args...)

// Attach OTEL propagators trace context env var to the child process
if traceContext, err := tracing.GetPropagatorsTraceContext(ctx); err != nil {
log.G(ctx).Warn("could not marshall propagators trace context", err)
} else {
traceContextEnv := fmt.Sprintf("OTEL_PROPAGATORS_TRACE_CONTEXT=%s", traceContext)
cmd.Env = append(os.Environ(), traceContextEnv)
}

// We construct our own pipes instead of using the default StdinPipe,
// StoutPipe, and StderrPipe in order to set timeouts on reads and writes.
stdinRead, stdinWrite, err := os.Pipe()
Expand Down
10 changes: 10 additions & 0 deletions pkg/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ package tracing

import (
"context"
"encoding/json"
"net/http"
"strings"

"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/propagation"
semconv "go.opentelemetry.io/otel/semconv/v1.21.0"
"go.opentelemetry.io/otel/trace"
)
Expand Down Expand Up @@ -130,3 +132,11 @@ func Attribute(k string, v any) attribute.KeyValue {
func HTTPStatusCodeAttributes(code int) []attribute.KeyValue {
return []attribute.KeyValue{semconv.HTTPStatusCodeKey.Int(code)}
}

// GetPropagatorsTraceContext returns the current propagators trace context as a JSON string
func GetPropagatorsTraceContext(ctx context.Context) ([]byte, error) {
propagator := propagation.TraceContext{}
carrier := propagation.MapCarrier{}
propagator.Inject(ctx, carrier)
return json.Marshal(carrier)
}