MM-21898: Part 2. Add opentracing (#13904)

* initial implementation of opentracing

* app layer

* Revert Makefile

* .

* cleanup

* .

* .

* .

* .

* .

* .

* .

* .

* .

* .

* .

* [ci]

* autogenerate interface

* .

* missed vendor files

* updated interfaces

* updated store layers

* lint fixes

* .

* finishing layer generators and nested spans

* added errors and b3 support

* code review

* .

* .

* fixed build error due to misplased flag.Parse()

* code review addressed
Этот коммит содержится в:
Miguel de la Cruz
2020-03-05 14:46:08 +01:00
коммит произвёл GitHub
родитель 5a34ec4793
Коммит 182c29b456
154 изменённых файлов: 47653 добавлений и 264 удалений

Просмотреть файл

@@ -5,6 +5,7 @@ package web
import (
"bytes"
"context"
"fmt"
"net/http"
"reflect"
@@ -13,10 +14,15 @@ import (
"time"
"github.com/NYTimes/gziphandler"
"github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/ext"
spanlog "github.com/opentracing/opentracing-go/log"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/services/tracing"
"github.com/mattermost/mattermost-server/v5/store"
"github.com/mattermost/mattermost-server/v5/utils"
)
@@ -93,6 +99,33 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
c.Params = ParamsFromRequest(r)
c.Log = c.App.Log()
if *c.App.Config().ServiceSettings.EnableOpenTracing {
span, ctx := tracing.StartRootSpanByContext(context.Background(), "web:ServeHTTP")
carrier := opentracing.HTTPHeadersCarrier(r.Header)
_ = opentracing.GlobalTracer().Inject(span.Context(), opentracing.HTTPHeaders, carrier)
ext.HTTPMethod.Set(span, r.Method)
ext.HTTPUrl.Set(span, c.App.Path())
ext.PeerAddress.Set(span, c.App.IpAddress())
span.SetTag("request_id", c.App.RequestId())
span.SetTag("user_agent", c.App.UserAgent())
defer func() {
if c.Err != nil {
span.LogFields(spanlog.Error(c.Err))
ext.HTTPStatusCode.Set(span, uint16(c.Err.StatusCode))
ext.Error.Set(span, true)
}
span.Finish()
}()
c.App.SetContext(ctx)
tmpSrv := app.Server{}
tmpSrv = *c.App.Srv()
tmpSrv.Store = store.NewOpenTracingLayer(c.App.Srv().Store, ctx)
c.App.SetServer(&tmpSrv)
c.App = app.NewOpenTracingAppLayer(c.App, ctx)
}
// Set the max request body size to be equal to MaxFileSize.
// Ideally, non-file request bodies should be smaller than file request bodies,
// but we don't have a clean way to identify all file upload handlers.