Documentation ¶
Index ¶
- func Debug(ctx context.Context, msg string, attributes ...Field)
- func End(ctx context.Context)
- func Error(ctx context.Context, msg string, attributes ...Field)
- func Fatal(ctx context.Context, msg string, attributes ...Field)
- func FieldsToKeyValues(fields ...Field) []attribute.KeyValue
- func FieldsToZapFields(ctx context.Context, fields ...Field) []zapcore.Field
- func Flush(ctx context.Context)
- func GenSpanID() string
- func GenTraceID() string
- func GinMiddleware(service string) gin.HandlerFunc
- func HttpInject(ctx context.Context, request *http.Request) error
- func Info(ctx context.Context, msg string, attributes ...Field)
- func Init(conf Config, applicationAttributes ...Field)
- func NewRootContext(traceID string, spanID string) (context.Context, error)
- func SetSpanAttr(ctx context.Context, attributes ...Field)
- func SpanID(ctx context.Context) string
- func Start(ctx context.Context, spanName string, spanStartOption ...Field) context.Context
- func TraceID(ctx context.Context) string
- func Warn(ctx context.Context, msg string, attributes ...Field)
- type Config
- type Field
- func Bool(key string, val bool) Field
- func BoolSlice(key string, val []bool) Field
- func Float64(key string, val float64) Field
- func Float64Slice(key string, val []float64) Field
- func Int(key string, val int) Field
- func Int64(key string, val int64) Field
- func Int64Slice(key string, val []int64) Field
- func IntSlice(key string, val []int) Field
- func String(key string, val string) Field
- func StringSlice(key string, val []string) Field
- func Stringer(key string, val fmt.Stringer) Field
- type FieldType
- type LoggerSpanContext
- type Trace
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FieldsToKeyValues ¶
FieldsToKeyValue
func FieldsToZapFields ¶
FieldsToZapFields
func GenTraceID ¶
func GenTraceID() string
GenTraceID generate traceID current timestamp with 8 rand bytes
func GinMiddleware ¶
func GinMiddleware(service string) gin.HandlerFunc
GinMiddleware extract spanContext
func HttpInject ¶
HTTPInject inject spanContext
func Init ¶
LoggerInit logger init applicationAttributes can use service.name,service.namesapce,service.instance.id,service.version, telemetry.sdk.name,telemetry.sdk.language,telemetry.sdk.version,telemetry.auto.version or other key that you need
example: Init(conf,String("sevice.name",service1))
func NewRootContext ¶
NewRootContext new root context with given traceID and spanID
func SetSpanAttr ¶
SetSpanAttr set attributes for current span
func Start ¶
Start start span
example 1: parentCtx:=Start(context.Background(),"span1",String("spanAttr","attr")) Info(parentCtx,"msg",String("Attr","attr")) End(parentCtx) childCtx:=Start(parentCtx,"span2") Info(childCtx,"msg") End(childCtx)
example 2: ctx:= NewRootContext(traceID,spanID) ctx1:=Start(ctx,"span1",String("spanAttr","attr")) Info(ctx1,"msg") End(ctx1)
Types ¶
type Config ¶
type Config struct { // Print info or error,default false Debug bool `yaml:"debug" mapstructure:"debug"` // Enable to save log to the disk,default false EnableLog bool `yaml:"enable_log" mapstructure:"enable_log"` // Enable to generate trace info,default false EnableTrace bool `yaml:"enable_trace" mapstructure:"enable_trace"` // Path to store the log,default ./run.log File string `yaml:"file" mapstructure:"file"` // MaxSize is the maximum size in megabytes of the log file before it gets // rotated. It defaults to 100 megabytes. MaxSize int `yaml:"max_size" mapstructure:"max_size"` // MaxBackups is the maximum number of old log files to retain. The default // is to retain all old log files (though MaxAge may still cause them to get // deleted.) MaxBackups int `yaml:"max_backups" mapstructure:"max_backups"` // MaxAge is the maximum number of days to retain old log files based on the // timestamp encoded in their filename. Note that a day is defined as 24 // hours and may not exactly correspond to calendar days due to daylight // savings, leap seconds, etc. The default is not to remove old log files // based on age. MaxAge int `yaml:"max_age" mapstructure:"max_age"` // Compress determines if the rotated log files should be compressed // using gzip. The default is not to perform compression. Compress bool `yaml:"compress" mapstructure:"compress"` // "* * * * * *",The smallest unit is seconds,refer to linux crond format // Rotate causes Logger to close the existing log file and immediately create a new one. // This is a helper function for applications that want to initiate rotations outside of the normal rotation rules, // such as in response to SIGHUP. After rotating, // this initiates a cleanup of old log files according to the normal rules. Rotate string `yaml:"rotate" mapstructure:"rotate"` // TraceProviderType support file or jaeger TracerProviderType string `yaml:"tracer_provider_type" mapstructure:"tracer_provider_type"` // trace sampling, 0.0-1 // 0,never trace // 1,always trace TraceSampleRatio float64 `yaml:"trace_sample_ratio" mapstructure:"trace_sample_ratio"` // Jaeger URI JaegerServer string `yaml:"jaeger_server" mapstructure:"jaeger_server"` JaegerUsername string `yaml:"jaeger_username" mapstructure:"jaeger_username"` JaegerPassword string `yaml:"jaeger_password" mapstructure:"jaeger_password"` }
Config
type Field ¶
type LoggerSpanContext ¶
type LoggerSpanContext struct {
// contains filtered or unexported fields
}
save context span
type Trace ¶
type Trace struct{}
func (Trace) NewFileProvider ¶
NewFileProvider
func (Trace) NewJaegerProvider ¶
NewJaegerProvider