Skip to content

Add root trace span for build command and fix S3 cache timeout - #326

Merged
WVerlaek merged 2 commits into
mainfrom
wv/add-tracing-for-build-command
Jan 15, 2026
Merged

Add root trace span for build command and fix S3 cache timeout#326
WVerlaek merged 2 commits into
mainfrom
wv/add-tracing-for-build-command

Conversation

@WVerlaek

@WVerlaek WVerlaek commented Jan 15, 2026

Copy link
Copy Markdown
Member

Description

Adds a leeway.command trace span that wraps the entire build command execution, capturing time spent on workspace loading and cache operations that weren't previously traced.

Also fixes a timeout issue where ExistingPackages would fail after 60 seconds on S3 buckets with millions of objects. The previous implementation used ListObjects with an empty prefix to enumerate all objects. Now uses parallel HeadObject calls to check only the specific keys needed.

Related Issue(s)

Fixes CORE-6616
Part of CORE-6596

How to test

image
  1. Run a build with tracing enabled:
    leeway build --otel-endpoint localhost:4318 --otel-insecure :pkg
    
  2. Verify leeway.command span wraps leeway.build span
  3. For S3 cache fix: run against a bucket with many objects and verify no timeout on ExistingPackages

@WVerlaek
WVerlaek force-pushed the wv/add-tracing-for-build-command branch 7 times, most recently from e1bed66 to c99a208 Compare January 15, 2026 14:17
- Add leeway.command span in root command via cmd.SetContext()
- Create leeway.build child span in build command
- Refactor telemetry package with singleton pattern and span utilities
  (Initialize, Shutdown, Tracer, StartSpan, FinishSpan)
- Replace ListObjects with parallel HeadObject calls in ExistingPackages
  to fix timeout on buckets with millions of objects
- Add tracing spans for cache download operations with size attributes

Co-authored-by: Ona <no-reply@ona.com>
@WVerlaek
WVerlaek force-pushed the wv/add-tracing-for-build-command branch from c99a208 to e26c752 Compare January 15, 2026 14:19
Co-authored-by: Ona <no-reply@ona.com>
Comment thread cmd/root.go
Comment on lines +145 to +175
otelEndpoint, _ := cmd.Flags().GetString("otel-endpoint")
if otelEndpoint != "" {
telemetry.SetLeewayVersion(leeway.Version)

otelInsecure, _ := cmd.Flags().GetBool("otel-insecure")
if err := telemetry.Initialize(cmd.Context(), otelEndpoint, otelInsecure); err != nil {
log.WithError(err).Warn("failed to initialize OpenTelemetry tracer")
} else {
// Parse trace context if provided
traceParent, _ := cmd.Flags().GetString("trace-parent")
traceState, _ := cmd.Flags().GetString("trace-state")

parentCtx := cmd.Context()
if traceParent != "" {
if err := telemetry.ValidateTraceParent(traceParent); err != nil {
log.WithError(err).Warn("invalid trace-parent format")
} else if ctx, err := telemetry.ParseTraceContext(traceParent, traceState); err != nil {
log.WithError(err).Warn("failed to parse trace context")
} else {
parentCtx = ctx
}
}

// Create command span and update command context
var ctx context.Context
ctx, commandSpan = telemetry.StartSpan(parentCtx, "leeway.command",
attribute.String("leeway.version", leeway.Version),
attribute.String("leeway.command", cmd.Name()),
)
cmd.SetContext(ctx)
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extracted from build.go to root.go, so we trace all leeway commands by default and creates a span that wraps the full command duration. We were missing e.g. remote cache lookup time before


// List all objects with empty prefix to get all cached artifacts
// In practice, this could be optimized with a common prefix if versions share one
objects, err := s.storage.ListObjects(timeoutCtx, "")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ListObjects was timing out after 60s, we have millions of objects in the remote cache. Instead, we now always do a HeadObject for each package we are looking up.

This takes only 135ms for our full build:

vscode ➜ /workspaces/leeway (main) $ go run main.go build dev:full-build -Dversion=dev
INFO[0000] checking remote cache for existing packages   count=55
INFO[0000] remote cache check completed                  checked=55 duration=135ms found=0

@WVerlaek
WVerlaek marked this pull request as ready for review January 15, 2026 14:31

@leodido leodido left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LFG

Ship it 🚀

s.downloadSBOMFiles(ctx, p.FullName(), gzKey, localPath)

return cache.DownloadResult{Status: cache.DownloadStatusSuccess}
return cache.DownloadResult{Status: cache.DownloadStatusSuccess, Bytes: gzBytes}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@WVerlaek
WVerlaek merged commit 7e12607 into main Jan 15, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants