echo

package
v0.0.0-...-c72030a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 16, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

README

Middleware-echoweb

Instrumentation

  1. Create Cfg.yaml file
  2. Create Routes.yaml file
  3. Initailise Config with choice of sender, absolute path of CfgFile and RoutesFile along with EchoWeb Server pointer.
  4. Call init function and pass the Config struct intialised above.
  5. Copy tracer-config.yaml, tracer-routesRegistration.yaml file to container in Dockerfile

Example: tracer-config.yaml file:

cluster* : prod
shard* : 1
application : wavefrontHQ
service : wavefront-middleware
source : VMware
CustomApplicationTags* :
	staticTags:
		customApplicationTagKey : customApplicationTagValue
	jwtClaims**:
		- username
rateSampler* : 10
durationSampler* : 60

*optional parameter If no rate sampler is given it is taken as deterministic sampler ie all traces are sent to wavefront

**Middleware automatically parses jwt token to add the given claims as tags in the span

Example: tracer-routesRegistration.yaml

routesRegistration:
		/tracingapi/test.GET:
				routeSpecificTag: route-tag
				routeSpecifcMetaTags:
					routeSpecifcMetaTagKey: routeSpecifcMetaTagValue

Routes registration format: api-path.HTTP_METHOD

init function:

Using Direct Sender
func init() {
	cfgFile := "filePath of Cfg.yaml file"
	routesFile := "filePath of Routes.yaml file"

	config := new(Config)
	config.CfgFile = cfgFile
	config.RoutesFile= routesFile
	config.echoWeb = *echo.Echo
	config.DirectCfg = senders.DirectConfiguration
	
	//Initialising Global tracer
	err := InitTracer(config)

	if err != nil {
		/*
		Handle Error
		*/
	}
}
Using In-Direct Sender
func init() {
	cfgFile := "filePath of Cfg.yaml file"
	routesFile := "filePath of Routes.yaml file"

	config := new(Config)
	config.CfgFile = cfgFile
	config.RoutesFile= routesFile
	config.echoWeb = *echo.Echo
	config.DirectCfg = senders.ProxyConfiguration
	
	//Initialising Global tracer
	err := InitTracer(config)

	if err != nil {
		/*
		Handle Error
		*/
	}
}

Cross process context propagation

headers:= GetTracingHeadersToInject(c)

c - echo context

GetTracingHeadersToInject func returns headers which can be added to the call when making cross service calls. Context is propagated using headers which helps in stiching trace

Adding dynamic tags to Span

To add metadata derived during servicing the request

AddDynamicTags(c,tags)

c - echo context tags - key value pairs of strings

Contextual Logger

logger:= NewSpanLogger(c)

c - echo context Same usage as default go logger instance given by log lib in go. Ex: logger.Println("Logging") Logs are automatically injected span info including trace id, span id, and parent span id. Logs are sent to wavefront for each call

All the function exposed by standard Go Logger are exposed by custom logger with same usage

Other tracing methods exposed

For manual start of span
serverSpan,parentSpanId,err:= StartTraceSpan(c,operationName,tags)

c - echo context

For injecting headers in default http client request
httpRequest:= InjectTracerHTTP(tracer,span,httpReq)
Returns headers to be injected from span. To be used when manually starting span within the process
tags:= GetTracingHeadersToInjectFromSpan(tracer,span)

c - echo context

Returns headers to be injected from echo context. To be used when using middleware
GetTracingHeadersToInjectFromContext(c)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Tracer opentracing.Tracer

Tracer Global Tracer

Functions

func AddDynamicTags

func AddDynamicTags(context *echo.Context, tags map[string]interface{})

AddDynamicTags injects the dyanmic tags to the span

func GetTracingHeadersToInjectFromContext

func GetTracingHeadersToInjectFromContext(context echo.Context) map[string]string

GetTracingHeadersToInjectFromContext returns the headers which Should be added to the request to inject from the echo context To be used when using middleware

func GetTracingHeadersToInjectFromSpan

func GetTracingHeadersToInjectFromSpan(tracer opentracing.Tracer, serverSpan opentracing.Span) map[string]string

GetTracingHeadersToInjectFromSpan returns the headers which Should be added to the request to inject from the current span. To be used when manually starting span inside process

func InitTracer

func InitTracer(cfg Config) error

InitTracer initialize tracer object, initialize the GlobalTracer with this newly created, tracer object. Call utils/wavefront.Tracer to access the tracer object For proxy sender send token as empty string

func InjectTracerHTTP

func InjectTracerHTTP(tracer opentracing.Tracer, serverSpan opentracing.Span, httpReq *http.Request) error

InjectTracerHTTP injects the current span into the trace. By Adding the context of the current span to the headers of the Http request.

func StartTraceSpan

func StartTraceSpan(c echo.Context, appSpecificOperationName string, tags map[string]string) (opentracing.Span, string)

StartTraceSpan looks for existing context from the headers of the request. If context is found, it starts a child span to the parent span, Else it starts a root span. Tags are added to the respective spans created. If parent span exists parent span id is returned along with child span otherwise root span and "" is returned

func TracingHandler

func TracingHandler(next echo.HandlerFunc) echo.HandlerFunc

TracingHandler custom echoWeb middleware. Enables tracing for the routes defined in tracer-config.go. Injects respective tags for each route defined in the span of each trace.

Types

type Config

type Config struct {
	DirectCfg  *senders.DirectConfiguration
	ProxyCfg   *senders.ProxyConfiguration
	CfgFile    string
	RoutesFile string
	EchoWeb    *echo.Echo
}

Config stores the middleware config

type SpanLogger

type SpanLogger struct {
	// contains filtered or unexported fields
}

SpanLogger custom implementation of Go standard Logger Exposes the same functions as Standard Logger

func NewSpanLogger

func NewSpanLogger(context echo.Context) *SpanLogger

NewSpanLogger returns a new custom logger instance with TraceId and SpanId injected. It exposes the same functions as the standard Golang Logger, with added function of injecting span info info to the logs. And sending span logs to wavefront.

func (*SpanLogger) Fatal

func (wavefrontLogger *SpanLogger) Fatal(v ...interface{})

Fatal is equivalent to Print() followed by a call to os.Exit(1). Sends the log object to wavefront.

func (*SpanLogger) Fatalf

func (wavefrontLogger *SpanLogger) Fatalf(format string, v ...interface{})

Fatalf is equivalent to Printf() followed by a call to os.Exit(1). Sends the log object to wavefront.

func (*SpanLogger) Fatalln

func (wavefrontLogger *SpanLogger) Fatalln(v ...interface{})

Fatalln is equivalent to Println() followed by a call to os.Exit(1). Sends the log object to wavefront.

func (*SpanLogger) Flags

func (wavefrontLogger *SpanLogger) Flags() int

Flags returns the output flags for the logger.

func (*SpanLogger) Output

func (wavefrontLogger *SpanLogger) Output(calldepth int, s string) error

Output writes the output for a logging event. The string s contains the text to print after the prefix specified by the flags of the Logger. A newline is appended if the last character of s is not already a newline. Calldepth is the count of the number of frames to skip when computing the file name and line number if Llongfile or Lshortfile is set; a value of 1 will print the details for the caller of Output.

func (*SpanLogger) Panic

func (wavefrontLogger *SpanLogger) Panic(v ...interface{})

Panic is equivalent to Print() followed by a call to panic(). Sends the log object to wavefront.

func (*SpanLogger) Panicf

func (wavefrontLogger *SpanLogger) Panicf(format string, v ...interface{})

Panicf is equivalent to Printf() followed by a call to panic(). Sends the log object to wavefront.

func (*SpanLogger) Panicln

func (wavefrontLogger *SpanLogger) Panicln(v ...interface{})

Panicln is equivalent to Println() followed by a call to panic(). Sends the log object to wavefront.

func (*SpanLogger) Prefix

func (wavefrontLogger *SpanLogger) Prefix() string

Prefix returns the output prefix for the logger.

func (*SpanLogger) Print

func (wavefrontLogger *SpanLogger) Print(v ...interface{})

Print formats using the default formats for its operands and writes to standard output. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered. Sends the log object to wavefront.

func (*SpanLogger) Printf

func (wavefrontLogger *SpanLogger) Printf(format string, v ...interface{})

Printf formats according to a format specifier and writes to standard output. It returns the number of bytes written and any write error encountered. Sends the log object to wavefront.

func (*SpanLogger) Println

func (wavefrontLogger *SpanLogger) Println(v ...interface{})

Println formats using the default formats for its operands and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered. Sends the log object to wavefront.

func (*SpanLogger) SetFlags

func (wavefrontLogger *SpanLogger) SetFlags(flag int)

SetFlags sets the output flags for the logger.

func (*SpanLogger) SetOutput

func (wavefrontLogger *SpanLogger) SetOutput(w io.Writer)

SetOutput sets the output destination for the logger.

func (*SpanLogger) SetPrefix

func (wavefrontLogger *SpanLogger) SetPrefix(prefix string)

SetPrefix sets the output prefix in addition to trace Prefix for the logger.

type Writer

type Writer struct {
	io.Writer
	// contains filtered or unexported fields
}

Writer custom writer

func (Writer) Write

func (w Writer) Write(b []byte) (n int, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL