Skip to content

Commit

Permalink
refactor: replace reflection based proto.equal with optimized sizevt
Browse files Browse the repository at this point in the history
  • Loading branch information
kruskall committed Sep 14, 2023
1 parent 4c1dc48 commit c1625ef
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions input/otlp/traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import (
semconv "go.opentelemetry.io/collector/semconv/v1.5.0"
"go.uber.org/zap"
"google.golang.org/grpc/codes"
"google.golang.org/protobuf/proto"

"github.com/elastic/apm-data/model/modelpb"
)
Expand Down Expand Up @@ -415,7 +414,7 @@ func TranslateTransaction(
}

if isHTTP {
if !proto.Equal(&http, &modelpb.HTTP{}) {
if http.SizeVT() != 0 {
event.Http = &http
}

Expand Down Expand Up @@ -744,7 +743,7 @@ func TranslateSpan(spanKind ptrace.SpanKind, attributes pcommon.Map, event *mode
if httpResponse.StatusCode > 0 && event.Event.Outcome == outcomeUnknown {
event.Event.Outcome = clientHTTPStatusCodeOutcome(int(httpResponse.StatusCode))
}
if !proto.Equal(&http, &modelpb.HTTP{}) {
if http.SizeVT() != 0 {
event.Http = &http
}
event.Url = populateNil(event.Url)
Expand Down Expand Up @@ -851,15 +850,15 @@ func TranslateSpan(spanKind ptrace.SpanKind, attributes pcommon.Map, event *mode
if destAddr != "" {
event.Destination = &modelpb.Destination{Address: destAddr, Port: uint32(destPort)}
}
if !proto.Equal(&destinationService, &modelpb.DestinationService{}) {
if destinationService.SizeVT() != 0 {
if destinationService.Type == "" {
// Copy span type to destination.service.type.
destinationService.Type = event.Span.Type
}
event.Span.DestinationService = &destinationService
}

if !proto.Equal(&serviceTarget, &modelpb.ServiceTarget{}) {
if serviceTarget.SizeVT() != 0 {
event.Service.Target = &serviceTarget
}

Expand Down

0 comments on commit c1625ef

Please sign in to comment.