Added basic tracing for oauth
@@ -4,6 +4,7 @@ import (
"net/http"
"github.com/hellofresh/janus/pkg/errors"
+ "github.com/hellofresh/janus/pkg/opentracing"
"github.com/hellofresh/janus/pkg/request"
"github.com/hellofresh/janus/pkg/response"
"github.com/hellofresh/janus/pkg/router"
@@ -21,7 +22,10 @@ func NewController(repo Repository) *Controller {
func (c *Controller) Get() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
+ span := opentracing.FromContext(r.Context(), "datastore.FindAll")
data, err := c.repo.FindAll()
+ span.Finish()
+
if err != nil {
panic(err.Error())
}
@@ -34,7 +38,10 @@ func (c *Controller) Get() http.HandlerFunc {
func (c *Controller) GetBy() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
name := router.FromContext(r.Context()).ByName("name")
+ span := opentracing.FromContext(r.Context(), "datastore.FindByName")
data, err := c.repo.FindByName(name)
+ span.Finish()
+
if data.Name == "" {
panic(ErrOauthServerNotFound)
}
@@ -50,9 +57,12 @@ func (c *Controller) GetBy() http.HandlerFunc {
func (c *Controller) PutBy() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var err error
-
name := router.FromContext(r.Context()).ByName("name")
+
+ span := opentracing.FromContext(r.Context(), "datastore.FindByName")
oauth, err := c.repo.FindByName(name)
+ span.Finish()
+
if oauth.Name == "" {
panic(ErrOauthServerNotFound)
}
@@ -66,7 +76,10 @@ func (c *Controller) PutBy() http.HandlerFunc {
panic(errors.New(http.StatusInternalServerError, err.Error()))
}
+ span = opentracing.FromContext(r.Context(), "datastore.Add")
err = c.repo.Add(oauth)
+ span.Finish()
+
if nil != err {
panic(errors.New(http.StatusBadRequest, err.Error()))
}
@@ -84,7 +97,10 @@ func (c *Controller) Post() http.HandlerFunc {
panic(errors.New(http.StatusInternalServerError, err.Error()))
}
+ span := opentracing.FromContext(r.Context(), "datastore.Add")
err = c.repo.Add(&oauth)
+ span.Finish()
+
if nil != err {
panic(errors.New(http.StatusBadRequest, err.Error()))
}
@@ -97,7 +113,10 @@ func (c *Controller) DeleteBy() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
id := router.FromContext(r.Context()).ByName("id")
+ span := opentracing.FromContext(r.Context(), "datastore.Remove")
err := c.repo.Remove(id)
+ span.Finish()
+
if err != nil {
panic(errors.New(http.StatusInternalServerError, err.Error()))
}
