Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 8 additions & 17 deletions observability-tracing-aws-xray/internal/api/gen/models.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 28 additions & 29 deletions observability-tracing-aws-xray/internal/api/gen/server.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 14 additions & 35 deletions observability-tracing-aws-xray/internal/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,44 +280,23 @@ func toSpanDetailsResponse(span *xray.SpanDetail) gen.TraceSpanDetailsResponse {
startTime := span.StartTime
endTime := span.EndTime

attrs := make([]struct {
Key *string `json:"key,omitempty"`
Value *string `json:"value,omitempty"`
}, 0, len(span.Attributes))
for _, a := range span.Attributes {
key := a.Key
value := a.Value
attrs = append(attrs, struct {
Key *string `json:"key,omitempty"`
Value *string `json:"value,omitempty"`
}{Key: &key, Value: &value})
resp := gen.TraceSpanDetailsResponse{
SpanId: &span.SpanID,
SpanName: &span.SpanName,
SpanKind: &span.SpanKind,
StartTime: &startTime,
EndTime: &endTime,
DurationNs: &dur,
ParentSpanId: &span.ParentSpanID,
Status: ptr(gen.TraceSpanDetailsResponseStatus(span.Status)),
}

resAttrs := make([]struct {
Key *string `json:"key,omitempty"`
Value *string `json:"value,omitempty"`
}, 0, len(span.ResourceAttributes))
for _, a := range span.ResourceAttributes {
key := a.Key
value := a.Value
resAttrs = append(resAttrs, struct {
Key *string `json:"key,omitempty"`
Value *string `json:"value,omitempty"`
}{Key: &key, Value: &value})
if span.Attributes != nil {
resp.Attributes = &span.Attributes
}

return gen.TraceSpanDetailsResponse{
SpanId: &span.SpanID,
SpanName: &span.SpanName,
SpanKind: &span.SpanKind,
StartTime: &startTime,
EndTime: &endTime,
DurationNs: &dur,
ParentSpanId: &span.ParentSpanID,
Status: ptr(gen.TraceSpanDetailsResponseStatus(span.Status)),
Attributes: &attrs,
ResourceAttributes: &resAttrs,
if span.ResourceAttributes != nil {
resp.ResourceAttributes = &span.ResourceAttributes
}
return resp
}

func ptr[T any](v T) *T {
Expand Down
9 changes: 2 additions & 7 deletions observability-tracing-aws-xray/internal/xray/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ type SpansResult struct {
TookMs int
}

type SpanAttribute struct {
Key string
Value string
}

type SpanDetail struct {
SpanID string
SpanName string
Expand All @@ -93,8 +88,8 @@ type SpanDetail struct {
DurationNs int64
ParentSpanID string
Status string
Attributes []SpanAttribute
ResourceAttributes []SpanAttribute
Attributes map[string]interface{}
ResourceAttributes map[string]interface{}
}

type SpanDetailResult struct {
Expand Down
20 changes: 10 additions & 10 deletions observability-tracing-aws-xray/internal/xray/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,37 +675,37 @@ func segmentToSpanDetail(seg *xraySegment, parentID string) *SpanDetail {
Status: segmentStatus(seg),
}

attrs := make([]SpanAttribute, 0)
attrs := make(map[string]interface{})
for k, v := range seg.Annotations {
attrs = append(attrs, SpanAttribute{Key: "annotation." + k, Value: fmt.Sprintf("%v", v)})
attrs["annotation."+k] = v
}
for k, v := range flattenMap("http", seg.HTTP) {
attrs = append(attrs, SpanAttribute{Key: k, Value: fmt.Sprintf("%v", v)})
attrs[k] = v
}
for k, v := range flattenMap("sql", seg.SQL) {
attrs = append(attrs, SpanAttribute{Key: k, Value: fmt.Sprintf("%v", v)})
attrs[k] = v
}
if seg.Namespace != "" {
attrs = append(attrs, SpanAttribute{Key: "xray.namespace", Value: seg.Namespace})
attrs["xray.namespace"] = seg.Namespace
}
if seg.Origin != "" {
attrs = append(attrs, SpanAttribute{Key: "xray.origin", Value: seg.Origin})
attrs["xray.origin"] = seg.Origin
}
detail.Attributes = attrs

resAttrs := make([]SpanAttribute, 0)
resAttrs := make(map[string]interface{})
for k, v := range flattenMap("aws", seg.AWS) {
resAttrs = append(resAttrs, SpanAttribute{Key: k, Value: fmt.Sprintf("%v", v)})
resAttrs[k] = v
}
if seg.Origin != "" {
resAttrs = append(resAttrs, SpanAttribute{Key: "cloud.platform", Value: seg.Origin})
resAttrs["cloud.platform"] = seg.Origin
}

if seg.Metadata != nil {
for ns, v := range seg.Metadata {
if nsMap, ok := v.(map[string]interface{}); ok {
for k, mv := range nsMap {
resAttrs = append(resAttrs, SpanAttribute{Key: fmt.Sprintf("metadata.%s.%s", ns, k), Value: fmt.Sprintf("%v", mv)})
resAttrs[fmt.Sprintf("metadata.%s.%s", ns, k)] = mv
}
}
}
Expand Down
36 changes: 36 additions & 0 deletions observability-tracing-aws-xray/internal/xray/queries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,42 @@ func TestFlattenMap(t *testing.T) {
}
}

// Regression for #3886: segment annotations keep their native types in the
// span detail instead of being stringified.
func TestSegmentToSpanDetail_PreservesNativeTypes(t *testing.T) {
seg := &xraySegment{
ID: "1a2b3c",
Name: "checkout",
StartTime: json.Number("1.0"),
EndTime: json.Number("2.0"),
Annotations: map[string]interface{}{
"retry_count": 3,
"ratio": 0.5,
"cache_hit": true,
"region": "us-east-1",
},
}

detail := segmentToSpanDetail(seg, "")

if v, ok := detail.Attributes["annotation.retry_count"].(int); !ok || v != 3 {
t.Errorf("retry_count: expected int(3), got %T(%v)",
detail.Attributes["annotation.retry_count"], detail.Attributes["annotation.retry_count"])
}
if v, ok := detail.Attributes["annotation.ratio"].(float64); !ok || v != 0.5 {
t.Errorf("ratio: expected float64(0.5), got %T(%v)",
detail.Attributes["annotation.ratio"], detail.Attributes["annotation.ratio"])
}
if v, ok := detail.Attributes["annotation.cache_hit"].(bool); !ok || !v {
t.Errorf("cache_hit: expected bool(true), got %T(%v)",
detail.Attributes["annotation.cache_hit"], detail.Attributes["annotation.cache_hit"])
}
if v, ok := detail.Attributes["annotation.region"].(string); !ok || v != "us-east-1" {
t.Errorf("region: expected string(us-east-1), got %T(%v)",
detail.Attributes["annotation.region"], detail.Attributes["annotation.region"])
}
}

func contains(s, substr string) bool {
return len(s) >= len(substr) && searchSubstring(s, substr)
}
Loading