From 71bb45b216ef8903c14bfe720e7b10474d305a7d Mon Sep 17 00:00:00 2001 From: Emmanuel Gautier Date: Sun, 29 Sep 2024 16:24:00 +0200 Subject: [PATCH] feat: add timeout and disable retry with sqa --- cmd/root.go | 5 +++++ go.mod | 2 +- go.sum | 4 ---- internal/analytics/analytics.go | 8 +++++++- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index c311ebe..7c8d921 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -34,6 +34,11 @@ func NewRootCmd(projectVersion string) (cmd *cobra.Command) { analytics.NewAnalytics(ctx, projectVersion) } }, + PersistentPostRun: func(cmd *cobra.Command, args []string) { + if !sqaOptOut { + analytics.Close() + } + }, } rootCmd.AddCommand(versionCmd) rootCmd.AddCommand(discover.NewDiscoverCmd()) diff --git a/go.mod b/go.mod index f05172f..9875545 100644 --- a/go.mod +++ b/go.mod @@ -18,6 +18,7 @@ require ( github.com/stretchr/testify v1.9.0 go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin v0.55.0 go.opentelemetry.io/otel v1.30.0 + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.30.0 go.opentelemetry.io/otel/sdk v1.30.0 go.opentelemetry.io/otel/trace v1.30.0 go.uber.org/ratelimit v0.3.1 @@ -65,7 +66,6 @@ require ( github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.12 // indirect go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.30.0 // indirect - go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.30.0 // indirect go.opentelemetry.io/otel/metric v1.30.0 // indirect go.opentelemetry.io/proto/otlp v1.3.1 // indirect golang.org/x/arch v0.10.0 // indirect diff --git a/go.sum b/go.sum index e4f39bc..bf50209 100644 --- a/go.sum +++ b/go.sum @@ -9,8 +9,6 @@ github.com/bytedance/sonic/loader v0.2.0 h1:zNprn+lsIP06C/IqCHs3gPQIvnvpKbbxyXQP github.com/bytedance/sonic/loader v0.2.0/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= -github.com/cerberauth/x v0.0.0-20240911111527-d0ec204e5d48 h1:6EzPQiCmEALpj8tREFA72uKSCVEzus6YWd9fBlXYIEM= -github.com/cerberauth/x v0.0.0-20240911111527-d0ec204e5d48/go.mod h1:l3nkeJfebGk9Rn2Uaz/xhKMkfHHp3K2ILl4f5WI7/uk= github.com/cerberauth/x v0.0.0-20240929131055-0a38dd31aeda h1:D2Zg/XW7L/ErDZjA9sj+GMaKdvaadTaYKiqv4iUO8Do= github.com/cerberauth/x v0.0.0-20240929131055-0a38dd31aeda/go.mod h1:l3nkeJfebGk9Rn2Uaz/xhKMkfHHp3K2ILl4f5WI7/uk= github.com/chengxilo/virtualterm v1.0.4 h1:Z6IpERbRVlfB8WkOmtbHiDbBANU7cimRIof7mk9/PwM= @@ -109,8 +107,6 @@ github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/projectdiscovery/wappalyzergo v0.1.20 h1:EbpBSIj6E+dBoKf3J1XPNygDBdwApXWNPFwWv5ugTSU= -github.com/projectdiscovery/wappalyzergo v0.1.20/go.mod h1:wnvmbC10pQTOoCKnCTmWKP20rpEtqrMJZvzuTuleeyw= github.com/projectdiscovery/wappalyzergo v0.1.21 h1:IBzws+/YyXctWMZOjADRIG3ghv076rT54jbO548/+q4= github.com/projectdiscovery/wappalyzergo v0.1.21/go.mod h1:wnvmbC10pQTOoCKnCTmWKP20rpEtqrMJZvzuTuleeyw= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= diff --git a/internal/analytics/analytics.go b/internal/analytics/analytics.go index 5736ec4..33909df 100644 --- a/internal/analytics/analytics.go +++ b/internal/analytics/analytics.go @@ -2,8 +2,10 @@ package analytics import ( "context" + "time" "github.com/cerberauth/x/analyticsx" + "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp" sdktrace "go.opentelemetry.io/otel/sdk/trace" ) @@ -14,9 +16,13 @@ func NewAnalytics(ctx context.Context, projectVersion string) (*sdktrace.TracerP tracerProvider, err = analyticsx.NewAnalytics(ctx, analyticsx.AppInfo{ Name: "vulnapi", Version: projectVersion, - }) + }, otlptracehttp.WithTimeout(time.Second*2), otlptracehttp.WithRetry(otlptracehttp.RetryConfig{Enabled: false})) if err != nil { return nil, err } return tracerProvider, err } + +func Close() { + tracerProvider.Shutdown(context.Background()) +}