diff --git a/internal/test/e2e/databasesql/main.go b/internal/test/e2e/databasesql/main.go index 5962ec942..8d713ea8c 100644 --- a/internal/test/e2e/databasesql/main.go +++ b/internal/test/e2e/databasesql/main.go @@ -14,8 +14,9 @@ import ( "os/signal" _ "github.com/mattn/go-sqlite3" - "go.opentelemetry.io/auto/internal/test/trigger" "go.uber.org/zap" + + "go.opentelemetry.io/auto/internal/test/trigger" ) const ( diff --git a/internal/test/e2e/gin/main.go b/internal/test/e2e/gin/main.go index 7c73467f9..99c52bfe3 100644 --- a/internal/test/e2e/gin/main.go +++ b/internal/test/e2e/gin/main.go @@ -13,6 +13,7 @@ import ( "os/signal" "github.com/gin-gonic/gin" + "go.opentelemetry.io/auto/internal/test/trigger" ) diff --git a/internal/test/e2e/grpc/main.go b/internal/test/e2e/grpc/main.go index cccc2358e..8aba8e2a8 100644 --- a/internal/test/e2e/grpc/main.go +++ b/internal/test/e2e/grpc/main.go @@ -16,12 +16,13 @@ import ( "os/signal" "time" - "go.opentelemetry.io/auto/internal/test/trigger" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/credentials/insecure" pb "google.golang.org/grpc/examples/helloworld/helloworld" "google.golang.org/grpc/status" + + "go.opentelemetry.io/auto/internal/test/trigger" ) const port = 1701 diff --git a/internal/test/e2e/kafka-go/main.go b/internal/test/e2e/kafka-go/main.go index ce2fcb836..51de1779b 100644 --- a/internal/test/e2e/kafka-go/main.go +++ b/internal/test/e2e/kafka-go/main.go @@ -13,6 +13,7 @@ import ( "time" kafka "github.com/segmentio/kafka-go" + "go.opentelemetry.io/auto/internal/test/trigger" ) diff --git a/internal/test/e2e/otelglobal/main.go b/internal/test/e2e/otelglobal/main.go index 5e92d6ce8..ecaea15e3 100644 --- a/internal/test/e2e/otelglobal/main.go +++ b/internal/test/e2e/otelglobal/main.go @@ -10,11 +10,12 @@ import ( "os" "os/signal" - "go.opentelemetry.io/auto/internal/test/trigger" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/trace" + + "go.opentelemetry.io/auto/internal/test/trigger" ) var tracer = otel.Tracer( diff --git a/internal/tools/collector/main.go b/internal/tools/collector/main.go index 0b4b9639e..88f55bf4f 100644 --- a/internal/tools/collector/main.go +++ b/internal/tools/collector/main.go @@ -84,8 +84,8 @@ func main() { configYaml := fmt.Sprintf(config, *outPath) logger.Debug("built config", "config", configYaml) - coll := Collector{logger: logger} - if err := coll.Start(ctx, configYaml); err != nil { + coll := collector{logger: logger} + if err := coll.start(ctx, configYaml); err != nil { logger.Error("failed to start collector", "error", err) os.Exit(1) } @@ -98,7 +98,7 @@ func main() { // Wait for the context to be canceled <-ctx.Done() - coll.Stop() + coll.stop() } func newLogger(lvlStr string) *slog.Logger { @@ -121,14 +121,14 @@ func newLogger(lvlStr string) *slog.Logger { return logger } -type Collector struct { +type collector struct { logger *slog.Logger collMu sync.Mutex coll *otelcol.Collector } -func (c *Collector) Start(ctx context.Context, configYaml string) error { +func (c *collector) start(ctx context.Context, configYaml string) error { c.collMu.Lock() defer c.collMu.Unlock() @@ -174,7 +174,7 @@ func (c *Collector) Start(ctx context.Context, configYaml string) error { return nil } -func (c *Collector) Stop() { +func (c *collector) stop() { c.logger.Info("stopping collector") c.collMu.Lock() defer c.collMu.Unlock() @@ -193,7 +193,7 @@ func startHTTPServer(addr string, cancel context.CancelFunc, logger *slog.Logger logger.Info("shutdown endpoint hit") cancel() w.WriteHeader(http.StatusOK) - w.Write([]byte("Shutting down collector...")) + _, _ = w.Write([]byte("Shutting down collector...")) }) logger.Info("starting shutdown HTTP server", "addr", addr) diff --git a/internal/tools/runner/main.go b/internal/tools/runner/main.go index b71e9cc14..0e6ff72f0 100644 --- a/internal/tools/runner/main.go +++ b/internal/tools/runner/main.go @@ -12,8 +12,9 @@ import ( "os/signal" "syscall" - "go.opentelemetry.io/auto" "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp" + + "go.opentelemetry.io/auto" ) func main() { @@ -32,8 +33,8 @@ func main() { ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt) defer stop() - app := App{logger: logger} - if err := app.Run(ctx, *binPath); err != nil { + app := app{logger: logger} + if err := app.run(ctx, *binPath); err != nil { logger.Error("failed to run", "error", err) os.Exit(1) } @@ -59,11 +60,11 @@ func newLogger(lvlStr string) *slog.Logger { return logger } -type App struct { +type app struct { logger *slog.Logger } -func (a *App) Run(ctx context.Context, binPath string) error { +func (a *app) run(ctx context.Context, binPath string) error { exp, err := otlptracehttp.New(ctx) if err != nil { return err @@ -109,13 +110,18 @@ func (a *App) Run(ctx context.Context, binPath string) error { var sig os.Signal = syscall.SIGCONT a.logger.Debug("sending signal to target") - cmd.Process.Signal(sig) + if err := cmd.Process.Signal(sig); err != nil { + return err + } a.logger.Debug("sent signal to target") done := make(chan struct{}) go func() { - cmd.Wait() + err := cmd.Wait() close(done) + if err != nil { + a.logger.Error("command failed", "error", err) + } }() select {