tracing

package
v0.0.0-...-a73014c Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//DefaultServiceVersion for dev environment where deployment markers aren't available
	DefaultServiceVersion = "debug"
	//ServiceVersionKey tag used in the spans for deployment markers
	ServiceVersionKey = "service.version"
	//Environment cloud environment (stage, prod, func, canary etc)
	Environment = "environment"

	//Error
	Error        = "error"
	ErrorType    = "error.type"
	ErrorStack   = "error.stack"
	ErrorDetails = "error.details"

	//HTTP Request Specific
	HttpClientHost              = "request.client_host"
	HttpRequestMethod           = "http.method"
	HttpRequestHeaderPrefix     = "request.header"
	HttpRequestQueryParamPrefix = "request.query.param"
	HttpStatusCode              = "http.status_code"
	GinErrors                   = "gin.errors"

	//Database Specific
	DBTable  = "db.table"
	DbMethod = "db.method"
	DbError  = "db.err"
	DbCount  = "db.count"

	//Http Response Specific
	HttpResponseStatus = "response.status_code"
	HttpPath           = "http.path"
)

Variables

View Source
var (
	DBPeerService string
	// Database HostName
	DBHostName string
	// Database port
	DBPort uint16

	RedisPeerService string
	// Redis Hostname
	RedisHostName string
	// Redis Port
	RedisPort uint16

	// Don't remove the following. This will be used for deployment markers. RTFM
	ServiceVersion string //Git Commit Hash / Service Version

	ContextPropogationKey          string
	ContextKey                     string
	DefaultContextPropogationValue string
	BaggagePrefix                  string
	BaggageKeys                    string
)
View Source
var RequestHeaderExclusions = map[string]bool{}

Exclude the following request headers from going into the spans from the http headers

View Source
var RequestQueryParamExclusions = map[string]bool{}

Exclude the following query params from going into the spans from the http headers

View Source
var RouteURLsToExclude []string

Functions

func AddClientTags

func AddClientTags(clientSpan opentracing.Span, tags map[string]interface{}) opentracing.Span

Helper method for adding a map of client tags to the given span object

func CloseTracers

func CloseTracers()

close all tracers which are opened in this app.

func InitConfig

func InitConfig(conf Config)

func InjectClientTrace

func InjectClientTrace(clientSpan opentracing.Span, req *http.Request)

Helper method for injecting traces for remote http calls

func InjectClientTraceWithUrlMethod

func InjectClientTraceWithUrlMethod(clientSpan opentracing.Span, req *http.Request, url string, method string)

Another helper method for injecting traces explictly with request object, url and http method

func RecordError

func RecordError(clientSpan opentracing.Span, err error, clientName string)

Helper method to record application errors into traces

Types

type Config

type Config struct {
	ServiceName                 string
	ServiceVersion              string
	Env                         string
	JaegerHostName              string
	JaegerPort                  string
	Enabled                     bool
	EnableDebug                 bool
	RequestHeaderExclusions     map[string]bool
	RequestQueryParamExclusions map[string]bool
	RouteURLsToExclude          []string
	Logger                      Logger
	PrometheusRegister          prometheus.Registerer
	Database                    DbConfig
	Redis                       RedisConfig
	Context                     Context
}

type Context

type Context struct {
	ContextPropogationKey          string
	ContextKey                     string
	DefaultContextPropogationValue string
	BaggagePrefix                  string
	BaggageKeys                    string
}

type DbConfig

type DbConfig struct {
	PeerService string
	HostName    string
	Port        uint16
}

type JaegerTracer

type JaegerTracer struct {
	// Tracer is a simple, thin interface for Span creation and SpanContext
	Tracer opentracing.Tracer
	// Interface for wrapping close methods when closing the tracer
	Closer io.Closer
}

Tracer instance

func GetTracer

func GetTracer() *JaegerTracer

Gets the tracer object. Tracer is a singleton

func InitAppTracer

func InitAppTracer(serviceName string) *JaegerTracer

* Initializes global app tracer Initializer and sets tracing configs of peer services also. * * To be called from main/init of the application, before calling InitTracing from anywhere else. * opentracing.StartSpan would start span on this tracer, by default

func InitTracing

func InitTracing(serviceName string) *JaegerTracer

* General Tracer Initializer. * To be called from init of any datastore like mysql/redis etc * * Environment determines the actual appearance on the jaeger UI * (e.g. {application}-prod, {application}-stage, {application}-canary etc

func (*JaegerTracer) GetCloser

func (tr *JaegerTracer) GetCloser() io.Closer

Return Closer interface. Useful for flushing the spans when needed or closing it during application shutdown

func (*JaegerTracer) GetTracer

func (tr *JaegerTracer) GetTracer() opentracing.Tracer

Get the opentracing object from the tracer

type Logger

type Logger interface {
	// Error logs a message at error priority
	Error(msg string)

	// Infof logs a message at info priority
	Infof(msg string, args ...interface{})

	// Debugf logs a message at debug priority
	Debugf(msg string, args ...interface{})
}

type RedisConfig

type RedisConfig struct {
	PeerService string
	HostName    string
	Port        uint16
}

Jump to

Keyboard shortcuts

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