You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
toolkit/cmd/otelq/main.go

49 lines
812 B

package main
import (
"flag"
"fmt"
"io"
"log"
"os"
tracev1 "go.opentelemetry.io/proto/otlp/trace/v1"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
)
var (
file = flag.String("file", "", "OpenTelemetry proto file. if set, will not use stdin.")
)
func main() {
flag.Parse()
if *file != "" {
fmt.Fprintf(os.Stderr, "reading file %s\n", *file)
h := must(os.Open(*file))
bs := must(io.ReadAll(h))
var td tracev1.TracesData
if err := proto.Unmarshal(bs, &td); err != nil {
log.Fatalln(err)
}
jsonbs, err := protojson.Marshal(&td)
if err != nil {
log.Fatalln(err)
}
fmt.Fprint(os.Stdout, string(jsonbs))
} else {
fmt.Println("using stdin")
}
}
func must[T any](v T, err error) T {
if err != nil {
log.Fatalln(err)
}
return v
}