Compare commits

...

1 Commits
main ... otelq

Author SHA1 Message Date
William Perron 88892a8e3d
wip: add otelq cmd
12 months ago

@ -0,0 +1,3 @@
# Otelq
Like `jq` or `yq`, but for OpenTelemetry data.

@ -0,0 +1,48 @@
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
}

@ -3,6 +3,7 @@ module go.wperron.io/toolkit
go 1.20
require (
github.com/golang/protobuf v1.5.2
github.com/grafana/tempo v1.5.0
github.com/stretchr/testify v1.8.4
go.opentelemetry.io/otel/sdk v1.14.0
@ -14,7 +15,6 @@ require (
github.com/cenkalti/backoff/v4 v4.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.14.0 // indirect

Loading…
Cancel
Save