Skip to content

Commit

Permalink
Merge pull request #82 from xoplog/seventy
Browse files Browse the repository at this point in the history
Rename a couple of things
  • Loading branch information
muir authored Oct 3, 2022
2 parents 55ae5c3 + 0e5de30 commit 21d70e0
Show file tree
Hide file tree
Showing 18 changed files with 96 additions and 108 deletions.
12 changes: 0 additions & 12 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@

# required before ready to use in production

- misc

- rename trace.Bundle.TraceParent to Bundle.ParentTrace
- remame xoptest.Request.Trace to Bundle

- repo

- create xop org, move repo there

- test

- actually feed xopotel traces into Jaeger
- propagation

- drop rest/ or finish it

- integrations

- resty

- documentation

Expand Down
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.TraceParent = seed.spanSeed.traceBundle.Trace
seed.spanSeed.traceBundle.ParentTrace = 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) TraceParent() trace.Trace { return span.seed.traceBundle.TraceParent.Copy() }
func (span *Span) ParentTrace() trace.Trace { return span.seed.traceBundle.ParentTrace.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
6 changes: 3 additions & 3 deletions trace/bundle.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package trace

type Bundle struct {
TraceParent Trace
ParentTrace Trace
Trace Trace
State State
Baggage Baggage
}

func NewBundle() Bundle {
return Bundle{
TraceParent: NewTrace(),
ParentTrace: NewTrace(),
Trace: NewTrace(),
}
}

func (b Bundle) Copy() Bundle {
return Bundle{
TraceParent: b.TraceParent.Copy(),
ParentTrace: b.ParentTrace.Copy(),
Trace: b.Trace.Copy(),
State: b.State.Copy(),
Baggage: b.Baggage.Copy(),
Expand Down
4 changes: 2 additions & 2 deletions xopjson/jsonlogger.go

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

4 changes: 2 additions & 2 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.trace.Trace.TraceID().String())
rq.AddSafeKey("span.id")
rq.AddSafeString(s.trace.Trace.SpanID().String())
if !s.trace.TraceParent.TraceID().IsZero() {
if !s.trace.ParentTrace.TraceID().IsZero() {
rq.AddSafeKey("trace.parent")
rq.AddSafeString(s.trace.TraceParent.String())
rq.AddSafeString(s.trace.ParentTrace.String())
}
if !s.trace.State.IsZero() {
rq.AddSafeKey("trace.state")
Expand Down
24 changes: 12 additions & 12 deletions xopjson/jsonlogger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,21 +232,21 @@ func newChecker(t *testing.T, tlog *xoptest.TestLogger, config checkConfig) *che
}
for i, span := range tlog.Spans {
if debugTspan {
t.Logf("recorded span: %s - %s", span.Trace.Trace.SpanID().String(), span.Name)
t.Logf("recorded span: %s - %s", span.Bundle.Trace.SpanID().String(), span.Name)
}
_, ok := c.spanIndex[span.Trace.Trace.SpanID().String()]
assert.Falsef(t, ok, "duplicate span id %s", span.Trace.Trace.SpanID().String())
c.spanIndex[span.Trace.Trace.SpanID().String()] = i
_, ok := c.spanIndex[span.Bundle.Trace.SpanID().String()]
assert.Falsef(t, ok, "duplicate span id %s", span.Bundle.Trace.SpanID().String())
c.spanIndex[span.Bundle.Trace.SpanID().String()] = i
}
for i, request := range tlog.Requests {
if debugTspan {
t.Logf("recorded request: %s - %s", request.Trace.Trace.SpanID().String(), request.Name)
t.Logf("recorded request: %s - %s", request.Bundle.Trace.SpanID().String(), request.Name)
}
_, ok := c.spanIndex[request.Trace.Trace.SpanID().String()]
assert.Falsef(t, ok, "duplicate span/request id %s", request.Trace.Trace.SpanID().String())
_, ok = c.requestIndex[request.Trace.Trace.SpanID().String()]
assert.Falsef(t, ok, "duplicate request id %s", request.Trace.Trace.SpanID().String())
c.requestIndex[request.Trace.Trace.SpanID().String()] = i
_, ok := c.spanIndex[request.Bundle.Trace.SpanID().String()]
assert.Falsef(t, ok, "duplicate span/request id %s", request.Bundle.Trace.SpanID().String())
_, ok = c.requestIndex[request.Bundle.Trace.SpanID().String()]
assert.Falsef(t, ok, "duplicate request id %s", request.Bundle.Trace.SpanID().String())
c.requestIndex[request.Bundle.Trace.SpanID().String()] = i
}
for spanID, versions := range c.sequencing {
if c.config.minVersions == c.config.maxVersions {
Expand Down Expand Up @@ -291,7 +291,7 @@ func (c *checker) check(t *testing.T, data string) {
}
}
for _, span := range c.tlog.Spans {
spanAttributes := c.accumulatedSpans[span.Trace.Trace.SpanID().String()]
spanAttributes := c.accumulatedSpans[span.Bundle.Trace.SpanID().String()]
if len(span.Metadata) != 0 || len(spanAttributes) != 0 {
if c.config.hasAttributesObject {
t.Logf("comparing metadata: %+v vs %+v", span.Metadata, spanAttributes)
Expand All @@ -302,7 +302,7 @@ func (c *checker) check(t *testing.T, data string) {
}
}
for _, span := range c.tlog.Requests {
spanAttributes := c.accumulatedSpans[span.Trace.Trace.SpanID().String()]
spanAttributes := c.accumulatedSpans[span.Bundle.Trace.SpanID().String()]
if len(span.Metadata) != 0 || len(spanAttributes) != 0 {
if c.config.hasAttributesObject {
t.Logf("comparing metadata: %+v vs %+v", span.Metadata, spanAttributes)
Expand Down
8 changes: 4 additions & 4 deletions xopmiddle/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,18 @@ func (i Inbound) makeChildSpan(w http.ResponseWriter, r *http.Request) (*xop.Log
if b3 := r.Header.Get("b3"); b3 != "" {
SetByB3Header(&bundle, b3)
} else if tp := r.Header.Get("traceparent"); tp != "" {
SetByTraceParentHeader(&bundle, tp)
SetByParentTraceHeader(&bundle, tp)
} else if b3TraceID := r.Header.Get("X-B3-TraceId"); b3TraceID != "" {
bundle.Trace.TraceID().SetString(b3TraceID)
if b3Sampling := r.Header.Get("X-B3-Sampled"); b3Sampling != "" {
SetByB3Sampled(&bundle.Trace, b3Sampling)
}
bundle.TraceParent = bundle.Trace
bundle.ParentTrace = bundle.Trace
if b3ParentSpanID := r.Header.Get("X-B3-ParentSpanId"); b3ParentSpanID != "" {
bundle.TraceParent.SpanID().SetString(b3ParentSpanID)
bundle.ParentTrace.SpanID().SetString(b3ParentSpanID)
} else {
// Uh oh, no parent span id
bundle.TraceParent.SpanID().SetZero()
bundle.ParentTrace.SpanID().SetZero()
}
if b3SpanID := r.Header.Get("X-B3-SpanId"); b3SpanID != "" {
bundle.Trace.SpanID().SetString(b3SpanID)
Expand Down
24 changes: 12 additions & 12 deletions xopmiddle/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,30 +187,30 @@ func TestHandlerFuncMiddleware(t *testing.T) {

require.Equal(t, 1, len(tLog.Requests), "one request")
request := tLog.Requests[0]
assert.Equal(t, hc.expectParentTrace, request.Trace.TraceParent.TraceID().String(), "parent traceID")
assert.Equal(t, hc.expectParentSpan, request.Trace.TraceParent.SpanID().String(), "parent spanID")
assert.Equal(t, "00", request.Trace.TraceParent.Version().String(), "parent version")
assert.Equal(t, hc.expectParentFlags, request.Trace.TraceParent.Flags().String(), "parent flags")
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")

if hc.expectTrace == "" {
hc.expectTrace = hc.expectParentTrace
}

if hc.expectTrace == "random" {
assert.False(t, request.Trace.Trace.TraceID().IsZero(), "trace traceID zero")
assert.False(t, request.Bundle.Trace.TraceID().IsZero(), "trace traceID zero")
} else {
assert.Equal(t, hc.expectTrace, request.Trace.Trace.TraceID().String(), "trace traceID")
assert.Equal(t, hc.expectTrace, request.Bundle.Trace.TraceID().String(), "trace traceID")
}
if hc.expectSpan != "" {
assert.Equal(t, hc.expectSpan, request.Trace.Trace.SpanID().String(), "trace spanID")
assert.Equal(t, hc.expectSpan, request.Bundle.Trace.SpanID().String(), "trace spanID")
} else {
assert.False(t, request.Trace.Trace.SpanID().IsZero(), "trace spanID is zero")
assert.NotEqual(t, hc.expectParentSpan, request.Trace.Trace.SpanID().String(), "trace spanID")
assert.False(t, request.Bundle.Trace.SpanID().IsZero(), "trace spanID is zero")
assert.NotEqual(t, hc.expectParentSpan, request.Bundle.Trace.SpanID().String(), "trace spanID")
}
assert.Equal(t, "00", request.Trace.Trace.Version().String(), "trace version")
assert.Equal(t, hc.expectFlags, request.Trace.Trace.Flags().String(), "trace flags")
assert.Equal(t, "00", request.Bundle.Trace.Version().String(), "trace version")
assert.Equal(t, hc.expectFlags, request.Bundle.Trace.Flags().String(), "trace flags")

assert.Equal(t, request.Trace.Trace.String(), w.Header().Get("traceresponse"), "trace response header")
assert.Equal(t, request.Bundle.Trace.String(), w.Header().Get("traceresponse"), "trace response header")
})
}
})
Expand Down
24 changes: 12 additions & 12 deletions xopmiddle/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ import (
"github.com/muir/xop-go/trace"
)

// SetByTraceParentHeader sets bundle.TraceParent.TraceID and
// then copies bundle.TraceParent to bundle.Trace. It then sets
// SetByParentTraceHeader sets bundle.ParentTrace.TraceID and
// then copies bundle.ParentTrace to bundle.Trace. It then sets
// the bundle.Trace.SpanID to random.
//
// "traceparent" header
// Example: 00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01
func SetByTraceParentHeader(b *trace.Bundle, h string) {
func SetByParentTraceHeader(b *trace.Bundle, h string) {
parent, ok := trace.TraceFromString(h)
if !ok {
b.Trace = trace.NewTrace()
b.Trace.TraceID().SetRandom()
b.Trace.SpanID().SetRandom()
return
}
b.TraceParent = parent
b.ParentTrace = 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.TraceParent = trace.NewTrace()
SetByB3Sampled(&b.TraceParent, h)
b.Trace = b.TraceParent
b.ParentTrace = trace.NewTrace()
SetByB3Sampled(&b.ParentTrace, h)
b.Trace = b.ParentTrace
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.TraceParent.TraceID().SetString(m[1])
SetByB3Sampled(&b.TraceParent, m[3])
b.ParentTrace.TraceID().SetString(m[1])
SetByB3Sampled(&b.ParentTrace, m[3])
if m[4] == "" {
b.TraceParent.SpanID().SetZero()
b.ParentTrace.SpanID().SetZero()
} else {
b.TraceParent.SpanID().SetString(m[4])
b.ParentTrace.SpanID().SetString(m[4])
}
b.Trace = b.TraceParent
b.Trace = b.ParentTrace
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.TraceParent.IsZero() {
if bundle.ParentTrace.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
24 changes: 12 additions & 12 deletions xopotel/otel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,21 +238,21 @@ func newChecker(t *testing.T, tlog *xoptest.TestLogger, spansNotIntTest []string
}
for i, span := range tlog.Spans {
if debugTspan {
t.Logf("recorded span: %s - %s", span.Trace.Trace.SpanID().String(), span.Name)
t.Logf("recorded span: %s - %s", span.Bundle.Trace.SpanID().String(), span.Name)
}
_, ok := c.spanIndex[span.Trace.Trace.SpanID().String()]
assert.Falsef(t, ok, "duplicate span id %s", span.Trace.Trace.SpanID().String())
c.spanIndex[span.Trace.Trace.SpanID().String()] = i
_, ok := c.spanIndex[span.Bundle.Trace.SpanID().String()]
assert.Falsef(t, ok, "duplicate span id %s", span.Bundle.Trace.SpanID().String())
c.spanIndex[span.Bundle.Trace.SpanID().String()] = i
}
for i, request := range tlog.Requests {
if debugTspan {
t.Logf("recorded request: %s - %s", request.Trace.Trace.SpanID().String(), request.Name)
t.Logf("recorded request: %s - %s", request.Bundle.Trace.SpanID().String(), request.Name)
}
_, ok := c.spanIndex[request.Trace.Trace.SpanID().String()]
assert.Falsef(t, ok, "duplicate span/request id %s", request.Trace.Trace.SpanID().String())
_, ok = c.requestIndex[request.Trace.Trace.SpanID().String()]
assert.Falsef(t, ok, "duplicate request id %s", request.Trace.Trace.SpanID().String())
c.requestIndex[request.Trace.Trace.SpanID().String()] = i
_, ok := c.spanIndex[request.Bundle.Trace.SpanID().String()]
assert.Falsef(t, ok, "duplicate span/request id %s", request.Bundle.Trace.SpanID().String())
_, ok = c.requestIndex[request.Bundle.Trace.SpanID().String()]
assert.Falsef(t, ok, "duplicate request id %s", request.Bundle.Trace.SpanID().String())
c.requestIndex[request.Bundle.Trace.SpanID().String()] = i
}
return c
}
Expand All @@ -279,13 +279,13 @@ func (c *checker) check(t *testing.T, data string) {
}
}
for _, span := range c.tlog.Spans {
spanAttributes := c.accumulatedSpans[span.Trace.Trace.SpanID().String()]
spanAttributes := c.accumulatedSpans[span.Bundle.Trace.SpanID().String()]
if len(span.Metadata) != 0 || len(spanAttributes.data) != 0 {
compareData(t, span.Metadata, span.MetadataType, "xoptest.Metadata", spanAttributes.data, "xoptel.span.generic", true)
}
}
for _, span := range c.tlog.Requests {
spanAttributes := c.accumulatedSpans[span.Trace.Trace.SpanID().String()]
spanAttributes := c.accumulatedSpans[span.Bundle.Trace.SpanID().String()]
if len(span.Metadata) != 0 || len(spanAttributes.data) != 0 {
compareData(t, span.Metadata, span.MetadataType, "xoptest.Metadata", spanAttributes.data, "xopotel.span.generic", true)
}
Expand Down
2 changes: 1 addition & 1 deletion xopresty/resty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func TestXopResty(t *testing.T) {
assert.NoError(t, err, "Get")
assert.True(t, called, "handler called")

text := "T1.1.1: traceresponse http.remote_trace=" + farSideSpan.Trace.Trace.String()
text := "T1.1.1: traceresponse http.remote_trace=" + farSideSpan.Bundle.Trace.String()
assert.Equalf(t, 1, tLog.CountLines(xoptest.TextContains(text)), "count lines with '%s'", text)

for _, text := range tc.expectedText {
Expand Down
Loading

0 comments on commit 21d70e0

Please sign in to comment.