1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-01-12 02:28:07 +02:00

address feedback

This commit is contained in:
Stefan Prisca 2020-05-02 14:50:11 +02:00
parent 7c6554fc4d
commit c8578e1512
2 changed files with 15 additions and 16 deletions

View File

@ -426,15 +426,15 @@ func peerInfoFromContext(ctx context.Context) []core.KeyValue {
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 {
match := fullMethodRegexp.FindAllStringSubmatch(method, 1)
if (len(match) == 0) || (len(match) > 1 && len(match[1]) != 2) {
match := fullMethodRegexp.FindStringSubmatch(method)
if len(match) == 0 {
return ""
}
return match[0][1]
return match[1]
}
func addEventForMessageReceived(ctx context.Context, id int, m interface{}) {

View File

@ -30,15 +30,7 @@ type testExporter struct {
}
func (t *testExporter) ExportSpan(ctx context.Context, s *export.SpanData) {
var spans []*export.SpanData
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
t.spanMap[s.Name] = append(t.spanMap[s.Name], s)
}
type mockCCInvoker struct {
@ -72,16 +64,23 @@ func TestUCISimpleMethodNameSetsServiceNameAttribute(t *testing.T) {
testUCISetsExpectedNameAttribute(t, simpleName, expectedServiceName)
}
func TestUCIUnamedMethodSetsEmptyNameAttribute(t *testing.T) {
func TestUCIInvalidMethodSetsEmptyNameAttribute(t *testing.T) {
expectedServiceName := ""
emptyName := fmt.Sprintf("/%s/bar", expectedServiceName)
emptyName := "invalidMethodName"
testUCISetsExpectedNameAttribute(t, emptyName, expectedServiceName)
}
func TestUCILongMethodNameSetsServiceNameAttribute(t *testing.T) {
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)
}