Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
nhulston committed Jan 15, 2025
1 parent 02da8e3 commit 9790821
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
29 changes: 16 additions & 13 deletions contrib/aws/internal/span_pointers/span_pointers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package span_pointers
import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"fmt"
"github.com/aws/smithy-go/middleware"
smithyhttp "github.com/aws/smithy-go/transport/http"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace"
Expand Down Expand Up @@ -50,13 +50,13 @@ func HandleS3Operation(in middleware.DeserializeInput, out middleware.Deserializ
components := []string{bucket, key, etag}
hash := generatePointerHash(components)

ctxWithLinks, ok := span.Context().(ddtrace.SpanContextWithLinks)
if !ok {
log.Debug("Span links could not be found. Unable to create S3 span pointer.")
return
}
//ctxWithLinks, ok := span.Context().(ddtrace.SpanContextWithLinks)
//if !ok {
// log.Debug("Span links could not be found. Unable to create S3 span pointer.")
// return
//}

links := ctxWithLinks.SpanLinks()
//links := ctxWithLinks.SpanLinks()
link := ddtrace.SpanLink{
// We leave trace_id, span_id, trade_id_high, tracestate, and flags as 0 or empty.
// The Datadog frontend will use `ptr.hash` to find the linked span.
Expand All @@ -67,12 +67,15 @@ func HandleS3Operation(in middleware.DeserializeInput, out middleware.Deserializ
"link.kind": LinkKind,
},
}
links = append(links, link)
if spanLinksJsonBytes, err := json.Marshal(links); err == nil {
span.SetTag("_dd.span_links", string(spanLinksJsonBytes))
} else {
log.Debug("Span links could not be marshalled. Unable to create S3 span pointer.")
}
fmt.Println("Adding link...")
span.AddSpanLinks(link)
fmt.Println("Link added!")
//links = append(links, link)
//if spanLinksJsonBytes, err := json.Marshal(links); err == nil {
// span.SetTag("_dd.span_links", string(spanLinksJsonBytes))
//} else {
// log.Debug("Span links could not be marshalled. Unable to create S3 span pointer.")
//}
}

// generatePointerHash generates a unique hash from an array of strings by joining them with | before hashing.
Expand Down
3 changes: 3 additions & 0 deletions ddtrace/ddtrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ type Span interface {
// item should propagate to all descendant spans, both in- and cross-process.
SetBaggageItem(key, val string)

// AddSpanLinks appends the given links to the span's span links.
AddSpanLinks(spanLinks ...SpanLink)

// Finish finishes the current span with the given options. Finish calls should be idempotent.
Finish(opts ...FinishOption)

Expand Down
4 changes: 4 additions & 0 deletions ddtrace/tracer/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,10 @@ func (s *span) setMetric(key string, v float64) {
}
}

func (s *span) AddSpanLinks(spanLinks ...ddtrace.SpanLink) {
s.SpanLinks = append(s.SpanLinks, spanLinks...)
}

// Finish closes this Span (but not its children) providing the duration
// of its part of the tracing session.
func (s *span) Finish(opts ...ddtrace.FinishOption) {
Expand Down

0 comments on commit 9790821

Please sign in to comment.