Skip to content

Commit

Permalink
Dropped reporter, updated cube
Browse files Browse the repository at this point in the history
Signed-off-by: Vishal Rana <[email protected]>
  • Loading branch information
vishr committed Sep 20, 2017
1 parent 013857e commit f6665f1
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 138 deletions.
8 changes: 4 additions & 4 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

[[constraint]]
name = "github.com/labstack/labstack-go"
version = "0.7.2"
version = "0.8.2"

[[constraint]]
name = "github.com/stretchr/testify"
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ Name | Description | Author
--- | --- | ---
[casbin](https://github.com/casbin/casbin) | Access control library | [hsluoyz](https://github.com/hsluoyz)
[cube](https://labstack.com/docs/cube) | HTTP analytics | [vishr](https://github.com/vishr)
[reporter](https://labstack.com/docs/log) | Error reporting | [vishr](https://github.com/vishr)
session | Session middleware backed by [gorilla/sessions](https://github.com/gorilla/sessions) | [vishr](https://github.com/vishr)
47 changes: 36 additions & 11 deletions cube/cube.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package cube

import (
"fmt"
"net/http"
"runtime"
"time"

"github.com/labstack/echo"
Expand All @@ -14,12 +17,6 @@ type (
// Skipper defines a function to skip middleware.
Skipper middleware.Skipper

// App ID
AppID string

// App name
AppName string

// LabStack Account ID
AccountID string `json:"account_id"`

Expand All @@ -32,6 +29,9 @@ type (
// Interval in seconds to dispatch the batch
DispatchInterval time.Duration `json:"dispatch_interval"`

// Additional tags
Tags []string `json:"tags"`

// TODO: To be implemented
ClientLookup string `json:"client_lookup"`
}
Expand Down Expand Up @@ -74,8 +74,6 @@ func MiddlewareWithConfig(config Config) echo.MiddlewareFunc {
// Initialize
client := labstack.NewClient(config.AccountID, config.APIKey)
cube := client.Cube()
cube.AppID = config.AppID
cube.AppName = config.AppName
cube.APIKey = config.APIKey
cube.BatchSize = config.BatchSize
cube.DispatchInterval = config.DispatchInterval
Expand All @@ -86,12 +84,39 @@ func MiddlewareWithConfig(config Config) echo.MiddlewareFunc {
if config.Skipper(c) {
return next(c)
}
r := cube.Start(c.Request(), c.Response())

// Start
cr := cube.Start(c.Request(), c.Response())

// Handle panic
defer func() {
if r := recover(); r != nil {
switch r := r.(type) {
case error:
err = r
default:
err = fmt.Errorf("%v", r)
}
stack := make([]byte, 4<<10) // 4 KB
length := runtime.Stack(stack, false)
cr.Error = err.Error()
cr.StackTrace = string(stack[:length])
println(c.Response().Status)
if c.Response().Status == http.StatusOK {
c.Response().Status = http.StatusInternalServerError
}
}

// Stop
cube.Stop(cr, c.Response().Status, c.Response().Size)
}()

// Next
if err = next(c); err != nil {
c.Error(err)
}
cube.Stop(r, c.Response().Status, c.Response().Size)
return

return nil
}
}
}
121 changes: 0 additions & 121 deletions reporter/reporter.go

This file was deleted.

0 comments on commit f6665f1

Please sign in to comment.