mirror of
https://github.com/hanzoai/traces.git
synced 2026-10-30 18:20:41 +00:00
* Migrate from OpenTracing to OpenTelemetry instrumentation Signed-off-by: Andreas Gerstmayr <[email protected]> * update dskit to c41c58734f46 Signed-off-by: Andreas Gerstmayr <[email protected]> * switch to exporters/autoexport, update docs and examples Signed-off-by: Andreas Gerstmayr <[email protected]> * update dependencies Signed-off-by: Andreas Gerstmayr <[email protected]> * refactor added code from opentracing to OTEL SDK Signed-off-by: Andreas Gerstmayr <[email protected]> * move the changelog entry to the correct version Signed-off-by: Andreas Gerstmayr <[email protected]> * run go mod tidy Signed-off-by: Andreas Gerstmayr <[email protected]> * align tracer name with pkg name, some fixes Signed-off-by: Andreas Gerstmayr <[email protected]> * update cmd/tempo-query/tempo tracer name Signed-off-by: Andreas Gerstmayr <[email protected]> * update changelog, enable tracing if OTEL_TRACES_EXPORTER is set Signed-off-by: Andreas Gerstmayr <[email protected]> --------- Signed-off-by: Andreas Gerstmayr <[email protected]>
76 lines
1.9 KiB
Go
76 lines
1.9 KiB
Go
package generator
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/gogo/protobuf/jsonpb"
|
|
"go.opentelemetry.io/otel/attribute"
|
|
|
|
"github.com/grafana/tempo/pkg/api"
|
|
"github.com/grafana/tempo/pkg/tempopb"
|
|
)
|
|
|
|
func (g *Generator) SpanMetricsHandler(w http.ResponseWriter, r *http.Request) {
|
|
ctx, cancel := context.WithDeadline(r.Context(), time.Now().Add(g.cfg.QueryTimeout))
|
|
defer cancel()
|
|
|
|
ctx, span := tracer.Start(ctx, "Generator.SpanMetricsHandler")
|
|
defer span.End()
|
|
|
|
span.SetAttributes(attribute.String("requestURI", r.RequestURI))
|
|
|
|
req, err := api.ParseSpanMetricsRequest(r)
|
|
if err != nil {
|
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
var resp *tempopb.SpanMetricsResponse
|
|
resp, err = g.GetMetrics(ctx, req)
|
|
if err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
marshaller := &jsonpb.Marshaler{}
|
|
err = marshaller.Marshal(w, resp)
|
|
if err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
w.Header().Set(api.HeaderContentType, api.HeaderAcceptJSON)
|
|
}
|
|
|
|
func (g *Generator) QueryRangeHandler(w http.ResponseWriter, r *http.Request) {
|
|
ctx, cancel := context.WithDeadline(r.Context(), time.Now().Add(g.cfg.QueryTimeout))
|
|
defer cancel()
|
|
|
|
ctx, span := tracer.Start(ctx, "Generator.QueryRangeHandler")
|
|
defer span.End()
|
|
|
|
span.SetAttributes(attribute.String("requestURI", r.RequestURI))
|
|
|
|
req, err := api.ParseQueryRangeRequest(r)
|
|
if err != nil {
|
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
var resp *tempopb.QueryRangeResponse
|
|
resp, err = g.QueryRange(ctx, req)
|
|
if err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
marshaller := &jsonpb.Marshaler{}
|
|
err = marshaller.Marshal(w, resp)
|
|
if err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
w.Header().Set(api.HeaderContentType, api.HeaderAcceptJSON)
|
|
}
|