Skip to content

Commit

Permalink
fix(ddtrace/tracer): use "_dd.span_links" to get the span links in mo…
Browse files Browse the repository at this point in the history
…cktracer
  • Loading branch information
darccio committed Feb 21, 2025
1 parent 5ad4fed commit 0ae5db7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func TestHandleS3Operation(t *testing.T) {
if tt.expectSuccess {
require.Len(t, spans, 1)
links := spans[0].Links()
assert.NotEmpty(t, links, "Expected span links to not be empty")
require.NotEmpty(t, links, "Expected span links to not be empty")

attributes := links[0].Attributes
assert.Equal(t, S3PointerKind, attributes["ptr.kind"])
Expand Down
12 changes: 10 additions & 2 deletions ddtrace/mocktracer/mockspan.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package mocktracer // import "github.com/DataDog/dd-trace-go/v2/ddtrace/mocktracer"

import (
"encoding/json"
"fmt"
"time"

Expand Down Expand Up @@ -207,9 +208,16 @@ func (s *Span) Unwrap() *tracer.Span {

// Links returns the span's span links.
func (s *Span) Links() []tracer.SpanLink {
return s.links
payload := s.Tag("_dd.span_links")
if payload == nil {
return nil
}
// Unmarshal the JSON payload into the SpanLink slice.
var links []tracer.SpanLink
json.Unmarshal([]byte(payload.(string)), &links)
return links
}

func (s *Span) AddSpanLink(link tracer.SpanLink) {
s.links = append(s.links, link)
s.sp.AddSpanLink(link)
}

0 comments on commit 0ae5db7

Please sign in to comment.