1
0
mirror of synced 2024-11-23 12:36:02 +03:00

add tags in sentry

This commit is contained in:
DmitryZagorulko 2018-10-12 13:39:55 +03:00 committed by Alex Lushpai
parent e4e645a075
commit bf853827a4
3 changed files with 66 additions and 24 deletions

View File

@ -67,6 +67,30 @@ func ErrorCaptureHandler(client *raven.Client, errorsStacktrace bool) ErrorHandl
"endpoint": c.Request.RequestURI, "endpoint": c.Request.RequestURI,
} }
var (
ok bool
conn Connection
)
connection, ok := c.Get("connection")
if ok {
conn = connection.(Connection)
}
b, ok := c.Get("bot")
if ok {
tags["bot"] = b.(Bot).Token
conn = *getConnectionById(b.(Bot).ConnectionID)
}
if conn.APIURL != "" {
tags["crm"] = conn.APIURL
}
if conn.ClientID != "" {
tags["clientID"] = conn.ClientID
}
if recovery != nil { if recovery != nil {
stacktrace := raven.NewStacktrace(4, 3, nil) stacktrace := raven.NewStacktrace(4, 3, nil)
recStr := fmt.Sprint(recovery) recStr := fmt.Sprint(recovery)

View File

@ -406,17 +406,7 @@ func updateBots(conn *Connection, hashSettings string) {
} }
func telegramWebhookHandler(c *gin.Context) { func telegramWebhookHandler(c *gin.Context) {
token := c.Param("token") b := c.MustGet("bot").(Bot)
b, err := getBotByToken(token)
if err != nil {
c.Error(err)
return
}
if b.ID == 0 {
c.AbortWithStatus(http.StatusOK)
return
}
conn := getConnectionById(b.ConnectionID) conn := getConnectionById(b.ConnectionID)
if !conn.Active { if !conn.Active {
@ -559,17 +549,7 @@ func telegramWebhookHandler(c *gin.Context) {
} }
func mgWebhookHandler(c *gin.Context) { func mgWebhookHandler(c *gin.Context) {
clientID := c.GetHeader("Clientid") conn := c.MustGet("connection").(Connection)
if clientID == "" {
c.AbortWithStatus(http.StatusBadRequest)
return
}
conn := getConnection(clientID)
if !conn.Active {
c.AbortWithStatus(http.StatusBadRequest)
return
}
var msg v1.WebhookRequest var msg v1.WebhookRequest
if err := c.ShouldBindJSON(&msg); err != nil { if err := c.ShouldBindJSON(&msg); err != nil {

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"net/http"
"os" "os"
"os/signal" "os/signal"
"syscall" "syscall"
@ -92,8 +93,8 @@ func setup() *gin.Engine {
r.POST("/delete-bot/", checkBotForRequest(), deleteBotHandler) r.POST("/delete-bot/", checkBotForRequest(), deleteBotHandler)
r.POST("/set-lang/", checkBotForRequest(), setLangBotHandler) r.POST("/set-lang/", checkBotForRequest(), setLangBotHandler)
r.POST("/actions/activity", activityHandler) r.POST("/actions/activity", activityHandler)
r.POST("/telegram/:token", telegramWebhookHandler) r.POST("/telegram/:token", checkBotForWebhook(), telegramWebhookHandler)
r.POST("/webhook/", mgWebhookHandler) r.POST("/webhook/", checkConnectionForWebhook(), mgWebhookHandler)
return r return r
} }
@ -147,3 +148,40 @@ func checkConnectionForRequest() gin.HandlerFunc {
c.Set("connection", conn) c.Set("connection", conn)
} }
} }
func checkConnectionForWebhook() gin.HandlerFunc {
return func(c *gin.Context) {
clientID := c.GetHeader("Clientid")
if clientID == "" {
c.AbortWithStatus(http.StatusBadRequest)
return
}
conn := getConnection(clientID)
if !conn.Active {
c.AbortWithStatus(http.StatusBadRequest)
return
}
c.Set("connection", *conn)
}
}
func checkBotForWebhook() gin.HandlerFunc {
return func(c *gin.Context) {
token := c.Param("token")
b, err := getBotByToken(token)
if err != nil {
c.Error(err)
return
}
if b.ID == 0 {
c.AbortWithStatus(http.StatusOK)
return
}
c.Set("bot", *b)
}
}