Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add verbose, name filter flags #1

Merged
merged 1 commit into from
Mar 28, 2023
Merged
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
18 changes: 17 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package main

import (
"flag"
"fmt"
"io/ioutil"
"log"
"net/http"
"strings"

"github.com/davecgh/go-spew/spew"
"github.com/vmihailenco/msgpack/v5"
@@ -41,6 +43,10 @@ type Trace []Span
type Traces []Trace

func main() {
verbose := flag.Bool("verbose", false, "verbose mode outputs all information available for each span")
nameFilter := flag.String("name", "", "filter spans by name (must include the given string value). Not usable with verbose mode.")
flag.Parse()

traceHandler := func(w http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(r.Body)
if err != nil {
@@ -55,7 +61,17 @@ func main() {
if err != nil {
log.Println("Failed to unpack traces")
}
log.Println(spew.Sdump(traces))
if *verbose {
log.Println(spew.Sdump(traces))
} else {
for _, trace := range traces {
for _, span := range trace {
if *nameFilter == "" || strings.Contains(span.Name, *nameFilter) {
log.Printf("%s\n\033[34m%s\033[0m\n", span.Name, span.Resource)
}
}
}
}
fmt.Fprintf(w, "OK")
}