Documentation ¶
Overview ¶
Package tel represent Telemetry service we support context as source of Telemetry for gracefully support middleware we not pass ref to Telemetry for better handling different log instances
Index ¶
- Constants
- Variables
- func FromCtxWithSpan(ctx context.Context) *span
- func GrpcUnaryClientInterceptor(ignore ...string) grpc.UnaryClientInterceptor
- func NewTelemetryContext(cfg Config, ctx context.Context) context.Context
- func SetLogOutput(ctx context.Context) *bytes.Buffer
- func StartSpanFromContext(ctx context.Context, name string, opts ...opentracing.StartSpanOption) (span, context.Context)
- func UpdateTraceFields(ctx context.Context)
- func WithContext(ctx context.Context, l Telemetry) context.Context
- type Config
- type HealthChecker
- type HealthHandler
- type Monitor
- type Telemetry
- func (t *Telemetry) Close()
- func (t Telemetry) Copy() Telemetry
- func (t Telemetry) Ctx() context.Context
- func (t Telemetry) GrpcUnaryClientInterceptorAll(ignore ...string) grpc.UnaryClientInterceptor
- func (t Telemetry) GrpcUnaryServerInterceptor(ignore ...string) grpc.UnaryServerInterceptor
- func (t Telemetry) GrpcUnaryServerInterceptorAll(ignore ...string) grpc.UnaryServerInterceptor
- func (t Telemetry) HttpServerMiddleware() func(next http.Handler) http.Handler
- func (t Telemetry) HttpServerMiddlewareAll(m metrics.HttpTracker) func(next http.Handler) http.Handler
- func (t Telemetry) IsDebug() bool
- func (t Telemetry) M() Monitor
- func (t *Telemetry) Printf(msg string, items ...interface{})
- func (t *Telemetry) PutFields(fields ...zap.Field) *Telemetry
- func (t *Telemetry) StartMonitor()
- func (t *Telemetry) StartSpan(name string, opts ...opentracing.StartSpanOption) (span, context.Context)
- func (t Telemetry) T() opentracing.Tracer
- func (t Telemetry) WithContext(ctx context.Context) context.Context
- func (t *Telemetry) WithSpan(s opentracing.Span) span
Constants ¶
const ( MonitorEndpoint = "/metrics" HealthEndpoint = "/health" PprofIndexEndpoint = "/debug/pprof" EchoShutdownTimeout = 5 * time.Second )
const (
Component = "component"
)
Variables ¶
var (
ErrEmptyHandler = fmt.Errorf("unable to add nil health to monitoring")
)
var ErrGrpcInternal = status.New(codes.Internal, "internal server error").Err()
Functions ¶
func FromCtxWithSpan ¶
FromCtxWithSpan retrieves from ctx tele span object span object just composition of tele object with open-tracing instance which write both to log and fill trace log simultaneously
func GrpcUnaryClientInterceptor ¶
func GrpcUnaryClientInterceptor(ignore ...string) grpc.UnaryClientInterceptor
GrpcUnaryClientInterceptor input ctx assume that it contain telemetry instance as well as invoker already under our telemetry GrpcUnaryClientInterceptor implement:
- recovery
- detail log during errors (+ in recovery also)
- measure execution time
func NewTelemetryContext ¶
NewTelemetryContext creates new instance and put it to @ctx
func SetLogOutput ¶
SetLogOutput debug function for duplicate input log into bytes.Buffer
func StartSpanFromContext ¶
func StartSpanFromContext(ctx context.Context, name string, opts ...opentracing.StartSpanOption) (span, context.Context)
StartSpanFromContext start telemetry span witch create or continue existent trace for gracefully continue trace ctx should contain both span and tele
func UpdateTraceFields ¶
UpdateTraceFields during session start good way to update tracing fields @prefix - for split different inter-service calls: kafka, grpc, db and etc
Types ¶
type Config ¶
type Config struct { Project string `env:"PROJECT"` Namespace string `env:"NAMESPACE"` LogLevel string `env:"LOG_LEVEL" envDefault:"info"` Debug bool `env:"DEBUG" envDefault:"false"` MonitorAddr string `env:"MONITOR_ADDR" envDefault:"0.0.0.0:8011"` }
func DefaultConfig ¶
func DefaultConfig() Config
func DefaultDebugConfig ¶
func DefaultDebugConfig() Config
func GetConfigFromEnv ¶
func GetConfigFromEnv() Config
GetConfigFromEnv uses DefaultConfig and overwrite only variables present in env
type HealthChecker ¶
type HealthHandler ¶
type HealthHandler struct {
health.CompositeChecker
}
func (*HealthHandler) ServeHTTP ¶
func (h *HealthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP returns a json encoded health set the status to http.StatusServiceUnavailable if the check is down
type Telemetry ¶
func (Telemetry) GrpcUnaryClientInterceptorAll ¶
func (t Telemetry) GrpcUnaryClientInterceptorAll(ignore ...string) grpc.UnaryClientInterceptor
GrpcUnaryClientInterceptorAll setup recovery, metrics, tracing and debug option according goal of our framework Execution order:
- opentracing injection via otgrpc.OpenTracingClientInterceptor
- recovery, measure execution time + debug log via own GrpcUnaryClientInterceptor
- metrics via metrics.UnaryClientInterceptor
func (Telemetry) GrpcUnaryServerInterceptor ¶
func (t Telemetry) GrpcUnaryServerInterceptor(ignore ...string) grpc.UnaryServerInterceptor
GrpcUnaryServerInterceptor the most important create new telepresence instance + fill trace ids
implements: * new telepresence instance * fill trace ids * recovery * detail log during errors (+ in recovery also) * measure execution time
func (Telemetry) GrpcUnaryServerInterceptorAll ¶
func (t Telemetry) GrpcUnaryServerInterceptorAll(ignore ...string) grpc.UnaryServerInterceptor
GrpcUnaryServerInterceptorAll setup recovery, metrics, tracing and debug option according goal of our framework Execution order:
- opentracing injection via otgrpc.OpenTracingServerInterceptor
- ctx new instance, recovery, measure execution time + debug log via own GrpcUnaryServerInterceptor
- metrics via metrics.UnaryServerInterceptor
func (Telemetry) HttpServerMiddleware ¶
HttpServerMiddleware perform: * telemetry log injection * measure execution time * recovery
func (Telemetry) HttpServerMiddlewareAll ¶
func (t Telemetry) HttpServerMiddlewareAll(m metrics.HttpTracker) func(next http.Handler) http.Handler
HttpServerMiddlewareAll represent all essential metrics Execution order:
- opentracing injection via nethttp.Middleware
- recovery + measure execution time + debug log via own HttpServerMiddleware
- metrics via metrics.NewHttpMiddlewareWithOption
func (*Telemetry) PutFields ¶
PutFields update current logger instance with new fields, which would affect only on nest write log call for current tele instance Because reference it also affect context and this approach is covered in Test_telemetry_With
func (*Telemetry) StartMonitor ¶
func (t *Telemetry) StartMonitor()
StartMonitor is blocking operation
func (*Telemetry) StartSpan ¶
func (t *Telemetry) StartSpan(name string, opts ...opentracing.StartSpanOption) (span, context.Context)
StartSpan start absolutely new trace telemetry span keep in mind than that function don't continue any trace, only create new for continue span use StartSpanFromContext
func (Telemetry) WithContext ¶
WithContext put new copy of telemetry into context
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
example
|
|
demo/client
Module
|
|
demo/gin
Module
|
|
demo/nats
Module
|
|
Package httpclient implement tel http.client wrapper which help to handle error The most important approach: perform logs by itself
|
Package httpclient implement tel http.client wrapper which help to handle error The most important approach: perform logs by itself |
middleware
|
|
chi
Module
|
|
echo
Module
|
|
gin
Module
|
|
gin/example
Module
|
|
grpc
Module
|
|
nats
Module
|
|
natsmw
Module
|
|
monitoring
|
|
plugins
|
|
otelsql
Module
|
|
pgx
Module
|
|
sqlwrapper
Module
|
|
propagators
|
|
natsprop
Module
|