Skip to content

Commit f6665f1

Browse files
committed
Dropped reporter, updated cube
Signed-off-by: Vishal Rana <[email protected]>
1 parent 013857e commit f6665f1

File tree

5 files changed

+41
-138
lines changed

5 files changed

+41
-138
lines changed

Gopkg.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
[[constraint]]
3737
name = "github.com/labstack/labstack-go"
38-
version = "0.7.2"
38+
version = "0.8.2"
3939

4040
[[constraint]]
4141
name = "github.com/stretchr/testify"

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@ Name | Description | Author
1212
--- | --- | ---
1313
[casbin](https://github.com/casbin/casbin) | Access control library | [hsluoyz](https://github.com/hsluoyz)
1414
[cube](https://labstack.com/docs/cube) | HTTP analytics | [vishr](https://github.com/vishr)
15-
[reporter](https://labstack.com/docs/log) | Error reporting | [vishr](https://github.com/vishr)
1615
session | Session middleware backed by [gorilla/sessions](https://github.com/gorilla/sessions) | [vishr](https://github.com/vishr)

cube/cube.go

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package cube
22

33
import (
4+
"fmt"
5+
"net/http"
6+
"runtime"
47
"time"
58

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

17-
// App ID
18-
AppID string
19-
20-
// App name
21-
AppName string
22-
2320
// LabStack Account ID
2421
AccountID string `json:"account_id"`
2522

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

32+
// Additional tags
33+
Tags []string `json:"tags"`
34+
3535
// TODO: To be implemented
3636
ClientLookup string `json:"client_lookup"`
3737
}
@@ -74,8 +74,6 @@ func MiddlewareWithConfig(config Config) echo.MiddlewareFunc {
7474
// Initialize
7575
client := labstack.NewClient(config.AccountID, config.APIKey)
7676
cube := client.Cube()
77-
cube.AppID = config.AppID
78-
cube.AppName = config.AppName
7977
cube.APIKey = config.APIKey
8078
cube.BatchSize = config.BatchSize
8179
cube.DispatchInterval = config.DispatchInterval
@@ -86,12 +84,39 @@ func MiddlewareWithConfig(config Config) echo.MiddlewareFunc {
8684
if config.Skipper(c) {
8785
return next(c)
8886
}
89-
r := cube.Start(c.Request(), c.Response())
87+
88+
// Start
89+
cr := cube.Start(c.Request(), c.Response())
90+
91+
// Handle panic
92+
defer func() {
93+
if r := recover(); r != nil {
94+
switch r := r.(type) {
95+
case error:
96+
err = r
97+
default:
98+
err = fmt.Errorf("%v", r)
99+
}
100+
stack := make([]byte, 4<<10) // 4 KB
101+
length := runtime.Stack(stack, false)
102+
cr.Error = err.Error()
103+
cr.StackTrace = string(stack[:length])
104+
println(c.Response().Status)
105+
if c.Response().Status == http.StatusOK {
106+
c.Response().Status = http.StatusInternalServerError
107+
}
108+
}
109+
110+
// Stop
111+
cube.Stop(cr, c.Response().Status, c.Response().Size)
112+
}()
113+
114+
// Next
90115
if err = next(c); err != nil {
91116
c.Error(err)
92117
}
93-
cube.Stop(r, c.Response().Status, c.Response().Size)
94-
return
118+
119+
return nil
95120
}
96121
}
97122
}

reporter/reporter.go

Lines changed: 0 additions & 121 deletions
This file was deleted.

0 commit comments

Comments
 (0)