generated from datumforge/go-template
-
Notifications
You must be signed in to change notification settings - Fork 7
/
helpers.go
50 lines (37 loc) · 1 KB
/
helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package sentry
import (
"strings"
echo "github.com/datumforge/echox"
"github.com/getsentry/sentry-go"
)
func prepareTagValue(str string) string {
size := 200 // limit of sentry
str = strings.ReplaceAll(str, "\n", " ") // no \n in strings
result := []rune(str)
if len(result) <= size {
return str
}
return string(result[:size-3]) + "..."
}
func prepareTagName(str string) string {
size := 32 // limit of sentry
result := []rune(str)
if len(result) <= size {
return str
}
return string(result[:size])
}
func setTag(span *sentry.Span, tag, value string) {
if tag == "" || value == "" {
return
}
span.SetTag(prepareTagName(tag), prepareTagValue(value))
}
func getRequestID(ctx echo.Context) string {
requestID := ctx.Request().Header.Get(echo.HeaderXRequestID) // request-id generated by reverse-proxy
if requestID == "" {
// missed request-id from proxy, got generated one by middleware.RequestID()
requestID = ctx.Response().Header().Get(echo.HeaderXRequestID)
}
return requestID
}