Skip to content

Commit

Permalink
preparing for extracted span links PR
Browse files Browse the repository at this point in the history
  • Loading branch information
mhlidd committed Nov 8, 2024
1 parent 716a72c commit 687c23f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ddtrace/ddtrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ type SpanContextW3C interface {
TraceID128Bytes() [16]byte
}

// SpanContextWithLinks represents a SpanContext with additional methods for
// access to the SpanLinks on the span context, if present.
type SpanContextWithLinks interface {
SpanContext

// SpanLinks returns the span links on the SpanContext.
SpanLinks() []SpanLink

// Setlinks takes in a slice of SpanLinks and sets them to the SpanContext.
SetLinks(links []SpanLink)
}

// Tracer specifies an implementation of the Datadog tracer which allows starting
// and propagating spans. The official implementation if exposed as functions
// within the "tracer" package.
Expand Down
12 changes: 12 additions & 0 deletions ddtrace/tracer/spancontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ type spanContext struct {
baggage map[string]string
hasBaggage uint32 // atomic int for quick checking presence of baggage. 0 indicates no baggage, otherwise baggage exists.
origin string // e.g. "synthetics"

spanLinks []ddtrace.SpanLink // links to related spans in separate|external|disconnected traces
}

// newSpanContext creates a new SpanContext to serve as context for the given
Expand Down Expand Up @@ -166,6 +168,8 @@ func (c *spanContext) SpanID() uint64 { return c.spanID }
// TraceID implements ddtrace.SpanContext.
func (c *spanContext) TraceID() uint64 { return c.traceID.Lower() }

func (c *spanContext) TraceIDUpper() uint64 { return c.traceID.Upper() }

// TraceID128 implements ddtrace.SpanContextW3C.
func (c *spanContext) TraceID128() string {
if c == nil {
Expand All @@ -179,6 +183,14 @@ func (c *spanContext) TraceID128Bytes() [16]byte {
return c.traceID
}

func (c *spanContext) SpanLinks() []ddtrace.SpanLink {
return c.spanLinks
}

func (c *spanContext) SetLinks(links []ddtrace.SpanLink) {
c.spanLinks = links
}

// ForeachBaggageItem implements ddtrace.SpanContext.
func (c *spanContext) ForeachBaggageItem(handler func(k, v string) bool) {
if atomic.LoadUint32(&c.hasBaggage) == 0 {
Expand Down

0 comments on commit 687c23f

Please sign in to comment.