Skip to content

Commit

Permalink
rename Bundle.ParentTrace -> Bundle.Parent
Browse files Browse the repository at this point in the history
  • Loading branch information
muir committed Oct 4, 2022
1 parent a8bbcbd commit 6e2220f
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 44 deletions.
2 changes: 1 addition & 1 deletion logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion span.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion span.zzzgo
Original file line number Diff line number Diff line change
Expand Up @@ -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() }

Expand Down
20 changes: 10 additions & 10 deletions trace/bundle.go
Original file line number Diff line number Diff line change
@@ -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(),
}
}
6 changes: 3 additions & 3 deletions xopjson/jsonlogger.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions xopjson/jsonlogger.zzzgo
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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() {
Expand Down
6 changes: 3 additions & 3 deletions xopmiddle/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions xopmiddle/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions xopmiddle/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
}
Expand All @@ -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
Expand All @@ -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])
}

Expand Down
2 changes: 1 addition & 1 deletion xopotel/otel.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion xopotel/otel.zzzgo
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
10 changes: 5 additions & 5 deletions xoptest/xoptestutil/cases.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,18 +480,18 @@ 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")
return bundle
}()),
},
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")
Expand Down

0 comments on commit 6e2220f

Please sign in to comment.