diff --git a/http-tracer.go b/http-tracer.go index 4078e0c..d89cc23 100644 --- a/http-tracer.go +++ b/http-tracer.go @@ -22,6 +22,7 @@ import ( "io" "io/ioutil" "net/http" + "slices" "strconv" "strings" "time" @@ -301,6 +302,16 @@ func doTrace(trace TraceInfo, backend *Backend) { return } + if globalErrorsOnly && (st.StatusCode < 400 || st.StatusCode >= 600) { + return + } + + if len(globalStatusCodes) > 0 { + if !slices.Contains(globalStatusCodes, st.StatusCode) { + return + } + } + if globalJSONEnabled { if globalDebugEnabled { buf := &bytes.Buffer{} diff --git a/main.go b/main.go index ab70460..19b40a9 100644 --- a/main.go +++ b/main.go @@ -66,6 +66,8 @@ var ( globalTrace string globalJSONEnabled bool globalConsoleDisplay bool + globalErrorsOnly bool + globalStatusCodes []int globalConnStats []*ConnStats log2 *logrus.Logger ) @@ -807,6 +809,8 @@ func sidekickMain(ctx *cli.Context) { globalQuietEnabled = ctx.GlobalBool("quiet") globalConsoleDisplay = globalLoggingEnabled || ctx.IsSet("trace") || !term.IsTerminal(int(os.Stdout.Fd())) globalDebugEnabled = ctx.GlobalBool("debug") + globalErrorsOnly = ctx.GlobalBool("errors") + globalStatusCodes = ctx.GlobalIntSlice("status-code") go func() { t := time.NewTicker(ctx.GlobalDuration("dns-ttl")) @@ -961,6 +965,14 @@ func main() { Usage: "choose custom DNS TTL value for DNS refreshes for load balanced endpoints", Value: 10 * time.Minute, }, + cli.BoolFlag{ + Name: "errors , e", + Usage: "filter out any non-error responses", + }, + cli.IntSliceFlag{ + Name: "status-code", + Usage: "filter by given status code", + }, } app.CustomAppHelpTemplate = `NAME: {{.Name}} - {{.Description}}