diff --git a/ddtrace/ddtrace.go b/ddtrace/ddtrace.go index e311b5ff25..768146e7ac 100644 --- a/ddtrace/ddtrace.go +++ b/ddtrace/ddtrace.go @@ -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. diff --git a/ddtrace/tracer/spancontext.go b/ddtrace/tracer/spancontext.go index 29da1b80b1..44419241db 100644 --- a/ddtrace/tracer/spancontext.go +++ b/ddtrace/tracer/spancontext.go @@ -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 @@ -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 { @@ -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 {