github.com/haalcala/mattermost-server-change-repo@v0.0.0-20210713015153-16753fbeee5f/app/layer_generators/opentracing_layer.go.tmpl (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See LICENSE.txt for license information.
     3  
     4  // Code generated by "make app-layers"
     5  // DO NOT EDIT
     6  
     7  package opentracing
     8  
     9  import (
    10  	"github.com/opentracing/opentracing-go/ext"
    11  	spanlog "github.com/opentracing/opentracing-go/log"
    12  	goi18n "github.com/mattermost/go-i18n/i18n"
    13  )
    14  
    15  type {{.Name}} struct {
    16  	app app.AppIface
    17  
    18  	srv *app.Server
    19  
    20  	log              *mlog.Logger
    21  	notificationsLog *mlog.Logger
    22  
    23  	t              i18n.TranslateFunc
    24  	session        model.Session
    25  	requestId      string
    26  	ipAddress      string
    27  	path           string
    28  	userAgent      string
    29  	acceptLanguage string
    30  
    31  	accountMigration einterfaces.AccountMigrationInterface
    32  	cluster          einterfaces.ClusterInterface
    33  	compliance       einterfaces.ComplianceInterface
    34  	dataRetention    einterfaces.DataRetentionInterface
    35  	searchEngine     *searchengine.Broker
    36  	ldap             einterfaces.LdapInterface
    37  	messageExport    einterfaces.MessageExportInterface
    38  	metrics          einterfaces.MetricsInterface
    39  	notification     einterfaces.NotificationInterface
    40  	saml             einterfaces.SamlInterface
    41  
    42  	httpService httpservice.HTTPService
    43  	imageProxy  *imageproxy.ImageProxy
    44  	timezones   *timezones.Timezones
    45  
    46  	context context.Context
    47  	ctx context.Context
    48  }
    49  
    50  {{range $index, $element := .Methods}}
    51  func (a *{{$.Name}}) {{$index}}({{$element.Params | joinParamsWithType}}) {{$element.Results | joinResultsForSignature}} {
    52  	origCtx := a.ctx
    53  	span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.{{$index}}")
    54  
    55  	a.ctx = newCtx
    56  	a.app.Srv().Store.SetContext(newCtx)
    57  	defer func() {
    58  		a.app.Srv().Store.SetContext(origCtx)
    59  		a.ctx = origCtx
    60  	}()
    61  	{{range $paramIdx, $param := $element.Params}}
    62  		{{ shouldTrace $element.ParamsToTrace $param.Name }}
    63  	{{end}}
    64  	defer span.Finish()
    65  	{{- if $element.Results | len | eq 0}}
    66  		a.app.{{$index}}({{$element.Params | joinParams}})
    67  	{{else}}
    68  		{{$element.Results | genResultsVars}} := a.app.{{$index}}({{$element.Params | joinParams}})
    69  		{{if $element.Results | errorPresent}}
    70  			if {{$element.Results | errorVar}} != nil {
    71  				span.LogFields(spanlog.Error({{$element.Results | errorVar}}))
    72  				ext.Error.Set(span, true)
    73  			}
    74  		{{end}}
    75  		return {{$element.Results | genResultsVars -}}
    76  	{{end}}}
    77  {{end}}
    78  
    79  func NewOpenTracingAppLayer(childApp app.AppIface, ctx context.Context) *{{.Name}} {
    80  	newApp := {{.Name}}{
    81  		app: childApp,
    82  		ctx: ctx,
    83  	}
    84  
    85  	newApp.srv = childApp.Srv()
    86  	newApp.log = childApp.Log()
    87  	newApp.notificationsLog = childApp.NotificationsLog()
    88  	newApp.t = childApp.GetT()
    89  	if childApp.Session() != nil {
    90  		newApp.session = *childApp.Session()
    91  	}
    92  	newApp.requestId = childApp.RequestId()
    93  	newApp.ipAddress = childApp.IpAddress()
    94  	newApp.path = childApp.Path()
    95  	newApp.userAgent = childApp.UserAgent()
    96  	newApp.acceptLanguage = childApp.AcceptLanguage()
    97  	newApp.accountMigration = childApp.AccountMigration()
    98  	newApp.cluster = childApp.Cluster()
    99  	newApp.compliance = childApp.Compliance()
   100  	newApp.dataRetention = childApp.DataRetention()
   101  	newApp.searchEngine = childApp.SearchEngine()
   102  	newApp.ldap = childApp.Ldap()
   103  	newApp.messageExport = childApp.MessageExport()
   104  	newApp.metrics = childApp.Metrics()
   105  	newApp.notification = childApp.Notification()
   106  	newApp.saml = childApp.Saml()
   107  	newApp.httpService = childApp.HTTPService()
   108  	newApp.imageProxy = childApp.ImageProxy()
   109  	newApp.timezones = childApp.Timezones()
   110  	newApp.context = childApp.Context()
   111  
   112  	return &newApp
   113  }
   114  
   115  
   116  func (a *{{.Name}}) Srv() *app.Server {
   117  	return a.srv
   118  }
   119  func (a *{{.Name}}) Log() *mlog.Logger {
   120  	return a.log
   121  }
   122  func (a *{{.Name}}) NotificationsLog() *mlog.Logger {
   123  	return a.notificationsLog
   124  }
   125  func (a *{{.Name}}) T(translationID string, args ...interface{}) string {
   126  	return a.t(translationID, args...)
   127  }
   128  func (a *{{.Name}}) Session() *model.Session {
   129  	return &a.session
   130  }
   131  func (a *{{.Name}}) RequestId() string {
   132  	return a.requestId
   133  }
   134  func (a *{{.Name}}) IpAddress() string {
   135  	return a.ipAddress
   136  }
   137  func (a *{{.Name}}) Path() string {
   138  	return a.path
   139  }
   140  func (a *{{.Name}}) UserAgent() string {
   141  	return a.userAgent
   142  }
   143  func (a *{{.Name}}) AcceptLanguage() string {
   144  	return a.acceptLanguage
   145  }
   146  func (a *{{.Name}}) AccountMigration() einterfaces.AccountMigrationInterface {
   147  	return a.accountMigration
   148  }
   149  func (a *{{.Name}}) Cluster() einterfaces.ClusterInterface {
   150  	return a.cluster
   151  }
   152  func (a *{{.Name}}) Compliance() einterfaces.ComplianceInterface {
   153  	return a.compliance
   154  }
   155  func (a *{{.Name}}) DataRetention() einterfaces.DataRetentionInterface {
   156  	return a.dataRetention
   157  }
   158  func (a *{{.Name}}) Ldap() einterfaces.LdapInterface {
   159  	return a.ldap
   160  }
   161  func (a *{{.Name}}) MessageExport() einterfaces.MessageExportInterface {
   162  	return a.messageExport
   163  }
   164  func (a *{{.Name}}) Metrics() einterfaces.MetricsInterface {
   165  	return a.metrics
   166  }
   167  func (a *{{.Name}}) Notification() einterfaces.NotificationInterface {
   168  	return a.notification
   169  }
   170  func (a *{{.Name}}) Saml() einterfaces.SamlInterface {
   171  	return a.saml
   172  }
   173  func (a *{{.Name}}) HTTPService() httpservice.HTTPService {
   174  	return a.httpService
   175  }
   176  func (a *{{.Name}}) ImageProxy() *imageproxy.ImageProxy {
   177  	return a.imageProxy
   178  }
   179  func (a *{{.Name}}) Timezones() *timezones.Timezones {
   180  	return a.timezones
   181  }
   182  func (a *{{.Name}}) Context() context.Context {
   183  	return a.context
   184  }
   185  func (a *{{.Name}}) SetSession(sess *model.Session) {
   186  	a.session = *sess
   187  }
   188  func (a *{{.Name}}) SetT(t i18n.TranslateFunc){
   189  	a.t = t
   190  }
   191  func (a *{{.Name}}) SetRequestId(str string){
   192  	a.requestId = str
   193  }
   194  func (a *{{.Name}}) SetIpAddress(str string){
   195  	a.ipAddress = str
   196  }
   197  func (a *{{.Name}}) SetUserAgent(str string){
   198  	a.userAgent = str
   199  }
   200  func (a *{{.Name}}) SetAcceptLanguage(str string)	{
   201  	a.acceptLanguage = str
   202  }
   203  func (a *{{.Name}}) SetPath(str string){
   204  	a.path = str
   205  }
   206  func (a *{{.Name}}) SetContext(c context.Context){
   207  	a.context = c
   208  }
   209  func (a *{{.Name}}) SetServer(srv *app.Server) {
   210  	a.srv = srv
   211  }
   212  func (a *{{.Name}}) GetT() i18n.TranslateFunc {
   213  	return a.t
   214  }