...
1
2
3
4 package internal
5
6 import (
7 "strings"
8
9 "go.opentelemetry.io/otel/attribute"
10 semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
11 )
12
13
14
15
16
17
18
19 func ParseFullMethod(fullMethod string) (string, []attribute.KeyValue) {
20 if !strings.HasPrefix(fullMethod, "/") {
21
22 return fullMethod, nil
23 }
24 name := fullMethod[1:]
25 pos := strings.LastIndex(name, "/")
26 if pos < 0 {
27
28 return name, nil
29 }
30 service, method := name[:pos], name[pos+1:]
31
32 var attrs []attribute.KeyValue
33 if service != "" {
34 attrs = append(attrs, semconv.RPCService(service))
35 }
36 if method != "" {
37 attrs = append(attrs, semconv.RPCMethod(method))
38 }
39 return name, attrs
40 }
41
View as plain text