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

@ -1,59 +0,0 @@
package gziputil
import (
"encoding/binary"
"fmt"
)
type Gzip struct {
magic []byte
cm byte
flg byte
mtime uint32
xfl byte
os byte
xlen uint16
xflds []byte
crc32 uint32
isize uint32
rest []byte
trailer []byte
}
func explainGzip(bs []byte) Gzip {
g := Gzip{
magic: bs[0:2],
cm: bs[2],
flg: bs[3],
mtime: binary.BigEndian.Uint32(bs[4:8]),
xfl: bs[8],
os: bs[9],
}
offset := 10
if g.xfl&2 == 1 {
g.xlen = binary.BigEndian.Uint16(bs[offset : offset+2])
offset += 2
g.xflds = bs[offset : offset+int(g.xlen)]
offset += int(g.xlen)
}
g.crc32 = binary.BigEndian.Uint32(bs[offset : offset+4])
offset += 4
g.isize = binary.BigEndian.Uint32(bs[offset : offset+4])
offset += 4
g.rest = bs[offset : len(bs)-8]
offset = len(bs) - 8
g.trailer = bs[offset:]
return g
}
func (g Gzip) String() string {
return fmt.Sprintf("magic=%04x cm=%02x flg=%02x mtime=%d xfl=%02x os=%02x xlen=%d crc32=%d isize=%d rest=%x trailer=%08x", g.magic, g.cm, g.flg, g.mtime, g.xfl, g.os, g.xlen, g.crc32, g.isize, g.rest, g.trailer)
}
Loading…
Cancel
Save