You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.0 KiB
46 lines
1.0 KiB
package collector |
|
|
|
import ( |
|
"net/url" |
|
"strings" |
|
) |
|
|
|
import ( |
|
"go-common/app/service/main/dapper/model" |
|
) |
|
|
|
// OperationNameProcess fix operation name so sad! |
|
type OperationNameProcess struct{} |
|
|
|
// Process implement operation name |
|
func (o *OperationNameProcess) Process(span *model.Span) error { |
|
switch { |
|
case !span.IsServer() && strings.HasPrefix(span.OperationName, "http://"): |
|
o.fixHTTP(span) |
|
} |
|
return nil |
|
} |
|
|
|
func (o *OperationNameProcess) fixHTTP(span *model.Span) { |
|
oldOperationName := span.OperationName |
|
method := "UNKONWN" |
|
if methodTag := span.GetTagString("http.method"); methodTag != "" { |
|
method = methodTag |
|
} |
|
operationName := "HTTP:" + method |
|
span.SetOperationName(operationName) |
|
|
|
peerSign := oldOperationName |
|
if strings.HasPrefix(oldOperationName, "http://") { |
|
if reqURL, err := url.Parse(oldOperationName); err == nil { |
|
peerSign = reqURL.Path |
|
span.SetTag("http.url", oldOperationName) |
|
} |
|
} |
|
span.SetTag("_peer.sign", peerSign) |
|
} |
|
|
|
// NewOperationNameProcess . |
|
func NewOperationNameProcess() Processer { |
|
return &OperationNameProcess{} |
|
}
|
|
|