예제 #1
0
func (wr wrapper) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	startTime, tracer, headers := wr.dps.BeforeRequest(w, req)

	defer func() {
		if err := recover(); err != nil {
			wr.dps.BaseClient.Prep(err, tracer.SpanId)
			wr.dps.AfterRequest(startTime, tracer, req, headers, 500, true)

			errorMsg := fmt.Sprintf("%v", err)
			deferstats.WritePanicResponse(w, req, errorMsg)
		}
	}()

	wr.handler.ServeHTTP(tracer, req)

	wr.dps.AfterRequest(startTime, tracer, req, headers, tracer.Status(), false)
}
예제 #2
0
// HTTPContextHandler wraps a http handler and captures the latency of each
// request
// this currently happens in a global list :( - TBFS
func (wrapper *Wrapper) HTTPContextHandler(f ContextHandler) ContextHandler {
	return ContextHandlerFunc(func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
		startTime, ext, tracer, headers := wrapper.Dps.ContextBeforeRequest(w, r)
		ctx = context.WithValue(ctx, "ContextTracer", tracer)

		defer func() {
			if err := recover(); err != nil {
				wrapper.Dps.BaseClient.Prep(err, tracer.SpanId)
				wrapper.Dps.ContextAfterRequest(startTime, tracer, r, headers, 500, true)

				errorMsg := fmt.Sprintf("%v", err)
				deferstats.WritePanicResponse(w, r, errorMsg)
			}
		}()

		f.ServeHTTPContext(ctx, ext, r)

		wrapper.Dps.ContextAfterRequest(startTime, tracer, r, headers, ext.Status(), false)
	})
}
예제 #3
0
// Wrapper is a Martini middleware to wrap handler execution and post to a
// Defer Panic dashboard
func Wrapper(dps *deferstats.Client) martini.Handler {
	return func(w http.ResponseWriter, r *http.Request, c martini.Context) {
		startTime, tracer, headers := dps.BeforeRequest(w, r)

		defer func() {
			if err := recover(); err != nil {
				dps.BaseClient.Prep(err, tracer.SpanId)
				dps.AfterRequest(startTime, tracer, r, headers, 500, true)

				errorMsg := fmt.Sprintf("%v", err)
				deferstats.WritePanicResponse(w, r, errorMsg)
			}
		}()

		c.MapTo(tracer, (*http.ResponseWriter)(nil))
		c.Next()

		dps.AfterRequest(startTime, tracer, r, headers, tracer.Status(), false)
	}
}
예제 #4
0
// Wrapper is a Revel middleware to wrap handler execution and post to a
// Defer Panic dashboard
func Wrapper(dps *deferstats.Client) func(c *revel.Controller, fc []revel.Filter) {
	return func(c *revel.Controller, fc []revel.Filter) {
		startTime, tracer, headers := dps.BeforeRequest(c.Response.Out, c.Request.Request)

		defer func() {
			if err := recover(); err != nil {
				dps.BaseClient.Prep(err, tracer.SpanId)
				dps.AfterRequest(startTime, tracer, c.Request.Request, headers, 500, true)

				errorMsg := fmt.Sprintf("%v", err)
				deferstats.WritePanicResponse(c.Response.Out, c.Request.Request, errorMsg)
			}
		}()

		c.Response.Out = tracer
		fc[0](c, fc[1:])

		dps.AfterRequest(startTime, tracer, c.Request.Request, headers, tracer.Status(), false)
	}
}
예제 #5
0
// Wrapper is a Echo middleware to wrap handler execution and post to a
// Defer Panic dashboard
func Wrapper(dps *deferstats.Client) echo.MiddlewareFunc {
	return func(h echo.HandlerFunc) echo.HandlerFunc {
		return func(c *echo.Context) error {
			startTime, tracer, headers := dps.BeforeRequest(c.Response().Writer(), c.Request())

			defer func() {
				if err := recover(); err != nil {
					dps.BaseClient.Prep(err, tracer.SpanId)
					dps.AfterRequest(startTime, tracer, c.Request(), headers, 500, true)

					errorMsg := fmt.Sprintf("%v", err)
					deferstats.WritePanicResponse(c.Response().Writer(), c.Request(), errorMsg)
				}
			}()
			c.Response().SetWriter(tracer)
			if err := h(c); err != nil {
				c.Error(err)
			}

			dps.AfterRequest(startTime, tracer, c.Request(), headers, tracer.Status(), false)
			return nil
		}
	}
}