Skip to content

Commit 64e009e

Browse files
committed
Added reporter middleware
Signed-off-by: Vishal Rana <[email protected]>
1 parent 67b7ae8 commit 64e009e

File tree

3 files changed

+117
-9
lines changed

3 files changed

+117
-9
lines changed

website/content/middleware/cube.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
+++
2-
date = "2014-09-09"
2+
title = "Cube Middleware"
33
description = "Cube middleware for Echo. It provides HTTP analytics."
44
[menu.main]
55
name = "Cube"
@@ -26,7 +26,7 @@ import (
2626

2727
```go
2828
e := echo.New()
29-
e.Use(cube.Middleware("<YOUR_API_KEY>"))
29+
e.Use(cube.Middleware("<ACCOUNT_ID>", "<API_KEY>"))
3030
```
3131

3232
## Custom Configuration
@@ -36,7 +36,8 @@ e.Use(cube.Middleware("<YOUR_API_KEY>"))
3636
```go
3737
e := echo.New()
3838
e.Use(cube.MiddlewareWithConfig(cube.Config{
39-
APIKey: "<YOUR_API_KEY>",
39+
AccountID: "<ACCOUNT_ID>",
40+
APIKey: "<API_KEY>",
4041
DispatchInterval: 5 * 60, // 5 minutes
4142
}))
4243
```
@@ -47,13 +48,16 @@ e.Use(cube.MiddlewareWithConfig(cube.Config{
4748
// Config defines the config for Cube middleware.
4849
Config struct {
4950
// Skipper defines a function to skip middleware.
50-
Skipper Skipper
51+
Skipper middleware.Skipper
5152

52-
// App ID
53-
AppID string `json:"app_id"`
53+
// App ID
54+
AppID string
5455

55-
// App name
56-
AppName string `json:"app_name"`
56+
// App name
57+
AppName string
58+
59+
// LabStack Account ID
60+
AccountID string `json:"account_id"`
5761

5862
// LabStack API key
5963
APIKey string `json:"api_key"`
@@ -64,6 +68,7 @@ Config struct {
6468
// Interval in seconds to dispatch the batch
6569
DispatchInterval time.Duration `json:"dispatch_interval"`
6670

71+
// TODO: To be implemented
6772
ClientLookup string `json:"client_lookup"`
6873
}
6974
```
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
+++
2+
title = "Reporter Middleware"
3+
description = "Reporter middleware for Echo. It provides error reporting using LabStack log service."
4+
[menu.main]
5+
name = "Reporter"
6+
parent = "middleware"
7+
+++
8+
9+
10+
Reporter provides automatic error reporting and notification using the LabStack platform.
11+
12+
API key: https://labstack.com/signup<br>
13+
Dashboard access: https://labstack.com/log
14+
15+
> Echo community contribution
16+
17+
## Dependencies
18+
19+
```go
20+
import (
21+
"github.com/labstack/echo-contrib/reporter"
22+
)
23+
```
24+
25+
*Usage*
26+
27+
```go
28+
e := echo.New()
29+
e.Use(reporter.Middleware("<ACCOUNT_ID>", "<API_KEY>"))
30+
```
31+
32+
## Custom Configuration
33+
34+
*Usage*
35+
36+
```go
37+
e := echo.New()
38+
e.Use(reporter.MiddlewareWithConfig(reporter.Config{
39+
AccountID: "<ACCOUNT_ID>",
40+
APIKey: "<API_KEY>",
41+
Headers: []string{"User-Agent"}, // Headers to include
42+
}))
43+
```
44+
45+
## Configuration
46+
47+
```go
48+
// Config defines the config for Reporter middleware.
49+
Config struct {
50+
// Skipper defines a function to skip middleware.
51+
Skipper middleware.Skipper
52+
53+
// App ID
54+
AppID string
55+
56+
// App name
57+
AppName string
58+
59+
// LabStack Account ID
60+
AccountID string `json:"account_id"`
61+
62+
// LabStack API key
63+
APIKey string `json:"api_key"`
64+
65+
// Headers to include
66+
Headers []string `json:"headers"`
67+
68+
// TODO: To be implemented
69+
ClientLookup string `json:"client_lookup"`
70+
}
71+
```
72+
73+
[Learn more](https://labstack.com/docs/log)
74+
75+
*Default Configuration*
76+
77+
```go
78+
// DefaultConfig is the default Reporter middleware config.
79+
DefaultConfig = Config{
80+
Skipper: middleware.DefaultSkipper,
81+
}
82+
```
83+
84+
## Alert Policy
85+
86+
Navigate to https://labstack.com/monitor/new to create an alert policy with the following data:
87+
88+
- Name: <POLICY_NAME>
89+
- Query String: app_name: <APP_NAME> AND level:FATAL
90+
- Email: <EMAIL>
91+
- Message:
92+
93+
```html
94+
Message: {{ message }}
95+
Stack Trace: {{ stack_trace }}
96+
```
97+
98+
> Leave rest of the fields as is.

website/layouts/partials/notice.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
<div class="w3-panel w3-pale-green w3-leftbar w3-border-green">
1+
<!-- <div class="w3-panel w3-pale-green w3-leftbar w3-border-green">
22
<p>
33
Check out <a href="/middleware/cube">cube middleware</a> for HTTP analytics. Measure server latency, data transfer, discover top endpoints, server errors and much more.
44
</p>
5+
</div> -->
6+
<div class="w3-panel w3-pale-green w3-leftbar w3-border-green">
7+
<p>
8+
Check out <a href="/middleware/reporter">reporter middleware</a> for automatic error reporting and notification.
9+
</p>
510
</div>

0 commit comments

Comments
 (0)