Skip to content

Commit 4400949

Browse files
authored
Add rpc.service for the destination.service.resource calculation (#160)
1 parent 1a05d8f commit 4400949

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

enrichments/trace/internal/elastic/span.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,9 @@ func (s *spanEnrichmentContext) setDestinationService(span ptrace.Span) {
463463
s.serverAddress, s.serverPort, // fallback
464464
); res != "" {
465465
destnResource = res
466+
} else {
467+
// fallback to RPC service
468+
destnResource = s.rpcService
466469
}
467470
}
468471
}

enrichments/trace/internal/elastic/span_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,33 @@ func TestElasticSpanEnrich(t *testing.T) {
938938
elasticattr.SuccessCount: int64(1),
939939
},
940940
},
941+
{
942+
name: "rpc_span_with_only_rpc_sevice_attr",
943+
input: func() ptrace.Span {
944+
span := getElasticSpan()
945+
span.SetName("testspan")
946+
// rpc.service should be used as destination.service.resource
947+
// if no other attributes are present.
948+
span.Attributes().PutStr(semconv25.AttributeRPCService, "myService")
949+
span.Attributes().PutStr(semconv25.AttributeRPCSystem, "grpc")
950+
return span
951+
}(),
952+
config: config.Enabled().Span,
953+
enrichedAttrs: map[string]any{
954+
elasticattr.TimestampUs: startTs.AsTime().UnixMicro(),
955+
elasticattr.SpanName: "testspan",
956+
elasticattr.ProcessorEvent: "span",
957+
elasticattr.SpanRepresentativeCount: float64(1),
958+
elasticattr.SpanType: "external",
959+
elasticattr.SpanSubtype: "grpc",
960+
elasticattr.SpanDurationUs: expectedDuration.Microseconds(),
961+
elasticattr.EventOutcome: "success",
962+
elasticattr.SuccessCount: int64(1),
963+
elasticattr.ServiceTargetType: "grpc",
964+
elasticattr.ServiceTargetName: "myService",
965+
elasticattr.SpanDestinationServiceResource: "myService",
966+
},
967+
},
941968
} {
942969
t.Run(tc.name, func(t *testing.T) {
943970
expectedSpan := ptrace.NewSpan()

0 commit comments

Comments
 (0)