diff --git a/server/traces/otel_converter.go b/server/traces/otel_converter.go index e16c6f42ea..b10d60f4ca 100644 --- a/server/traces/otel_converter.go +++ b/server/traces/otel_converter.go @@ -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...) } } @@ -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, diff --git a/server/traces/span_entitiess.go b/server/traces/span_entitiess.go index 676a9ea7e7..d893783c4d 100644 --- a/server/traces/span_entitiess.go +++ b/server/traces/span_entitiess.go @@ -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 { @@ -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 }