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: 8 additions & 1 deletion cmd/compass-sidecar/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"log/slog"
"net/http"
"os"
"os/signal"
"syscall"
"time"

"github.com/ilyakaznacheev/cleanenv"
Expand Down Expand Up @@ -123,6 +125,11 @@ type Options struct {
}

func main() {
// Cancel the root context on an interrupt or termination signal, so the
// HTTP server drains and the tracers run their cleanup on shutdown.
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()

o := Options{}

cmd := &cobra.Command{
Expand Down Expand Up @@ -272,7 +279,7 @@ func main() {

// Cobra prints the error, so exit quietly rather than panicking with a
// stack trace over the top of it.
if err := cmd.Execute(); err != nil {
if err := cmd.ExecuteContext(ctx); err != nil {
os.Exit(1)
}
}
Expand Down
9 changes: 8 additions & 1 deletion cmd/compass/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import (
"context"
"fmt"
"os"
"os/signal"
"regexp"
"strings"
"syscall"

tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
Expand Down Expand Up @@ -60,6 +62,11 @@ func main() {
termenv.NewOutput(os.Stdout).EnvColorProfile(),
))

// Cancel the root context on an interrupt or termination signal, so the
// collector goroutine is torn down deterministically on shutdown.
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()

o := Options{}

cmd := &cobra.Command{
Expand Down Expand Up @@ -141,7 +148,7 @@ func main() {

// Cobra prints the error, so exit quietly rather than panicking with a
// stack trace over the top of it.
if err := cmd.Execute(); err != nil {
if err := cmd.ExecuteContext(ctx); err != nil {
os.Exit(1)
}
}
Loading