We can use span.Error directly!
@@ -4,6 +4,7 @@ import (
"compress/zlib"
"context"
"encoding/json"
+ "errors"
"fmt"
"io"
"net/http"
@@ -47,7 +48,7 @@ func handleImport(s *Server) http.Handler {
body, err = zlib.NewReader(r.Body)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
- //trace.Error(err)
+ span.Error(err)
encLogger.WithError(err).Error("Could not read compressed request body")
s.statsd.Count("import.request_error_total", 1, []string{"cause:deflate"}, 1.0)
return
@@ -55,7 +56,7 @@ func handleImport(s *Server) http.Handler {
defer body.Close()
default:
http.Error(w, encoding, http.StatusUnsupportedMediaType)
- //trace.Error(errors.New("Could not determine content-encoding of request"))
+ span.Error(errors.New("Could not determine content-encoding of request"))
encLogger.Error("Could not determine content-encoding of request")
s.statsd.Count("import.request_error_total", 1, []string{"cause:unknown_content_encoding"}, 1.0)
return
@@ -63,7 +64,7 @@ func handleImport(s *Server) http.Handler {
if err = json.NewDecoder(body).Decode(&jsonMetrics); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
- //trace.Error(err)
+ span.Error(err)
innerLogger.WithError(err).Error("Could not decode /import request")
s.statsd.Count("import.request_error_total", 1, []string{"cause:json"}, 1.0)
return
@@ -72,7 +73,7 @@ func handleImport(s *Server) http.Handler {
if len(jsonMetrics) == 0 {
const msg = "Received empty /import request"
http.Error(w, msg, http.StatusBadRequest)
- //trace.Error(errors.New(msg))
+ span.Error(errors.New(msg))
innerLogger.WithError(err).Error(msg)
return
}
@@ -85,7 +86,7 @@ func handleImport(s *Server) http.Handler {
if !s.nonEmpty(span.Attach(ctx), jsonMetrics) {
const msg = "Received empty or improperly-formed metrics"
http.Error(w, msg, http.StatusBadRequest)
- //trace.Error(errors.New(msg))
+ span.Error(errors.New(msg))
innerLogger.Error(msg)
return
}
