/** Creates a new instance with the methodName overriden. */ public SpanName withMethodName(String methodName) { return of(getClientName(), methodName); }
/** Creates a new instance with the methodName overriden. */ public SpanName withMethodName(String methodName) { return of(getClientName(), methodName); }
/** Creates a new instance with the clientName overriden. */ public SpanName withClientName(String clientName) { return of(clientName, getMethodName()); }
@InternalApi("Visible for testing") static SpanName getSpanName(@Nonnull MethodDescriptor<?, ?> methodDescriptor) { Matcher matcher = FULL_METHOD_NAME_REGEX.matcher(methodDescriptor.getFullMethodName()); Preconditions.checkArgument(matcher.matches(), "Invalid fullMethodName"); return SpanName.of(matcher.group(1), matcher.group(2)); } }
/** Creates a new instance with the clientName overriden. */ public SpanName withClientName(String clientName) { return of(clientName, getMethodName()); }
@InternalApi("Visible for testing") static SpanName getSpanName(@Nonnull ApiMethodDescriptor<?, ?> methodDescriptor) { Matcher matcher = FULL_METHOD_NAME_REGEX.matcher(methodDescriptor.getFullMethodName()); Preconditions.checkArgument(matcher.matches(), "Invalid fullMethodName"); return SpanName.of(matcher.group(1), matcher.group(2)); } }
@InternalApi("Visible for testing") static SpanName getSpanName(@Nonnull MethodDescriptor<?, ?> methodDescriptor) { Matcher matcher = FULL_METHOD_NAME_REGEX.matcher(methodDescriptor.getFullMethodName()); Preconditions.checkArgument(matcher.matches(), "Invalid fullMethodName"); return SpanName.of(matcher.group(1), matcher.group(2)); } }
@InternalApi("Visible for testing") static SpanName getSpanName(@Nonnull ApiMethodDescriptor<?, ?> methodDescriptor) { Matcher matcher = FULL_METHOD_NAME_REGEX.matcher(methodDescriptor.getFullMethodName()); Preconditions.checkArgument(matcher.matches(), "Invalid fullMethodName"); return SpanName.of(matcher.group(1), matcher.group(2)); } }
@Test public void testSpanNameOverride() { OpencensusTracerFactory factory = new OpencensusTracerFactory(internalTracer, "OverridenClient"); factory.newTracer(SpanName.of("FakeClient", "FakeMethod")); Truth.assertThat(internalTracer.lastSpanName).isEqualTo("OverridenClient.FakeMethod"); }
@Test public void testSpanNamePassthrough() { OpencensusTracerFactory factory = new OpencensusTracerFactory(internalTracer, null); factory.newTracer(SpanName.of("FakeClient", "FakeMethod")); Truth.assertThat(internalTracer.lastSpanName).isEqualTo("FakeClient.FakeMethod"); }
@Test public void testGetSpanName() { Map<String, SpanName> validNames = ImmutableMap.of( "compute.projects.disableXpnHost", SpanName.of("compute.projects", "disableXpnHost"), "client.method", SpanName.of("client", "method")); for (Entry<String, SpanName> entry : validNames.entrySet()) { @SuppressWarnings("unchecked") ApiMethodDescriptor descriptor = ApiMethodDescriptor.newBuilder() .setFullMethodName(entry.getKey()) .setHttpMethod(HttpMethods.POST) .setRequestFormatter(Mockito.mock(HttpRequestFormatter.class)) .setResponseParser(Mockito.mock(HttpResponseParser.class)) .build(); SpanName actualSpanName = HttpJsonCallableFactory.getSpanName(descriptor); assertThat(actualSpanName).isEqualTo(entry.getValue()); } }
@Test public void testGetSpanName() { @SuppressWarnings("unchecked") MethodDescriptor descriptor = MethodDescriptor.newBuilder() .setType(MethodType.SERVER_STREAMING) .setFullMethodName("google.bigtable.v2.Bigtable/ReadRows") .setRequestMarshaller(Mockito.mock(Marshaller.class)) .setResponseMarshaller(Mockito.mock(Marshaller.class)) .build(); SpanName actualSpanName = GrpcCallableFactory.getSpanName(descriptor); assertThat(actualSpanName).isEqualTo(SpanName.of("Bigtable", "ReadRows")); }
@Test public void testGetSpanNameUnqualified() { @SuppressWarnings("unchecked") MethodDescriptor descriptor = MethodDescriptor.newBuilder() .setType(MethodType.SERVER_STREAMING) .setFullMethodName("UnqualifiedService/ReadRows") .setRequestMarshaller(Mockito.mock(Marshaller.class)) .setResponseMarshaller(Mockito.mock(Marshaller.class)) .build(); SpanName actualSpanName = GrpcCallableFactory.getSpanName(descriptor); assertThat(actualSpanName).isEqualTo(SpanName.of("UnqualifiedService", "ReadRows")); }