feat: add traces to ofrep endpoint (#1593)
Signed-off-by: Simon Schrottner <simon.schrottner@dynatrace.com>
This commit is contained in:
parent
11db29dc3a
commit
a5d43bc1de
|
|
@ -11,6 +11,9 @@ import (
|
||||||
"github.com/open-feature/flagd/core/pkg/model"
|
"github.com/open-feature/flagd/core/pkg/model"
|
||||||
"github.com/open-feature/flagd/core/pkg/service/ofrep"
|
"github.com/open-feature/flagd/core/pkg/service/ofrep"
|
||||||
"github.com/rs/xid"
|
"github.com/rs/xid"
|
||||||
|
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
||||||
|
"go.opentelemetry.io/otel"
|
||||||
|
"go.opentelemetry.io/otel/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -23,6 +26,7 @@ type handler struct {
|
||||||
Logger *logger.Logger
|
Logger *logger.Logger
|
||||||
evaluator evaluator.IEvaluator
|
evaluator evaluator.IEvaluator
|
||||||
contextValues map[string]any
|
contextValues map[string]any
|
||||||
|
tracer trace.Tracer
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewOfrepHandler(logger *logger.Logger, evaluator evaluator.IEvaluator, contextValues map[string]any) http.Handler {
|
func NewOfrepHandler(logger *logger.Logger, evaluator evaluator.IEvaluator, contextValues map[string]any) http.Handler {
|
||||||
|
|
@ -30,12 +34,13 @@ func NewOfrepHandler(logger *logger.Logger, evaluator evaluator.IEvaluator, cont
|
||||||
Logger: logger,
|
Logger: logger,
|
||||||
evaluator: evaluator,
|
evaluator: evaluator,
|
||||||
contextValues: contextValues,
|
contextValues: contextValues,
|
||||||
|
tracer: otel.Tracer("flagd.ofrep.v1"),
|
||||||
}
|
}
|
||||||
|
|
||||||
router := mux.NewRouter()
|
router := mux.NewRouter()
|
||||||
router.HandleFunc(singleEvaluation, h.HandleFlagEvaluation).Methods("POST")
|
router.HandleFunc(singleEvaluation, h.HandleFlagEvaluation).Methods("POST")
|
||||||
router.HandleFunc(bulkEvaluation, h.HandleBulkEvaluation).Methods("POST")
|
router.HandleFunc(bulkEvaluation, h.HandleBulkEvaluation).Methods("POST")
|
||||||
return router
|
return otelhttp.NewHandler(router, "flagd.ofrep")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *handler) HandleFlagEvaluation(w http.ResponseWriter, r *http.Request) {
|
func (h *handler) HandleFlagEvaluation(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
@ -57,7 +62,6 @@ func (h *handler) HandleFlagEvaluation(w http.ResponseWriter, r *http.Request) {
|
||||||
h.writeJSONToResponse(http.StatusBadRequest, ofrep.ContextErrorResponseFrom(flagKey), w)
|
h.writeJSONToResponse(http.StatusBadRequest, ofrep.ContextErrorResponseFrom(flagKey), w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
context := flagdContext(h.Logger, requestID, request, h.contextValues)
|
context := flagdContext(h.Logger, requestID, request, h.contextValues)
|
||||||
evaluation := h.evaluator.ResolveAsAnyValue(r.Context(), requestID, flagKey, context)
|
evaluation := h.evaluator.ResolveAsAnyValue(r.Context(), requestID, flagKey, context)
|
||||||
if evaluation.Error != nil {
|
if evaluation.Error != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue