Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(traces): fixing missing span attributes #4014

Merged
merged 3 commits into from
Sep 10, 2024
Merged
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
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
}
Loading