diff --git a/logger.go b/logger.go index c8eb7213..cc85c783 100644 --- a/logger.go +++ b/logger.go @@ -143,7 +143,7 @@ func (sub *Sub) Log() *Log { } func (old *Log) newChildLog(seed Seed, description string, detached bool) *Log { - seed.spanSeed.traceBundle.ParentTrace = seed.spanSeed.traceBundle.Trace + seed.spanSeed.traceBundle.Parent = seed.spanSeed.traceBundle.Trace seed = seed.react(false, description) type singleAlloc struct { diff --git a/span.go b/span.go index b0c00f81..6e52b6b3 100644 --- a/span.go +++ b/span.go @@ -25,7 +25,7 @@ func (log *Log) Span() *Span { func (span *Span) TraceState() trace.State { return span.seed.traceBundle.State } func (span *Span) TraceBaggage() trace.Baggage { return span.seed.traceBundle.Baggage } -func (span *Span) ParentTrace() trace.Trace { return span.seed.traceBundle.ParentTrace.Copy() } +func (span *Span) ParentTrace() trace.Trace { return span.seed.traceBundle.Parent.Copy() } func (span *Span) Trace() trace.Trace { return span.seed.traceBundle.Trace.Copy() } func (span *Span) Bundle() trace.Bundle { return span.seed.traceBundle.Copy() } diff --git a/span.zzzgo b/span.zzzgo index de68a4c5..10aa914b 100644 --- a/span.zzzgo +++ b/span.zzzgo @@ -21,7 +21,7 @@ func (log *Log) Span() *Span { func (span *Span) TraceState() trace.State { return span.seed.traceBundle.State } func (span *Span) TraceBaggage() trace.Baggage { return span.seed.traceBundle.Baggage } -func (span *Span) ParentTrace() trace.Trace { return span.seed.traceBundle.ParentTrace.Copy() } +func (span *Span) ParentTrace() trace.Trace { return span.seed.traceBundle.Parent.Copy() } func (span *Span) Trace() trace.Trace { return span.seed.traceBundle.Trace.Copy() } func (span *Span) Bundle() trace.Bundle { return span.seed.traceBundle.Copy() } diff --git a/trace/bundle.go b/trace/bundle.go index 715aac4a..b3e99b03 100644 --- a/trace/bundle.go +++ b/trace/bundle.go @@ -1,24 +1,24 @@ package trace type Bundle struct { - ParentTrace Trace - Trace Trace - State State - Baggage Baggage + Parent Trace + Trace Trace + State State + Baggage Baggage } func NewBundle() Bundle { return Bundle{ - ParentTrace: NewTrace(), - Trace: NewTrace(), + Parent: NewTrace(), + Trace: NewTrace(), } } func (b Bundle) Copy() Bundle { return Bundle{ - ParentTrace: b.ParentTrace.Copy(), - Trace: b.Trace.Copy(), - State: b.State.Copy(), - Baggage: b.Baggage.Copy(), + Parent: b.Parent.Copy(), + Trace: b.Trace.Copy(), + State: b.State.Copy(), + Baggage: b.Baggage.Copy(), } } diff --git a/xopjson/jsonlogger.go b/xopjson/jsonlogger.go index a3ff32b2..5689b3af 100644 --- a/xopjson/jsonlogger.go +++ b/xopjson/jsonlogger.go @@ -98,9 +98,9 @@ func (s *span) addRequestStartData(rq *builder) { rq.AddSafeString(s.bundle.Trace.TraceID().String()) rq.AddSafeKey("span.id") rq.AddSafeString(s.bundle.Trace.SpanID().String()) - if !s.bundle.ParentTrace.TraceID().IsZero() { + if !s.bundle.Parent.TraceID().IsZero() { rq.AddSafeKey("trace.parent") - rq.AddSafeString(s.bundle.ParentTrace.String()) + rq.AddSafeString(s.bundle.Parent.String()) } if !s.bundle.State.IsZero() { rq.AddSafeKey("trace.state") @@ -262,7 +262,7 @@ func (s *span) Span(_ context.Context, ts time.Time, bundle trace.Bundle, name s func (s *span) spanStartData(rq *builder) { rq.stringKV("span.name", s.name) rq.Time("ts", s.startTime) - rq.stringKV("span.parent_span", s.bundle.ParentTrace.SpanID().String()) + rq.stringKV("span.parent_span", s.bundle.Parent.SpanID().String()) } func (s *span) setSpanIDPrefill() { diff --git a/xopjson/jsonlogger.zzzgo b/xopjson/jsonlogger.zzzgo index ab6912cd..dd3b8e80 100644 --- a/xopjson/jsonlogger.zzzgo +++ b/xopjson/jsonlogger.zzzgo @@ -96,9 +96,9 @@ func (s *span) addRequestStartData(rq *builder) { rq.AddSafeString(s.bundle.Trace.TraceID().String()) rq.AddSafeKey("span.id") rq.AddSafeString(s.bundle.Trace.SpanID().String()) - if !s.bundle.ParentTrace.TraceID().IsZero() { + if !s.bundle.Parent.TraceID().IsZero() { rq.AddSafeKey("trace.parent") - rq.AddSafeString(s.bundle.ParentTrace.String()) + rq.AddSafeString(s.bundle.Parent.String()) } if !s.bundle.State.IsZero() { rq.AddSafeKey("trace.state") @@ -260,7 +260,7 @@ func (s *span) Span(_ context.Context, ts time.Time, bundle trace.Bundle, name s func (s *span) spanStartData(rq *builder) { rq.stringKV("span.name", s.name) rq.Time("ts", s.startTime) - rq.stringKV("span.parent_span", s.bundle.ParentTrace.SpanID().String()) + rq.stringKV("span.parent_span", s.bundle.Parent.SpanID().String()) } func (s *span) setSpanIDPrefill() { diff --git a/xopmiddle/middleware.go b/xopmiddle/middleware.go index a1b21651..737663e1 100644 --- a/xopmiddle/middleware.go +++ b/xopmiddle/middleware.go @@ -81,12 +81,12 @@ func (i Inbound) makeChildSpan(w http.ResponseWriter, r *http.Request) (*xop.Log if b3Sampling := r.Header.Get("X-B3-Sampled"); b3Sampling != "" { SetByB3Sampled(&bundle.Trace, b3Sampling) } - bundle.ParentTrace = bundle.Trace + bundle.Parent = bundle.Trace if b3ParentSpanID := r.Header.Get("X-B3-ParentSpanId"); b3ParentSpanID != "" { - bundle.ParentTrace.SpanID().SetString(b3ParentSpanID) + bundle.Parent.SpanID().SetString(b3ParentSpanID) } else { // Uh oh, no parent span id - bundle.ParentTrace.SpanID().SetZero() + bundle.Parent.SpanID().SetZero() } if b3SpanID := r.Header.Get("X-B3-SpanId"); b3SpanID != "" { bundle.Trace.SpanID().SetString(b3SpanID) diff --git a/xopmiddle/middleware_test.go b/xopmiddle/middleware_test.go index 3fd319cd..58b953f7 100644 --- a/xopmiddle/middleware_test.go +++ b/xopmiddle/middleware_test.go @@ -187,10 +187,10 @@ func TestHandlerFuncMiddleware(t *testing.T) { require.Equal(t, 1, len(tLog.Requests), "one request") request := tLog.Requests[0] - assert.Equal(t, hc.expectParentTrace, request.Bundle.ParentTrace.TraceID().String(), "parent traceID") - assert.Equal(t, hc.expectParentSpan, request.Bundle.ParentTrace.SpanID().String(), "parent spanID") - assert.Equal(t, "00", request.Bundle.ParentTrace.Version().String(), "parent version") - assert.Equal(t, hc.expectParentFlags, request.Bundle.ParentTrace.Flags().String(), "parent flags") + assert.Equal(t, hc.expectParentTrace, request.Bundle.Parent.TraceID().String(), "parent traceID") + assert.Equal(t, hc.expectParentSpan, request.Bundle.Parent.SpanID().String(), "parent spanID") + assert.Equal(t, "00", request.Bundle.Parent.Version().String(), "parent version") + assert.Equal(t, hc.expectParentFlags, request.Bundle.Parent.Flags().String(), "parent flags") if hc.expectTrace == "" { hc.expectTrace = hc.expectParentTrace diff --git a/xopmiddle/utils.go b/xopmiddle/utils.go index 102acdf7..6ffdb948 100644 --- a/xopmiddle/utils.go +++ b/xopmiddle/utils.go @@ -6,8 +6,8 @@ import ( "github.com/xoplog/xop-go/trace" ) -// SetByParentTraceHeader sets bundle.ParentTrace.TraceID and -// then copies bundle.ParentTrace to bundle.Trace. It then sets +// SetByParentTraceHeader sets bundle.Parent.TraceID and +// then copies bundle.Parent to bundle.Trace. It then sets // the bundle.Trace.SpanID to random. // // "traceparent" header @@ -20,7 +20,7 @@ func SetByParentTraceHeader(b *trace.Bundle, h string) { b.Trace.SpanID().SetRandom() return } - b.ParentTrace = parent + b.Parent = parent b.Trace = parent b.Trace.SpanID().SetRandom() } @@ -32,9 +32,9 @@ var b3RE = regexp.MustCompile(`^([a-fA-F0-9]{32})-([a-fA-F0-9]{16})-(0|1|true|fa func SetByB3Header(b *trace.Bundle, h string) { switch h { case "0", "1", "true", "false", "d": - b.ParentTrace = trace.NewTrace() - SetByB3Sampled(&b.ParentTrace, h) - b.Trace = b.ParentTrace + b.Parent = trace.NewTrace() + SetByB3Sampled(&b.Parent, h) + b.Trace = b.Parent b.Trace.TraceID().SetRandom() b.Trace.SpanID().SetRandom() return @@ -43,14 +43,14 @@ func SetByB3Header(b *trace.Bundle, h string) { if m == nil { return } - b.ParentTrace.TraceID().SetString(m[1]) - SetByB3Sampled(&b.ParentTrace, m[3]) + b.Parent.TraceID().SetString(m[1]) + SetByB3Sampled(&b.Parent, m[3]) if m[4] == "" { - b.ParentTrace.SpanID().SetZero() + b.Parent.SpanID().SetZero() } else { - b.ParentTrace.SpanID().SetString(m[4]) + b.Parent.SpanID().SetString(m[4]) } - b.Trace = b.ParentTrace + b.Trace = b.Parent b.Trace.SpanID().SetString(m[2]) } diff --git a/xopotel/otel.go b/xopotel/otel.go index 8781aa37..d24253aa 100644 --- a/xopotel/otel.go +++ b/xopotel/otel.go @@ -93,7 +93,7 @@ func BaseLogger(ctx context.Context, tracer oteltrace.Tracer, doLogging bool) xo } ctx, span := tracer.Start(ctx, nameOrDescription, oteltrace.WithNewRoot()) bundle := seed.Bundle() - if bundle.ParentTrace.IsZero() { + if bundle.Parent.IsZero() { bundle.State.SetString(span.SpanContext().TraceState().String()) bundle.Trace.Flags().Set([1]byte{byte(span.SpanContext().TraceFlags())}) bundle.Trace.Version().Set([1]byte{1}) diff --git a/xopotel/otel.zzzgo b/xopotel/otel.zzzgo index 65ef415a..0a14cee2 100644 --- a/xopotel/otel.zzzgo +++ b/xopotel/otel.zzzgo @@ -90,7 +90,7 @@ func BaseLogger(ctx context.Context, tracer oteltrace.Tracer, doLogging bool) xo } ctx, span := tracer.Start(ctx, nameOrDescription, oteltrace.WithNewRoot()) bundle := seed.Bundle() - if bundle.ParentTrace.IsZero() { + if bundle.Parent.IsZero() { bundle.State.SetString(span.SpanContext().TraceState().String()) bundle.Trace.Flags().Set([1]byte{byte(span.SpanContext().TraceFlags())}) bundle.Trace.Version().Set([1]byte{1}) diff --git a/xoptest/xoptestutil/cases.go b/xoptest/xoptestutil/cases.go index 03a4d82c..7af90789 100644 --- a/xoptest/xoptestutil/cases.go +++ b/xoptest/xoptestutil/cases.go @@ -480,10 +480,10 @@ var MessageCases = []struct { SeedMods: []xop.SeedModifier{ xop.WithBundle(func() trace.Bundle { var bundle trace.Bundle - bundle.ParentTrace.Flags().SetString("01") - bundle.ParentTrace.TraceID().SetString("a60a3cc0123a043fee48839c9d52a645") - bundle.ParentTrace.SpanID().SetString("c63f9d81e2285f34") - bundle.Trace = bundle.ParentTrace + bundle.Parent.Flags().SetString("01") + bundle.Parent.TraceID().SetString("a60a3cc0123a043fee48839c9d52a645") + bundle.Parent.SpanID().SetString("c63f9d81e2285f34") + bundle.Trace = bundle.Parent bundle.Trace.SpanID().SetRandom() bundle.State.SetString("congo=t61rcWkgMzE") bundle.Baggage.SetString("userId=alice,serverNode=DF%2028,isProduction=false") @@ -491,7 +491,7 @@ var MessageCases = []struct { }()), }, Do: func(t *testing.T, log *xop.Log, tlog *xoptest.TestLogger) { - assert.Equal(t, "00-a60a3cc0123a043fee48839c9d52a645-c63f9d81e2285f34-01", log.Span().Bundle().ParentTrace.String(), "trace parent") + assert.Equal(t, "00-a60a3cc0123a043fee48839c9d52a645-c63f9d81e2285f34-01", log.Span().Bundle().Parent.String(), "trace parent") assert.Equal(t, "a60a3cc0123a043fee48839c9d52a645", log.Span().Bundle().Trace.GetTraceID().String(), "trace trace") assert.NotEqual(t, "c63f9d81e2285f34", log.Span().Bundle().Trace.GetSpanID().String(), "trace trace") assert.Equal(t, "congo=t61rcWkgMzE", log.Span().Bundle().State.String(), "trace state")