This repository has been archived by the owner on Mar 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from opentracing/bhs/span_context_revival
Update to support opentracing.SpanContext (and References)
- Loading branch information
Showing
13 changed files
with
236 additions
and
244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,62 @@ | ||
package basictracer | ||
|
||
// Context holds the basic Span metadata. | ||
type Context struct { | ||
import ( | ||
"sync" | ||
|
||
"github.com/opentracing/opentracing-go" | ||
) | ||
|
||
// SpanContext holds the basic Span metadata. | ||
type SpanContext struct { | ||
// A probabilistically unique identifier for a [multi-span] trace. | ||
TraceID uint64 | ||
|
||
// A probabilistically unique identifier for a span. | ||
SpanID uint64 | ||
|
||
// The SpanID of this Context's parent, or 0 if there is no parent. | ||
ParentSpanID uint64 | ||
|
||
// Whether the trace is sampled. | ||
Sampled bool | ||
|
||
// The span's associated baggage. | ||
baggageLock sync.Mutex | ||
Baggage map[string]string // initialized on first use | ||
} | ||
|
||
// BaggageItem belongs to the opentracing.SpanContext interface | ||
func (c *SpanContext) BaggageItem(key string) string { | ||
// TODO: if we want to support onBaggage, need a pointer to the bt.Span. | ||
// s.onBaggage(canonicalKey, val) | ||
// if s.trim() { | ||
// return s | ||
// } | ||
|
||
c.baggageLock.Lock() | ||
defer c.baggageLock.Unlock() | ||
|
||
if c.Baggage == nil { | ||
return "" | ||
} | ||
return c.Baggage[key] | ||
} | ||
|
||
// SetBaggageItem belongs to the opentracing.SpanContext interface | ||
func (c *SpanContext) SetBaggageItem(key, val string) opentracing.SpanContext { | ||
c.baggageLock.Lock() | ||
defer c.baggageLock.Unlock() | ||
if c.Baggage == nil { | ||
c.Baggage = make(map[string]string) | ||
} | ||
c.Baggage[key] = val | ||
return c | ||
} | ||
|
||
// ForeachBaggageItem belongs to the opentracing.SpanContext interface | ||
func (c *SpanContext) ForeachBaggageItem(handler func(k, v string) bool) { | ||
c.baggageLock.Lock() | ||
defer c.baggageLock.Unlock() | ||
for k, v := range c.Baggage { | ||
if !handler(k, v) { | ||
break | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.