MM-11701 Log request ID for outgoing webhooks (#10513)

* "Log request ID"

* "Log request ID"

* "Update in response to comment"

* "Update in response to comment"

* "Run gofmt"
This commit is contained in:
Jerry Fireman
2019-05-17 09:48:32 -04:00
committed by Christopher Speller
parent 8d8a4d8614
commit 571a026a4e

View File

@@ -4,7 +4,6 @@
package web
import (
"fmt"
"io"
"net/http"
"strings"
@@ -30,6 +29,15 @@ func incomingWebhook(c *Context, w http.ResponseWriter, r *http.Request) {
var err *model.AppError
incomingWebhookPayload := &model.IncomingWebhookRequest{}
contentType := r.Header.Get("Content-Type")
defer func() {
if *c.App.Config().LogSettings.EnableWebhookDebugging {
if c.Err != nil {
mlog.Debug("Incoming webhook received", mlog.String("webhook_id", id), mlog.String("request_id", c.App.RequestId), mlog.String("payload", incomingWebhookPayload.ToJson()))
}
}
}()
if strings.Split(contentType, "; ")[0] == "application/x-www-form-urlencoded" {
payload := strings.NewReader(r.FormValue("payload"))
@@ -56,10 +64,6 @@ func incomingWebhook(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
if *c.App.Config().LogSettings.EnableWebhookDebugging {
mlog.Debug(fmt.Sprintf("Incoming webhook received. Id=%s Content=%s", id, incomingWebhookPayload.ToJson()))
}
err = c.App.HandleIncomingWebhook(id, incomingWebhookPayload)
if err != nil {
c.Err = err