Skip to content

Commit

Permalink
Merge pull request #21 from opentracing/bg/make_id_uint64
Browse files Browse the repository at this point in the history
Replace int64 to uint64 for Trace and Span IDs
  • Loading branch information
bg451 committed Mar 31, 2016
2 parents f95feba + 3c81427 commit 0e8c84d
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 53 deletions.
6 changes: 3 additions & 3 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package basictracer
// Context holds the basic Span metadata.
type Context struct {
// A probabilistically unique identifier for a [multi-span] trace.
TraceID int64
TraceID uint64

// A probabilistically unique identifier for a span.
SpanID int64
SpanID uint64

// The SpanID of this Context's parent, or 0 if there is no parent.
ParentSpanID int64
ParentSpanID uint64

// Whether the trace is sampled.
Sampled bool
Expand Down
4 changes: 2 additions & 2 deletions propagation.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ type accessorPropagator struct {
// by types which have a means of storing the trace metadata and already know
// how to serialize themselves (for example, protocol buffers).
type DelegatingCarrier interface {
SetState(traceID, spanID int64, sampled bool)
State() (traceID, spanID int64, sampled bool)
SetState(traceID, spanID uint64, sampled bool)
State() (traceID, spanID uint64, sampled bool)
SetBaggageItem(key, value string)
GetBaggage(func(key, value string))
}
Expand Down
10 changes: 5 additions & 5 deletions propagation_ot.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ func (p *textMapPropagator) Inject(
if !ok {
return opentracing.ErrInvalidCarrier
}
carrier.Set(fieldNameTraceID, strconv.FormatInt(sc.raw.TraceID, 16))
carrier.Set(fieldNameSpanID, strconv.FormatInt(sc.raw.SpanID, 16))
carrier.Set(fieldNameTraceID, strconv.FormatUint(sc.raw.TraceID, 16))
carrier.Set(fieldNameSpanID, strconv.FormatUint(sc.raw.SpanID, 16))
carrier.Set(fieldNameSampled, strconv.FormatBool(sc.raw.Sampled))

sc.Lock()
Expand All @@ -62,19 +62,19 @@ func (p *textMapPropagator) Join(
return nil, opentracing.ErrInvalidCarrier
}
requiredFieldCount := 0
var traceID, propagatedSpanID int64
var traceID, propagatedSpanID uint64
var sampled bool
var err error
decodedBaggage := make(map[string]string)
err = carrier.ForeachKey(func(k, v string) error {
switch strings.ToLower(k) {
case fieldNameTraceID:
traceID, err = strconv.ParseInt(v, 16, 64)
traceID, err = strconv.ParseUint(v, 16, 64)
if err != nil {
return opentracing.ErrTraceCorrupted
}
case fieldNameSpanID:
propagatedSpanID, err = strconv.ParseInt(v, 16, 64)
propagatedSpanID, err = strconv.ParseUint(v, 16, 64)
if err != nil {
return opentracing.ErrTraceCorrupted
}
Expand Down
6 changes: 3 additions & 3 deletions tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ type Options struct {
// to allow deterministic sampling decisions to be made across different nodes.
// For example,
//
// func(traceID int64) { return traceID % 64 == 0 }
// func(traceID uint64) { return traceID % 64 == 0 }
//
// samples every 64th trace on average.
ShouldSample func(int64) bool
ShouldSample func(uint64) bool
// TrimUnsampledSpans turns potentially expensive operations on unsampled
// Spans into no-ops. More precisely, tags, baggage items, and log events
// are silently discarded. If NewSpanEventListener is set, the callbacks
Expand Down Expand Up @@ -80,7 +80,7 @@ type Options struct {
// returned object with a Tracer.
func DefaultOptions() Options {
var opts Options
opts.ShouldSample = func(traceID int64) bool { return traceID%64 == 0 }
opts.ShouldSample = func(traceID uint64) bool { return traceID%64 == 0 }
opts.NewSpanEventListener = func() func(SpanEvent) { return nil }
return opts
}
Expand Down
8 changes: 4 additions & 4 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ var (
seededIDLock sync.Mutex
)

func randomID() int64 {
func randomID() uint64 {
seededIDLock.Lock()
defer seededIDLock.Unlock()
return seededIDGen.Int63()
return uint64(seededIDGen.Int63())
}

func randomID2() (int64, int64) {
func randomID2() (uint64, uint64) {
seededIDLock.Lock()
defer seededIDLock.Unlock()
return seededIDGen.Int63(), seededIDGen.Int63()
return uint64(seededIDGen.Int63()), uint64(seededIDGen.Int63())
}
4 changes: 2 additions & 2 deletions wire/carrier.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ package wire
type ProtobufCarrier TracerState

// SetState set's the tracer state.
func (p *ProtobufCarrier) SetState(traceID, spanID int64, sampled bool) {
func (p *ProtobufCarrier) SetState(traceID, spanID uint64, sampled bool) {
p.TraceId = traceID
p.SpanId = spanID
p.Sampled = sampled
}

// State returns the tracer state.
func (p *ProtobufCarrier) State() (traceID, spanID int64, sampled bool) {
func (p *ProtobufCarrier) State() (traceID, spanID uint64, sampled bool) {
traceID = p.TraceId
spanID = p.SpanId
sampled = p.Sampled
Expand Down
2 changes: 1 addition & 1 deletion wire/carrier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
func TestProtobufCarrier(t *testing.T) {
var carrier basictracer.DelegatingCarrier = &wire.ProtobufCarrier{}

var traceID, spanID int64 = 1, 2
var traceID, spanID uint64 = 1, 2
sampled := true
baggageKey, expVal := "key1", "val1"

Expand Down
64 changes: 33 additions & 31 deletions wire/wire.pb.go

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

4 changes: 2 additions & 2 deletions wire/wire.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package basictracer_go.wire;
option go_package = "wire";

message TracerState {
sfixed64 trace_id = 1;
sfixed64 span_id = 2;
fixed64 trace_id = 1;
fixed64 span_id = 2;
bool sampled = 3;
map<string, string> baggage_items = 4;
}

0 comments on commit 0e8c84d

Please sign in to comment.