Add root trace span for build command and fix S3 cache timeout - #326
Merged
Conversation
WVerlaek
force-pushed
the
wv/add-tracing-for-build-command
branch
7 times, most recently
from
January 15, 2026 14:17
e1bed66 to
c99a208
Compare
- 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
force-pushed
the
wv/add-tracing-for-build-command
branch
from
January 15, 2026 14:19
c99a208 to
e26c752
Compare
WVerlaek
commented
Jan 15, 2026
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) | ||
| } |
Member
Author
There was a problem hiding this comment.
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
WVerlaek
commented
Jan 15, 2026
|
|
||
| // 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, "") |
Member
Author
There was a problem hiding this comment.
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
marked this pull request as ready for review
January 15, 2026 14:31
leodido
approved these changes
Jan 15, 2026
| s.downloadSBOMFiles(ctx, p.FullName(), gzKey, localPath) | ||
|
|
||
| return cache.DownloadResult{Status: cache.DownloadStatusSuccess} | ||
| return cache.DownloadResult{Status: cache.DownloadStatusSuccess, Bytes: gzBytes} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds a
leeway.commandtrace 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
ExistingPackageswould fail after 60 seconds on S3 buckets with millions of objects. The previous implementation usedListObjectswith an empty prefix to enumerate all objects. Now uses parallelHeadObjectcalls to check only the specific keys needed.Related Issue(s)
Fixes CORE-6616
Part of CORE-6596
How to test
leeway.commandspan wrapsleeway.buildspanExistingPackages