mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-01-26 03:52:03 +02:00
address feedback
This commit is contained in:
parent
7c6554fc4d
commit
c8578e1512
@ -426,15 +426,15 @@ func peerInfoFromContext(ctx context.Context) []core.KeyValue {
|
|||||||
return peerInfoFromTarget(p.Addr.String())
|
return peerInfoFromTarget(p.Addr.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
var fullMethodRegexp = regexp.MustCompile(`^/(?:\S*/)?(?:\S*\.)?(\S*)/\S*$`)
|
var fullMethodRegexp = regexp.MustCompile(`^\/?(?:\S+\.)?(\S+)\/\S+$`)
|
||||||
|
|
||||||
func serviceFromFullMethod(method string) string {
|
func serviceFromFullMethod(method string) string {
|
||||||
match := fullMethodRegexp.FindAllStringSubmatch(method, 1)
|
match := fullMethodRegexp.FindStringSubmatch(method)
|
||||||
if (len(match) == 0) || (len(match) > 1 && len(match[1]) != 2) {
|
if len(match) == 0 {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
return match[0][1]
|
return match[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
func addEventForMessageReceived(ctx context.Context, id int, m interface{}) {
|
func addEventForMessageReceived(ctx context.Context, id int, m interface{}) {
|
||||||
|
@ -30,15 +30,7 @@ type testExporter struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *testExporter) ExportSpan(ctx context.Context, s *export.SpanData) {
|
func (t *testExporter) ExportSpan(ctx context.Context, s *export.SpanData) {
|
||||||
var spans []*export.SpanData
|
t.spanMap[s.Name] = append(t.spanMap[s.Name], s)
|
||||||
var ok bool
|
|
||||||
|
|
||||||
if spans, ok = t.spanMap[s.Name]; !ok {
|
|
||||||
spans = []*export.SpanData{}
|
|
||||||
t.spanMap[s.Name] = spans
|
|
||||||
}
|
|
||||||
spans = append(spans, s)
|
|
||||||
t.spanMap[s.Name] = spans
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type mockCCInvoker struct {
|
type mockCCInvoker struct {
|
||||||
@ -72,16 +64,23 @@ func TestUCISimpleMethodNameSetsServiceNameAttribute(t *testing.T) {
|
|||||||
testUCISetsExpectedNameAttribute(t, simpleName, expectedServiceName)
|
testUCISetsExpectedNameAttribute(t, simpleName, expectedServiceName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUCIUnamedMethodSetsEmptyNameAttribute(t *testing.T) {
|
func TestUCIInvalidMethodSetsEmptyNameAttribute(t *testing.T) {
|
||||||
expectedServiceName := ""
|
expectedServiceName := ""
|
||||||
emptyName := fmt.Sprintf("/%s/bar", expectedServiceName)
|
emptyName := "invalidMethodName"
|
||||||
|
|
||||||
testUCISetsExpectedNameAttribute(t, emptyName, expectedServiceName)
|
testUCISetsExpectedNameAttribute(t, emptyName, expectedServiceName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUCILongMethodNameSetsServiceNameAttribute(t *testing.T) {
|
func TestUCILongMethodNameSetsServiceNameAttribute(t *testing.T) {
|
||||||
expectedServiceName := "serviceName"
|
expectedServiceName := "serviceName"
|
||||||
emptyServiceFullName := fmt.Sprintf("/github.com/foo.baz/bar/foo.%s/bar", expectedServiceName)
|
emptyServiceFullName := fmt.Sprintf("/github.com.foo.baz.%s/bar", expectedServiceName)
|
||||||
|
|
||||||
|
testUCISetsExpectedNameAttribute(t, emptyServiceFullName, expectedServiceName)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUCINonAlhanumericMethodNameSetsServiceNameAttribute(t *testing.T) {
|
||||||
|
expectedServiceName := "serviceName_123"
|
||||||
|
emptyServiceFullName := fmt.Sprintf("/faz.bar/baz.%s/bar", expectedServiceName)
|
||||||
|
|
||||||
testUCISetsExpectedNameAttribute(t, emptyServiceFullName, expectedServiceName)
|
testUCISetsExpectedNameAttribute(t, emptyServiceFullName, expectedServiceName)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user