Skip to content

Commit 66c989b

Browse files
authored
refactor: add finer grained run--watch otel events (#269)
### Changes are visible to end-users: no ### Test plan - Covered by existing test cases
1 parent db05ae8 commit 66c989b

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

pkg/aspect/run/run.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ func (runner *Run) runWatch(ctx context.Context, bazelCmd []string, bzlCommandSt
410410
return fmt.Errorf("failed to get next event: %w", err)
411411
}
412412

413-
_, st := runner.tracer.Start(pcctx, "Run.Subscribe.Trigger")
413+
_, watchTrace := runner.tracer.Start(pcctx, "Run.Subscribe.WatchEvent")
414414

415415
// Enter into the build state to discard supirious changes caused by Bazel reading the
416416
// inputs which leads to their atime to change.
@@ -426,6 +426,9 @@ func (runner *Run) runWatch(ctx context.Context, bazelCmd []string, bzlCommandSt
426426
return fmt.Errorf("failed to create bazel detect command: %w", err)
427427
}
428428

429+
_, rebuildTrace := runner.tracer.Start(pcctx, "Run.Subscribe.Build", trace.WithAttributes(
430+
traceAttr.StringSlice("command", detectCmd.Args),
431+
))
429432
// Something has changed, but we have no idea if it affects our target.
430433
// Normally we'd want to perform a cquery to determine if it affects but
431434
// that is too costly especially in larger monorepos. So instead we rebuild
@@ -436,6 +439,8 @@ func (runner *Run) runWatch(ctx context.Context, bazelCmd []string, bzlCommandSt
436439
logger.Infof("incremental --watch build: %v", detectCmd.Args)
437440
incBuildErr := detectCmd.Run()
438441

442+
rebuildTrace.End()
443+
439444
dtErr := changedetect.detectChanges(cs.Paths)
440445
if dtErr != nil {
441446
return fmt.Errorf("failed to detect changes: %w", dtErr)
@@ -453,10 +458,14 @@ func (runner *Run) runWatch(ctx context.Context, bazelCmd []string, bzlCommandSt
453458
// the subprocess exists.
454459
fmt.Printf("%s Found %d changes, rebuilding the target.\n", color.GreenString("INFO:"), len(changes))
455460

461+
_, cycleTrace := runner.tracer.Start(pcctx, "Run.Subscribe.Cycle")
462+
456463
if err := incrementalProtocol.Cycle(changes); err != nil {
457464
return fmt.Errorf("failed to report cycle events: %w", err)
458465
}
459466

467+
cycleTrace.End()
468+
460469
// TODO: if we want to support ibazel livereload then we need to report changes.
461470
} else {
462471
fmt.Printf("%s Target is up-to-date.\n", color.GreenString("INFO:"))
@@ -467,7 +476,7 @@ func (runner *Run) runWatch(ctx context.Context, bazelCmd []string, bzlCommandSt
467476
return fmt.Errorf("failed to enter build state: %w", err)
468477
}
469478

470-
st.End()
479+
watchTrace.End()
471480
}
472481

473482
return nil

0 commit comments

Comments
 (0)