Skip to content

Commit

Permalink
fix(traces): fixing missing span attributes (#4014)
Browse files Browse the repository at this point in the history
* fix(traces): fixing missing span attributes

* adding default service name as tracetest for root span

* patching bug
  • Loading branch information
xoscar authored Sep 10, 2024
1 parent 0039562 commit 4935bdd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
14 changes: 14 additions & 0 deletions server/traces/otel_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ func FromOtelResourceSpans(resourceSpans []*v1.ResourceSpans) Trace {
flattenSpans := make([]*v1.Span, 0)
for _, resource := range resourceSpans {
for _, scopeSpans := range resource.ScopeSpans {
for _, span := range scopeSpans.Spans {
// if service exists, add it as an attribute
if scopeSpans.Scope != nil {
span.Attributes = append(span.Attributes, &v11.KeyValue{
Key: MetadataServiceName,
Value: &v11.AnyValue{Value: &v11.AnyValue_StringValue{StringValue: scopeSpans.Scope.Name}},
})

// Add attributes from the resource
span.Attributes = append(span.Attributes, scopeSpans.Scope.Attributes...)
}
}

flattenSpans = append(flattenSpans, scopeSpans.Spans...)
}
}
Expand Down Expand Up @@ -64,6 +77,7 @@ func ConvertOtelSpanIntoSpan(span *v1.Span) *Span {

spanID := createSpanID(span.SpanId)
attributes.Set(TracetestMetadataFieldParentID, createSpanID(span.ParentSpanId).String())

return &Span{
ID: spanID,
Name: span.Name,
Expand Down
4 changes: 4 additions & 0 deletions server/traces/span_entitiess.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const (
TracetestMetadataFieldKind string = "tracetest.span.kind"
TracetestMetadataFieldStatusCode string = "tracetest.span.status_code"
TracetestMetadataFieldStatusDescription string = "tracetest.span.status_description"

MetadataServiceName string = "service.name"
TracetestServiceName string = "tracetest"
)

func NewAttributes(inputs ...map[string]string) Attributes {
Expand Down Expand Up @@ -370,5 +373,6 @@ func (span Span) setTriggerResultAttributes(result trigger.TriggerResult) Span {
span.Attributes.Set("tracetest.response.headers", string(jsonheaders))
}

span.Attributes.Set(MetadataServiceName, TracetestServiceName)
return span
}

0 comments on commit 4935bdd

Please sign in to comment.