Skip to content

Commit ac4936a

Browse files
chore: lint and format OpenTelemetry code
- Fix errcheck warnings in test files (check tp.Shutdown errors) - Fix errcheck warnings for os.Setenv/Unsetenv in tests - Run go fmt on modified files Co-authored-by: Ona <no-reply@ona.com>
1 parent 5512a84 commit ac4936a

File tree

4 files changed

+41
-31
lines changed

4 files changed

+41
-31
lines changed

cmd/build.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -329,18 +329,18 @@ func getBuildOpts(cmd *cobra.Command) ([]leeway.BuildOption, cache.LocalCache, f
329329
if os.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT") == "" {
330330
os.Setenv("OTEL_EXPORTER_OTLP_ENDPOINT", otelEndpoint)
331331
}
332-
332+
333333
// Initialize tracer
334334
tp, err := telemetry.InitTracer(context.Background())
335335
if err != nil {
336336
log.WithError(err).Warn("failed to initialize OpenTelemetry tracer")
337337
} else {
338338
tracerProvider = tp
339-
339+
340340
// Parse trace context if provided
341341
traceParent, _ := cmd.Flags().GetString("trace-parent")
342342
traceState, _ := cmd.Flags().GetString("trace-state")
343-
343+
344344
parentCtx := context.Background()
345345
if traceParent != "" {
346346
if err := telemetry.ValidateTraceParent(traceParent); err != nil {
@@ -354,11 +354,11 @@ func getBuildOpts(cmd *cobra.Command) ([]leeway.BuildOption, cache.LocalCache, f
354354
}
355355
}
356356
}
357-
357+
358358
// Create OTel reporter
359359
tracer := otel.Tracer("leeway")
360360
reporter = append(reporter, leeway.NewOTelReporter(tracer, parentCtx))
361-
361+
362362
// Create shutdown function
363363
otelShutdown = func() {
364364
shutdownCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
@@ -436,7 +436,7 @@ func getBuildOpts(cmd *cobra.Command) ([]leeway.BuildOption, cache.LocalCache, f
436436
if otelShutdown == nil {
437437
otelShutdown = func() {}
438438
}
439-
439+
440440
return []leeway.BuildOption{
441441
leeway.WithLocalCache(localCache),
442442
leeway.WithRemoteCache(remoteCache),
@@ -515,7 +515,7 @@ func parseSLSAConfig(cmd *cobra.Command) (*cache.SLSAConfig, error) {
515515
slsaVerificationEnabled := os.Getenv(EnvvarSLSACacheVerification) == "true"
516516
slsaSourceURI := os.Getenv(EnvvarSLSASourceURI)
517517
requireAttestation := os.Getenv(EnvvarSLSARequireAttestation) == "true"
518-
518+
519519
// CLI flags override environment variables (if cmd is provided)
520520
if cmd != nil {
521521
if cmd.Flags().Changed("slsa-cache-verification") {
@@ -534,17 +534,17 @@ func parseSLSAConfig(cmd *cobra.Command) (*cache.SLSAConfig, error) {
534534
}
535535
}
536536
}
537-
537+
538538
// If verification is disabled, return nil
539539
if !slsaVerificationEnabled {
540540
return nil, nil
541541
}
542-
542+
543543
// Validation: source URI is required when verification is enabled
544544
if slsaSourceURI == "" {
545545
return nil, fmt.Errorf("--slsa-source-uri is required when using --slsa-cache-verification")
546546
}
547-
547+
548548
return &cache.SLSAConfig{
549549
Verification: true,
550550
SourceURI: slsaSourceURI,
@@ -556,19 +556,19 @@ func parseSLSAConfig(cmd *cobra.Command) (*cache.SLSAConfig, error) {
556556
func getRemoteCache(cmd *cobra.Command) cache.RemoteCache {
557557
remoteCacheBucket := os.Getenv(EnvvarRemoteCacheBucket)
558558
remoteStorage := os.Getenv(EnvvarRemoteCacheStorage)
559-
559+
560560
// Parse SLSA configuration
561561
slsaConfig, err := parseSLSAConfig(cmd)
562562
if err != nil {
563563
log.Fatalf("SLSA configuration error: %v", err)
564564
}
565-
565+
566566
if remoteCacheBucket != "" {
567567
config := &cache.RemoteConfig{
568568
BucketName: remoteCacheBucket,
569569
SLSA: slsaConfig,
570570
}
571-
571+
572572
switch remoteStorage {
573573
case "GCP":
574574
if slsaConfig != nil && slsaConfig.Verification {

pkg/leeway/reporter.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type Reporter interface {
4040
// The root package will also be passed into PackageBuildFinished once it's been built.
4141
BuildFinished(pkg *Package, err error)
4242

43-
// PackageBuildStarted is called when a package build actually gets underway. At this point
43+
// PackageBuildStarted is called when a package build actually gets underway. At this point
4444
// all transitive dependencies of the package have been built.
4545
PackageBuildStarted(pkg *Package, builddir string)
4646

@@ -695,13 +695,13 @@ func (sr *GitHubActionReporter) PackageBuildFinished(pkg *Package, rep *PackageB
695695
type OTelReporter struct {
696696
NoopReporter
697697

698-
tracer trace.Tracer
699-
parentCtx context.Context
700-
rootCtx context.Context
701-
rootSpan trace.Span
702-
packageCtxs map[string]context.Context
698+
tracer trace.Tracer
699+
parentCtx context.Context
700+
rootCtx context.Context
701+
rootSpan trace.Span
702+
packageCtxs map[string]context.Context
703703
packageSpans map[string]trace.Span
704-
mu sync.RWMutex
704+
mu sync.RWMutex
705705
}
706706

707707
// NewOTelReporter creates a new OpenTelemetry reporter with the given tracer and parent context
@@ -751,10 +751,10 @@ func (r *OTelReporter) BuildStarted(pkg *Package, status map[*Package]PackageBui
751751

752752
// Add build status summary
753753
var (
754-
cached int
755-
remote int
756-
download int
757-
toBuild int
754+
cached int
755+
remote int
756+
download int
757+
toBuild int
758758
)
759759
for _, s := range status {
760760
switch s {

pkg/leeway/reporter_otel_test.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ func TestOTelReporter_BuildLifecycle(t *testing.T) {
1515
tp := trace.NewTracerProvider(
1616
trace.WithSyncer(exporter),
1717
)
18-
defer tp.Shutdown(context.Background())
18+
defer func() {
19+
_ = tp.Shutdown(context.Background())
20+
}()
1921

2022
tracer := tp.Tracer("test")
2123
reporter := NewOTelReporter(tracer, context.Background())
@@ -76,7 +78,9 @@ func TestOTelReporter_PackageLifecycle(t *testing.T) {
7678
tp := trace.NewTracerProvider(
7779
trace.WithSyncer(exporter),
7880
)
79-
defer tp.Shutdown(context.Background())
81+
defer func() {
82+
_ = tp.Shutdown(context.Background())
83+
}()
8084

8185
tracer := tp.Tracer("test")
8286
reporter := NewOTelReporter(tracer, context.Background())
@@ -193,7 +197,9 @@ func TestOTelReporter_ConcurrentPackages(t *testing.T) {
193197
tp := trace.NewTracerProvider(
194198
trace.WithSyncer(exporter),
195199
)
196-
defer tp.Shutdown(context.Background())
200+
defer func() {
201+
_ = tp.Shutdown(context.Background())
202+
}()
197203

198204
tracer := tp.Tracer("test")
199205
reporter := NewOTelReporter(tracer, context.Background())
@@ -281,7 +287,9 @@ func TestOTelReporter_WithParentContext(t *testing.T) {
281287
tp := trace.NewTracerProvider(
282288
trace.WithSyncer(exporter),
283289
)
284-
defer tp.Shutdown(context.Background())
290+
defer func() {
291+
_ = tp.Shutdown(context.Background())
292+
}()
285293

286294
// Create parent span
287295
tracer := tp.Tracer("test")
@@ -310,7 +318,7 @@ func TestOTelReporter_WithParentContext(t *testing.T) {
310318

311319
reporter.BuildStarted(pkg, status)
312320
reporter.BuildFinished(pkg, nil)
313-
321+
314322
// End parent span so it appears in exporter
315323
parentSpan.End()
316324

pkg/leeway/telemetry/tracer_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,11 @@ func TestFormatTraceContext_Invalid(t *testing.T) {
170170
func TestInitTracer_NoEndpoint(t *testing.T) {
171171
// Save and restore environment
172172
oldEndpoint := os.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT")
173-
defer os.Setenv("OTEL_EXPORTER_OTLP_ENDPOINT", oldEndpoint)
173+
defer func() {
174+
_ = os.Setenv("OTEL_EXPORTER_OTLP_ENDPOINT", oldEndpoint)
175+
}()
174176

175-
os.Unsetenv("OTEL_EXPORTER_OTLP_ENDPOINT")
177+
_ = os.Unsetenv("OTEL_EXPORTER_OTLP_ENDPOINT")
176178

177179
_, err := InitTracer(context.Background())
178180
if err == nil {

0 commit comments

Comments
 (0)