func()

in enrichments/trace/internal/elastic/span.go [497:535]


func (s *spanEnrichmentContext) setDestinationService(span ptrace.Span) {
	var destnResource string
	if s.peerService != "" {
		destnResource = s.peerService
	}

	switch {
	case s.isDB:
		if destnResource == "" && s.dbSystem != "" {
			destnResource = s.dbSystem
		}
	case s.isMessaging:
		if destnResource == "" && s.messagingSystem != "" {
			destnResource = s.messagingSystem
		}
		// For parity with apm-data, destn resource does not handle
		// temporary destination flag. However, it is handled by
		// service.target fields and we might want to do the same here.
		if destnResource != "" && s.messagingDestinationName != "" {
			destnResource += "/" + s.messagingDestinationName
		}
	case s.isRPC, s.isHTTP:
		if destnResource == "" {
			if res := getHostPort(
				s.urlFull, s.urlDomain, s.urlPort,
				s.serverAddress, s.serverPort, // fallback
			); res != "" {
				destnResource = res
			} else {
				// fallback to RPC service
				destnResource = s.rpcService
			}
		}
	}

	if destnResource != "" {
		span.Attributes().PutStr(elasticattr.SpanDestinationServiceResource, destnResource)
	}
}