operation_name.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package collector
  2. import (
  3. "net/url"
  4. "strings"
  5. )
  6. import (
  7. "go-common/app/service/main/dapper/model"
  8. )
  9. // OperationNameProcess fix operation name so sad!
  10. type OperationNameProcess struct{}
  11. // Process implement operation name
  12. func (o *OperationNameProcess) Process(span *model.Span) error {
  13. switch {
  14. case !span.IsServer() && strings.HasPrefix(span.OperationName, "http://"):
  15. o.fixHTTP(span)
  16. }
  17. return nil
  18. }
  19. func (o *OperationNameProcess) fixHTTP(span *model.Span) {
  20. oldOperationName := span.OperationName
  21. method := "UNKONWN"
  22. if methodTag := span.GetTagString("http.method"); methodTag != "" {
  23. method = methodTag
  24. }
  25. operationName := "HTTP:" + method
  26. span.SetOperationName(operationName)
  27. peerSign := oldOperationName
  28. if strings.HasPrefix(oldOperationName, "http://") {
  29. if reqURL, err := url.Parse(oldOperationName); err == nil {
  30. peerSign = reqURL.Path
  31. span.SetTag("http.url", oldOperationName)
  32. }
  33. }
  34. span.SetTag("_peer.sign", peerSign)
  35. }
  36. // NewOperationNameProcess .
  37. func NewOperationNameProcess() Processer {
  38. return &OperationNameProcess{}
  39. }