Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
7c0a5f5e2a | |||
b08f5321b0 | |||
cc0f24e012 | |||
307a08f50c | |||
edc93e8c37 |
@@ -24,6 +24,13 @@ var (
|
||||
DefaultSummaryQuantiles = []float64{0.5, 0.9, 0.97, 0.99, 1}
|
||||
// DefaultSummaryWindow is the default window for summary
|
||||
DefaultSummaryWindow = 5 * time.Minute
|
||||
// DefaultSkipEndpoints is the slice of endpoint that must not be metered
|
||||
DefaultSkipEndpoints = []string{
|
||||
"MeterService.Metrics",
|
||||
"HealthService.Live",
|
||||
"HealthService.Ready",
|
||||
"HealthService.Version",
|
||||
}
|
||||
)
|
||||
|
||||
// Meter is an interface for collecting and instrumenting metrics
|
||||
|
@@ -85,6 +85,7 @@ func (sk SpanKind) String() string {
|
||||
type SpanOptions struct {
|
||||
Labels []interface{}
|
||||
Kind SpanKind
|
||||
Record bool
|
||||
}
|
||||
|
||||
// SpanOption func signature
|
||||
@@ -116,6 +117,12 @@ func WithSpanKind(k SpanKind) SpanOption {
|
||||
}
|
||||
}
|
||||
|
||||
func WithSpanRecord(b bool) SpanOption {
|
||||
return func(o *SpanOptions) {
|
||||
o.Record = b
|
||||
}
|
||||
}
|
||||
|
||||
// Options struct
|
||||
type Options struct {
|
||||
// Context used to store custome tracer options
|
||||
@@ -148,7 +155,8 @@ func NewEventOptions(opts ...EventOption) EventOptions {
|
||||
// NewSpanOptions returns default SpanOptions
|
||||
func NewSpanOptions(opts ...SpanOption) SpanOptions {
|
||||
options := SpanOptions{
|
||||
Kind: SpanKindInternal,
|
||||
Kind: SpanKindInternal,
|
||||
Record: true,
|
||||
}
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
|
@@ -7,14 +7,20 @@ import (
|
||||
"go.unistack.org/micro/v3/logger"
|
||||
)
|
||||
|
||||
// DefaultTracer is the global default tracer
|
||||
var DefaultTracer Tracer = NewTracer()
|
||||
|
||||
var (
|
||||
// DefaultTracer is the global default tracer
|
||||
DefaultTracer Tracer = NewTracer() //nolint:revive
|
||||
// TraceIDKey is the key used for the trace id in the log call
|
||||
TraceIDKey = "trace-id"
|
||||
// SpanIDKey is the key used for the span id in the log call
|
||||
SpanIDKey = "span-id"
|
||||
// DefaultSkipEndpoints is the slice of endpoint that must not be traced
|
||||
DefaultSkipEndpoints = []string{
|
||||
"MeterService.Metrics",
|
||||
"HealthService.Live",
|
||||
"HealthService.Ready",
|
||||
"HealthService.Version",
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@@ -26,13 +26,13 @@ type StructField struct {
|
||||
}
|
||||
|
||||
// StructFieldNameByTag get struct field name by tag key and its value
|
||||
func StructFieldNameByTag(src interface{}, tkey string, tval string) (string, error) {
|
||||
func StructFieldNameByTag(src interface{}, tkey string, tval string) (string, interface{}, error) {
|
||||
sv := reflect.ValueOf(src)
|
||||
if sv.Kind() == reflect.Ptr {
|
||||
sv = sv.Elem()
|
||||
}
|
||||
if sv.Kind() != reflect.Struct {
|
||||
return "", ErrInvalidStruct
|
||||
return "", nil, ErrInvalidStruct
|
||||
}
|
||||
|
||||
typ := sv.Type()
|
||||
@@ -46,7 +46,7 @@ func StructFieldNameByTag(src interface{}, tkey string, tval string) (string, er
|
||||
if ts, ok := fld.Tag.Lookup(tkey); ok {
|
||||
for _, p := range strings.Split(ts, ",") {
|
||||
if p == tval {
|
||||
return fld.Name, nil
|
||||
return fld.Name, val.Interface(), nil
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,17 +54,17 @@ func StructFieldNameByTag(src interface{}, tkey string, tval string) (string, er
|
||||
switch val.Kind() {
|
||||
case reflect.Ptr:
|
||||
if val = val.Elem(); val.Kind() == reflect.Struct {
|
||||
if name, err := StructFieldNameByTag(val.Interface(), tkey, tval); err == nil {
|
||||
return name, nil
|
||||
if name, fld, err := StructFieldNameByTag(val.Interface(), tkey, tval); err == nil {
|
||||
return name, fld, nil
|
||||
}
|
||||
}
|
||||
case reflect.Struct:
|
||||
if name, err := StructFieldNameByTag(val.Interface(), tkey, tval); err == nil {
|
||||
return name, nil
|
||||
if name, fld, err := StructFieldNameByTag(val.Interface(), tkey, tval); err == nil {
|
||||
return name, fld, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return "", ErrNotFound
|
||||
return "", nil, ErrNotFound
|
||||
}
|
||||
|
||||
// StructFieldByTag get struct field by tag key and its value
|
||||
@@ -111,10 +111,21 @@ func StructFieldByTag(src interface{}, tkey string, tval string) (interface{}, e
|
||||
|
||||
// ZeroFieldByPath clean struct field by its path
|
||||
func ZeroFieldByPath(src interface{}, path string) error {
|
||||
if src == nil {
|
||||
return nil
|
||||
}
|
||||
var err error
|
||||
val := reflect.ValueOf(src)
|
||||
|
||||
if IsEmpty(val) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, p := range strings.Split(path, ".") {
|
||||
if IsEmpty(val) {
|
||||
return nil
|
||||
}
|
||||
|
||||
val, err = structValueByName(val, p)
|
||||
if err != nil {
|
||||
return err
|
||||
|
Reference in New Issue
Block a user