From 7e70893992532f1a7a9a13b0a5874bf7ed344c3b Mon Sep 17 00:00:00 2001 From: Daniel Redondo Date: Mon, 27 Apr 2020 18:17:06 +0200 Subject: [PATCH 1/3] Show initialization error messages only if SCOPE_DEBUG is set --- agent/agent.go | 2 +- init.go | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/agent/agent.go b/agent/agent.go index 2a24b2bd..2f47be28 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -237,7 +237,7 @@ func NewAgent(options ...Option) (*Agent, error) { } else { agent.logger.Println("API key not found, agent can't be started") return nil, errors.New(fmt.Sprintf("There was a problem initializing Scope.\n"+ - "Check the agent logs at %s for more information.\n", agent.recorderFilename)) + "Check the agent logs at %s for more information.\n\nAPI key not found, agent can't be started", agent.recorderFilename)) } } diff --git a/init.go b/init.go index 995a00ad..88bc3104 100644 --- a/init.go +++ b/init.go @@ -12,6 +12,7 @@ import ( "testing" "go.undefinedlabs.com/scopeagent/agent" + "go.undefinedlabs.com/scopeagent/env" "go.undefinedlabs.com/scopeagent/instrumentation" "go.undefinedlabs.com/scopeagent/instrumentation/logging" scopetesting "go.undefinedlabs.com/scopeagent/instrumentation/testing" @@ -34,7 +35,9 @@ func Run(m *testing.M, opts ...agent.Option) int { newAgent, err := agent.NewAgent(opts...) if err != nil { res := m.Run() - fmt.Printf("\n%v\n", err) + if env.ScopeDebug.Value { + fmt.Printf("\n%v\n", err) + } return res } @@ -47,8 +50,10 @@ func Run(m *testing.M, opts ...agent.Option) int { signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) go func() { <-sigs - instrumentation.Logger().Println("Terminating agent, sending partial results...") - newAgent.Stop() + if newAgent != nil { + instrumentation.Logger().Println("Terminating agent, sending partial results...") + newAgent.Stop() + } os.Exit(1) }() From 71d47f9977d906cbe3dea32d2d3aa1edbc89fa8a Mon Sep 17 00:00:00 2001 From: Daniel Redondo Date: Mon, 27 Apr 2020 18:18:47 +0200 Subject: [PATCH 2/3] change ApiKey to Scope DSN --- agent/agent.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent/agent.go b/agent/agent.go index 2f47be28..45d6b6c3 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -237,7 +237,7 @@ func NewAgent(options ...Option) (*Agent, error) { } else { agent.logger.Println("API key not found, agent can't be started") return nil, errors.New(fmt.Sprintf("There was a problem initializing Scope.\n"+ - "Check the agent logs at %s for more information.\n\nAPI key not found, agent can't be started", agent.recorderFilename)) + "Check the agent logs at %s for more information.\n\nScope DSN not found, agent can't be started", agent.recorderFilename)) } } From be8bae199763b155a30788d757837337068b3d5d Mon Sep 17 00:00:00 2001 From: Daniel Redondo Date: Wed, 29 Apr 2020 22:47:04 +0200 Subject: [PATCH 3/3] Error message change --- agent/agent.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/agent/agent.go b/agent/agent.go index 45d6b6c3..2c939460 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -236,8 +236,7 @@ func NewAgent(options ...Option) (*Agent, error) { agent.apiKey = configProfile.ApiKey } else { agent.logger.Println("API key not found, agent can't be started") - return nil, errors.New(fmt.Sprintf("There was a problem initializing Scope.\n"+ - "Check the agent logs at %s for more information.\n\nScope DSN not found, agent can't be started", agent.recorderFilename)) + return nil, errors.New("Scope DSN not found. Tests will run but no results will be reported to Scope. More info at https://docs.scope.dev/") } }