Compare commits
No commits in common. "v3" and "v3.11.20" have entirely different histories.
@ -68,7 +68,15 @@ func (md Metadata) Iterator() *Iterator {
|
||||
}
|
||||
|
||||
func (md Metadata) MustGet(key string) string {
|
||||
val, ok := md.Get(key)
|
||||
// fast path
|
||||
val, ok := md[key]
|
||||
if !ok {
|
||||
// slow path
|
||||
val, ok = md[textproto.CanonicalMIMEHeaderKey(key)]
|
||||
if !ok {
|
||||
val, ok = md[strings.ToLower(key)]
|
||||
}
|
||||
}
|
||||
if !ok {
|
||||
panic("missing metadata key")
|
||||
}
|
||||
@ -111,18 +119,11 @@ func (md Metadata) Del(keys ...string) {
|
||||
}
|
||||
}
|
||||
|
||||
// Copy makes a copy of the metadata
|
||||
func (md Metadata) CopyTo(dst Metadata) {
|
||||
for k, v := range md {
|
||||
dst[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
// Copy makes a copy of the metadata
|
||||
func Copy(md Metadata, exclude ...string) Metadata {
|
||||
nmd := New(len(md))
|
||||
for k, v := range md {
|
||||
nmd[k] = v
|
||||
for key, val := range md {
|
||||
nmd.Set(key, val)
|
||||
}
|
||||
nmd.Del(exclude...)
|
||||
return nmd
|
||||
@ -146,7 +147,7 @@ func Merge(omd Metadata, mmd Metadata, overwrite bool) Metadata {
|
||||
case ok && !overwrite:
|
||||
continue
|
||||
case val != "":
|
||||
nmd[key] = val
|
||||
nmd.Set(key, val)
|
||||
case ok && val == "":
|
||||
nmd.Del(key)
|
||||
}
|
||||
@ -160,8 +161,6 @@ func Pairs(kv ...string) (Metadata, bool) {
|
||||
return nil, false
|
||||
}
|
||||
md := New(len(kv) / 2)
|
||||
for idx := 0; idx < len(kv); idx += 2 {
|
||||
md[kv[idx]] = kv[idx+1]
|
||||
}
|
||||
md.Set(kv...)
|
||||
return md, true
|
||||
}
|
||||
|
@ -1,18 +0,0 @@
|
||||
package semconv
|
||||
|
||||
var (
|
||||
// HeaderTopic is the header name that contains topic name
|
||||
HeaderTopic = "Micro-Topic"
|
||||
// HeaderContentType specifies content type of message
|
||||
HeaderContentType = "Content-Type"
|
||||
// HeaderEndpoint specifies endpoint in service
|
||||
HeaderEndpoint = "Micro-Endpoint"
|
||||
// HeaderService specifies service
|
||||
HeaderService = "Micro-Service"
|
||||
// HeaderTimeout specifies timeout of operation
|
||||
HeaderTimeout = "Micro-Timeout"
|
||||
// HeaderAuthorization specifies Authorization header
|
||||
HeaderAuthorization = "Authorization"
|
||||
// HeaderXRequestID specifies request id
|
||||
HeaderXRequestID = "X-Request-Id"
|
||||
)
|
@ -37,15 +37,6 @@ func NewContext(ctx context.Context, tracer Tracer) context.Context {
|
||||
|
||||
type spanKey struct{}
|
||||
|
||||
// SpanFromContext returns a span from context
|
||||
func SpanMustContext(ctx context.Context) Span {
|
||||
sp, ok := SpanFromContext(ctx)
|
||||
if !ok {
|
||||
panic("missing span")
|
||||
}
|
||||
return sp
|
||||
}
|
||||
|
||||
// SpanFromContext returns a span from context
|
||||
func SpanFromContext(ctx context.Context) (Span, bool) {
|
||||
if ctx == nil {
|
||||
|
@ -25,7 +25,6 @@ func (t *Tracer) Start(ctx context.Context, name string, opts ...tracer.SpanOpti
|
||||
name: name,
|
||||
ctx: ctx,
|
||||
tracer: t,
|
||||
labels: options.Labels,
|
||||
kind: options.Kind,
|
||||
startTime: time.Now(),
|
||||
}
|
||||
@ -38,14 +37,6 @@ func (t *Tracer) Start(ctx context.Context, name string, opts ...tracer.SpanOpti
|
||||
return tracer.NewSpanContext(ctx, span), span
|
||||
}
|
||||
|
||||
type memoryStringer struct {
|
||||
s string
|
||||
}
|
||||
|
||||
func (s memoryStringer) String() string {
|
||||
return s.s
|
||||
}
|
||||
|
||||
func (t *Tracer) Flush(_ context.Context) error {
|
||||
return nil
|
||||
}
|
||||
@ -61,6 +52,14 @@ func (t *Tracer) Name() string {
|
||||
return t.opts.Name
|
||||
}
|
||||
|
||||
type noopStringer struct {
|
||||
s string
|
||||
}
|
||||
|
||||
func (s noopStringer) String() string {
|
||||
return s.s
|
||||
}
|
||||
|
||||
type Span struct {
|
||||
ctx context.Context
|
||||
tracer tracer.Tracer
|
||||
@ -68,8 +67,8 @@ type Span struct {
|
||||
statusMsg string
|
||||
startTime time.Time
|
||||
finishTime time.Time
|
||||
traceID memoryStringer
|
||||
spanID memoryStringer
|
||||
traceID noopStringer
|
||||
spanID noopStringer
|
||||
events []*Event
|
||||
labels []interface{}
|
||||
logs []interface{}
|
||||
|
@ -2,7 +2,6 @@ package tracer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"go.unistack.org/micro/v3/util/id"
|
||||
)
|
||||
@ -24,7 +23,6 @@ func (t *noopTracer) Start(ctx context.Context, name string, opts ...SpanOption)
|
||||
name: name,
|
||||
ctx: ctx,
|
||||
tracer: t,
|
||||
startTime: time.Now(),
|
||||
labels: options.Labels,
|
||||
kind: options.Kind,
|
||||
}
|
||||
@ -33,6 +31,7 @@ func (t *noopTracer) Start(ctx context.Context, name string, opts ...SpanOption)
|
||||
if span.ctx == nil {
|
||||
span.ctx = context.Background()
|
||||
}
|
||||
t.spans = append(t.spans, span)
|
||||
return NewSpanContext(ctx, span), span
|
||||
}
|
||||
|
||||
@ -59,16 +58,21 @@ func (t *noopTracer) Name() string {
|
||||
return t.opts.Name
|
||||
}
|
||||
|
||||
type noopEvent struct {
|
||||
name string
|
||||
labels []interface{}
|
||||
}
|
||||
|
||||
type noopSpan struct {
|
||||
ctx context.Context
|
||||
tracer Tracer
|
||||
name string
|
||||
statusMsg string
|
||||
startTime time.Time
|
||||
finishTime time.Time
|
||||
traceID noopStringer
|
||||
spanID noopStringer
|
||||
events []*noopEvent
|
||||
labels []interface{}
|
||||
logs []interface{}
|
||||
kind SpanKind
|
||||
status SpanStatus
|
||||
}
|
||||
@ -82,7 +86,6 @@ func (s *noopSpan) SpanID() string {
|
||||
}
|
||||
|
||||
func (s *noopSpan) Finish(_ ...SpanOption) {
|
||||
s.finishTime = time.Now()
|
||||
}
|
||||
|
||||
func (s *noopSpan) Context() context.Context {
|
||||
@ -94,6 +97,8 @@ func (s *noopSpan) Tracer() Tracer {
|
||||
}
|
||||
|
||||
func (s *noopSpan) AddEvent(name string, opts ...EventOption) {
|
||||
options := NewEventOptions(opts...)
|
||||
s.events = append(s.events, &noopEvent{name: name, labels: options.Labels})
|
||||
}
|
||||
|
||||
func (s *noopSpan) SetName(name string) {
|
||||
@ -101,6 +106,7 @@ func (s *noopSpan) SetName(name string) {
|
||||
}
|
||||
|
||||
func (s *noopSpan) AddLogs(kv ...interface{}) {
|
||||
s.logs = append(s.logs, kv...)
|
||||
}
|
||||
|
||||
func (s *noopSpan) AddLabels(kv ...interface{}) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user