Skip to content

Commit

Permalink
feat: support protobuf format in tempo HTTP protocol (#3562)
Browse files Browse the repository at this point in the history
  • Loading branch information
mathnogueira authored Jan 25, 2024
1 parent 81201d7 commit 71bcf62
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions server/tracedb/tempodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/http"
"strings"

"github.com/golang/protobuf/proto"
"github.com/kubeshop/tracetest/server/datastore"
tempopb "github.com/kubeshop/tracetest/server/internal/proto-gen-go/tempo-idl"
"github.com/kubeshop/tracetest/server/model"
Expand Down Expand Up @@ -144,6 +145,19 @@ func httpGetTraceByID(ctx context.Context, traceID string, client *datasource.Ht
return traces.Trace{}, fmt.Errorf("tempo err: %w %s", errors.New("authentication handshake failed"), string(body))
}

if contentTypeAcceptsType(resp, "application/protobuf") {
var protoMessage tempopb.Trace
err = proto.Unmarshal(body, &protoMessage)
if err != nil {
return traces.Trace{}, err
}

trace := &v1.TracesData{
ResourceSpans: protoMessage.GetBatches(),
}

return traces.FromOtel(trace), nil
}
var trace HttpTempoTraceByIDResponse
err = json.Unmarshal(body, &trace)
if err != nil {
Expand All @@ -167,3 +181,13 @@ func handleError(err error) error {

return nil
}

func contentTypeAcceptsType(resp *http.Response, accept string) bool {
for _, headerValue := range resp.Header["Content-Type"] {
if headerValue == accept {
return true
}
}

return false
}

0 comments on commit 71bcf62

Please sign in to comment.