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 CreateRes(ctx context.Context, l Config) *resource.Resource
- func SetGlobal(t Telemetry)
- func SetLogOutput(log *Telemetry) *bytes.Buffer
- func StartSpanFromContext(ctx context.Context, name string, opts ...trace.SpanStartOption) (trace.Span, context.Context)
- func UpdateTraceFields(ctx context.Context)
- func WithContext(ctx context.Context, l Telemetry) context.Context
- func WrapContext(ctx context.Context, l *Telemetry) context.Context
- type Config
- type HistogramOpt
- type Logger
- type MonitorConfig
- type Option
- func WithHealthCheckers(c ...health.Checker) Option
- func WithHistogram(list ...HistogramOpt) Option
- func WithMonitorEnable(enable bool) Option
- func WithMonitoringAddr(addr string) Option
- func WithNamespace(ns string) Option
- func WithServiceName(name string) Option
- func WithTraceSampler(sampler sdktrace.Sampler) Option
- type OtelConfig
- type Telemetry
- func (t Telemetry) Copy() Telemetry
- func (t Telemetry) Ctx() context.Context
- func (t Telemetry) IsDebug() bool
- func (t Telemetry) LogLevel() zapcore.Level
- func (t Telemetry) Meter(ins string, opts ...metric.MeterOption) metric.Meter
- func (t Telemetry) MetricProvider() metric.MeterProvider
- func (t *Telemetry) Printf(msg string, items ...interface{})
- func (t *Telemetry) PutAttr(attr ...attribute.KeyValue) *Telemetry
- func (t *Telemetry) PutFields(fields ...zap.Field) *Telemetry
- func (t *Telemetry) PutSpan(in trace.Span)
- func (t Telemetry) Span() trace.Span
- func (t *Telemetry) StartSpan(ctx context.Context, name string, opts ...trace.SpanStartOption) (trace.Span, context.Context)
- func (t Telemetry) T() trace.Tracer
- func (t Telemetry) Tracer(name string, opts ...trace.TracerOption) Telemetry
- func (t Telemetry) TracerProvider() trace.TracerProvider
- func (t Telemetry) WithContext(ctx context.Context) context.Context
- func (t Telemetry) WithSpan(s trace.Span) *Telemetry
Constants ¶
const ( ServiceNameKey = attribute.Key("service") ServiceInstanceIDKey = attribute.Key("service_instance_id") )
const DisableLog = "none"
Variables ¶
var ( ErrNoTLS = errors.New("no tls configuration") ErrCaAppend = errors.New("append certs from pem") )
var ( Any = zap.Any Binary = zap.Binary ByteString = zap.ByteString Bool = zap.Bool Duration = zap.Duration Float32 = zap.Float32 Float64 = zap.Float64 Int = zap.Int Int64 = zap.Int64 Int32 = zap.Int32 Int16 = zap.Int16 Int8 = zap.Int8 String = zap.String Time = zap.Time Uint = zap.Uint Uint64 = zap.Uint64 Uint32 = zap.Uint32 Uint16 = zap.Uint16 Uint8 = zap.Uint8 Uintptr = zap.Uintptr Error = zap.Error )
var ( Strings = zap.Strings Ints = zap.Ints )
var DefaultHistogramBoundaries = []float64{.005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10}
DefaultHistogramBoundaries have been copied from prometheus.DefBuckets.
Note we anticipate the use of a high-precision histogram sketch as the standard histogram aggregator for OTLP export. (https://github.com/open-telemetry/opentelemetry-specification/issues/982).
var (
GenServiceName = defaultServiceFmt
)
Functions ¶
func SetLogOutput ¶
SetLogOutput debug function for duplicate input log into bytes.Buffer
func StartSpanFromContext ¶
func StartSpanFromContext(ctx context.Context, name string, opts ...trace.SpanStartOption) ( trace.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 { Service string `env:"OTEL_SERVICE_NAME"` Namespace string `env:"NAMESPACE" envDefault:"default"` Environment string `env:"DEPLOY_ENVIRONMENT" envDefault:"dev"` Version string `env:"VERSION" envDefault:"dev"` LogLevel string `env:"LOG_LEVEL" envDefault:"info"` // Valid values are "json", "console" or "none" LogEncode string `env:"LOG_ENCODE" envDefault:"json"` Debug bool `env:"DEBUG" envDefault:"false"` MonitorConfig OtelConfig }
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 HistogramOpt ¶ added in v2.2.0
HistogramOpt represent histogram bucket configuration for specific metric
type Logger ¶
type Logger interface { Check(lvl zapcore.Level, msg string) *zapcore.CheckedEntry Debug(msg string, fields ...zap.Field) Info(msg string, fields ...zap.Field) Warn(msg string, fields ...zap.Field) Error(msg string, fields ...zap.Field) Panic(msg string, fields ...zap.Field) Fatal(msg string, fields ...zap.Field) Sync() error Core() zapcore.Core }
type MonitorConfig ¶
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option interface used for setting optional config properties.
func WithHealthCheckers ¶
WithHealthCheckers provide checkers to monitoring system for check health status of service
func WithHistogram ¶ added in v2.2.0
func WithHistogram(list ...HistogramOpt) Option
WithHistogram register metrics with custom bucket list
func WithMonitorEnable ¶
WithMonitorEnable enable monitoring
func WithMonitoringAddr ¶
WithMonitoringAddr overwrite monitoring addr
func WithTraceSampler ¶ added in v2.2.3
WithTraceSampler allow use own sampling strategy for scrapping traces
type OtelConfig ¶
type OtelConfig struct { Enable bool `env:"OTEL_ENABLE" envDefault:"true"` // OtelAddr address where grpc open-telemetry exporter serve Addr string `env:"OTEL_COLLECTOR_GRPC_ADDR" envDefault:"127.0.0.1:4317"` // WithInsecure controls whether a client verifies the server's // certificate chain and host name. If InsecureSkipVerify is true, crypto/tls // accepts any certificate presented by the server and any host name in that // certificate. In this mode, TLS is susceptible to machine-in-the-middle // attacks unless custom verification is used. This should be used only for // testing or in combination with VerifyConnection or VerifyPeerCertificate. WithInsecure bool `env:"OTEL_EXPORTER_WITH_INSECURE" envDefault:"true"` // WithCompression enables gzip compression for all connections: logs, traces, metrics WithCompression bool `env:"OTEL_ENABLE_COMPRESSION" envDefault:"true"` MetricsPeriodicIntervalSec int `env:"OTEL_METRIC_PERIODIC_INTERVAL_SEC" envDefault:"15"` // ServerName is used to verify the hostname on the returned // certificates unless InsecureSkipVerify is given. It is also included // in the client's handshake to support virtual hosting unless it is // an IP address. // Disable WithInsecure option if set ServerName string `env:"OTEL_COLLECTOR_TLS_SERVER_NAME"` Logs struct { // OtelClient is logger of otel clients OtelClient bool `env:"LOGGING_OTEL_CLIENT"` // OtelProcessor is logger of otel processor OtelProcessor bool `env:"LOGGING_OTEL_PROCESSOR"` EnableRetry bool `env:"LOGS_ENABLE_RETRY" envDefault:"false"` SyncInterval time.Duration `env:"LOGS_SYNC_INTERVAL" envDefault:"1s"` MaxMessageSize int `env:"LOGS_MAX_MESSAGE_SIZE" envDefault:"256"` MaxMessagesPerSecond int `env:"LOGS_MAX_MESSAGES_PER_SECOND" envDefault:"100"` } Traces tracesConfig Metrics struct { EnableRetry bool `env:"METRICS_ENABLE_RETRY" envDefault:"false"` CardinalityDetector struct { Enable bool `env:"METRICS_CARDINALITY_DETECTOR_ENABLE" envDefault:"true"` MaxCardinality int `env:"METRICS_CARDINALITY_DETECTOR_MAX_CARDINALITY" envDefault:"100"` MaxInstruments int `env:"METRICS_CARDINALITY_DETECTOR_MAX_INSTRUMENTS" envDefault:"500"` DiagnosticInterval time.Duration `env:"METRICS_CARDINALITY_DETECTOR_DIAGNOSTIC_INTERVAL" envDefault:"10m"` } } // Raw parses a public/private key pair from a pair of // PEM encoded data. On successful return, Certificate.Leaf will be nil because // the parsed form of the certificate is not retained. Raw struct { CA []byte `env:"OTEL_COLLECTOR_TLS_CA_CERT"` Cert []byte `env:"OTEL_COLLECTOR_TLS_CLIENT_CERT"` Key []byte `env:"OTEL_COLLECTOR_TLS_CLIENT_KEY"` } // contains filtered or unexported fields }
TODO: Review overlapping options (WthInsecure, WithCompression, etc). TODO: Add TEL_ prefix to avoid env conflicts
func (*OtelConfig) IsTLS ¶ added in v2.1.2
func (c *OtelConfig) IsTLS() bool
type Telemetry ¶
func (Telemetry) MetricProvider ¶
func (t Telemetry) MetricProvider() metric.MeterProvider
MetricProvider used in constructor creation
func (*Telemetry) PutAttr ¶
PutAttr opentelemetry attr WARN: NON THREAD SAFE Be careful using this method with tel.Global()
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 WARN: NON THREAD SAFE Be careful using this method with tel.Global()
func (*Telemetry) PutSpan ¶ added in v2.2.3
PutSpan ... WARN: NON THREAD SAFE Be careful using this method with tel.Global()
func (*Telemetry) StartSpan ¶
func (t *Telemetry) StartSpan(ctx context.Context, name string, opts ...trace.SpanStartOption) (trace.Span, context.Context)
StartSpan start new trace telemetry span in case if ctx contains embed trace it will continue chain keep in mind than that function don't continue any trace, only create new for continue span use StartSpanFromContext In addition: register new root span in new ctx instance
return context where embed telemetry with span writer
func (Telemetry) Tracer ¶
func (t Telemetry) Tracer(name string, opts ...trace.TracerOption) Telemetry
Tracer instantiate with specific name and tel option @return new Telemetry pointed to this one
func (Telemetry) TracerProvider ¶
func (t Telemetry) TracerProvider() trace.TracerProvider
TracerProvider used in constructor creation
func (Telemetry) WithContext ¶
WithContext put new copy of telemetry into context