-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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 endpoints to allow uploading OTLP traces #5138
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -17,8 +17,10 @@ package apiv3 | |||||||
import ( | ||||||||
"fmt" | ||||||||
|
||||||||
"github.com/gogo/protobuf/jsonpb" | ||||||||
"github.com/gogo/protobuf/proto" | ||||||||
model2otel "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger" | ||||||||
"go.opentelemetry.io/collector/pdata/ptrace" | ||||||||
"go.opentelemetry.io/collector/pdata/ptrace/ptraceotlp" | ||||||||
|
||||||||
"github.com/jaegertracing/jaeger/model" | ||||||||
|
@@ -45,3 +47,26 @@ func modelToOTLP(spans []*model.Span) ([]*tracev1.ResourceSpans, error) { | |||||||
} | ||||||||
return chunk.ResourceSpans, nil | ||||||||
} | ||||||||
|
||||||||
func OTLP2model(OTLPSpans []byte) ([]model.Trace, error) { | ||||||||
ptrace_unmarshaler := ptrace.JSONUnmarshaler{} | ||||||||
otlp_traces, err := ptrace_unmarshaler.UnmarshalTraces(OTLPSpans) | ||||||||
if err != nil { | ||||||||
fmt.Println(err) | ||||||||
return nil, fmt.Errorf("cannot marshal OTLP : %w", err) | ||||||||
Comment on lines
+55
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
} | ||||||||
batches, err := model2otel.ProtoFromTraces(otlp_traces) | ||||||||
fmt.Println(otlp_traces.ResourceSpans()) | ||||||||
if err != nil { | ||||||||
fmt.Println(err) | ||||||||
return nil, fmt.Errorf("cannot marshal OTLP : %w", err) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
} | ||||||||
jaeger_traces := make([]model.Trace, len(batches) ) | ||||||||
for _, v := range batches { | ||||||||
mar := jsonpb.Marshaler{} | ||||||||
fmt.Println(mar.MarshalToString(v)) | ||||||||
jaeger_trace := v.ConvertToTraces() | ||||||||
jaeger_traces = append(jaeger_traces, *jaeger_trace) | ||||||||
} | ||||||||
return jaeger_traces, nil | ||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ import ( | |
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
"net/url" | ||
"strconv" | ||
|
@@ -31,6 +32,7 @@ import ( | |
"go.opentelemetry.io/otel/propagation" | ||
"go.uber.org/zap" | ||
|
||
"github.com/jaegertracing/jaeger/cmd/query/app/apiv3" | ||
"github.com/jaegertracing/jaeger/cmd/query/app/querysvc" | ||
"github.com/jaegertracing/jaeger/model" | ||
uiconv "github.com/jaegertracing/jaeger/model/converter/json" | ||
|
@@ -121,6 +123,7 @@ func NewAPIHandler(queryService *querysvc.QueryService, tm *tenancy.Manager, opt | |
// RegisterRoutes registers routes for this handler on the given router | ||
func (aH *APIHandler) RegisterRoutes(router *mux.Router) { | ||
aH.handleFunc(router, aH.getTrace, "/traces/{%s}", traceIDParam).Methods(http.MethodGet) | ||
aH.handleFunc(router, aH.transformOTLP, "/transform").Methods(http.MethodPost) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please move down, after |
||
aH.handleFunc(router, aH.archiveTrace, "/archive/{%s}", traceIDParam).Methods(http.MethodPost) | ||
aH.handleFunc(router, aH.search, "/traces").Methods(http.MethodGet) | ||
aH.handleFunc(router, aH.getServices, "/services").Methods(http.MethodGet) | ||
|
@@ -158,6 +161,39 @@ func (aH *APIHandler) formatRoute(route string, args ...interface{}) string { | |
return fmt.Sprintf("/%s"+route, args...) | ||
} | ||
|
||
func (aH *APIHandler) transformOTLP(w http.ResponseWriter, r *http.Request) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please move the function to a place in the file so that it reflects its relative position in RegisterRoutes |
||
body, err := ioutil.ReadAll(r.Body) | ||
if aH.handleError(w, err, http.StatusBadRequest) { | ||
return | ||
} | ||
|
||
if aH.handleError(w, err, http.StatusInternalServerError) { | ||
return | ||
} | ||
Comment on lines
+166
to
+172
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. only one of these is needed |
||
var uiErrors []structuredError | ||
traces, err := apiv3.OTLP2model(body) | ||
|
||
if aH.handleError(w, err, http.StatusInternalServerError) { | ||
return | ||
} | ||
|
||
uiTraces := make([]*ui.Trace, len(traces)) | ||
for i, v := range traces { | ||
uiTrace, uiErr := aH.convertModelToUI(&v, false) | ||
if uiErr != nil { | ||
uiErrors = append(uiErrors, *uiErr) | ||
} | ||
uiTraces[i] = uiTrace | ||
} | ||
|
||
structuredRes := structuredResponse{ | ||
Data: uiTraces, | ||
Errors: uiErrors, | ||
} | ||
aH.writeJSON(w,r,structuredRes) | ||
|
||
} | ||
|
||
func (aH *APIHandler) getServices(w http.ResponseWriter, r *http.Request) { | ||
services, err := aH.queryService.GetServices(r.Context()) | ||
if aH.handleError(w, err, http.StatusInternalServerError) { | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same applies to
jaeger_traces
andjaeger_traces
context: https://go.dev/doc/effective_go#mixed-caps