Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
*/
@BetaApi
@InternalApi
public class AppCentricTracer implements ApiTracer {
public class SpanTracer implements ApiTracer {
public static final String LANGUAGE_ATTRIBUTE = "gcp.client.language";

public static final String DEFAULT_LANGUAGE = "Java";
Expand All @@ -54,12 +54,12 @@ public class AppCentricTracer implements ApiTracer {
private TraceManager.Span attemptHandle;

/**
* Creates a new instance of {@code AppCentricTracer}.
* Creates a new instance of {@code SpanTracer}.
*
* @param traceManager the {@link TraceManager} to use for recording spans
* @param attemptSpanName the name of the individual attempt spans
*/
public AppCentricTracer(
public SpanTracer(
TraceManager traceManager, ApiTracerContext apiTracerContext, String attemptSpanName) {
this.traceManager = traceManager;
this.attemptSpanName = attemptSpanName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,32 @@
import com.google.common.annotations.VisibleForTesting;

/**
* A {@link ApiTracerFactory} to build instances of {@link AppCentricTracer}.
* A {@link ApiTracerFactory} to build instances of {@link SpanTracer}.
*
* <p>This class wraps the {@link TraceManager} and pass it to {@link AppCentricTracer}. It will be
* used to record traces in {@link AppCentricTracer}.
* <p>This class wraps the {@link TraceManager} and pass it to {@link SpanTracer}. It will be used
* to record traces in {@link SpanTracer}.
*
* <p>This class is expected to be initialized once during client initialization.
*/
@BetaApi
@InternalApi
public class AppCentricTracerFactory implements ApiTracerFactory {
public class SpanTracerFactory implements ApiTracerFactory {
private final TraceManager traceManager;

private final ApiTracerContext apiTracerContext;

/** Creates a AppCentricTracerFactory */
public AppCentricTracerFactory(TraceManager traceManager) {
/** Creates a SpanTracerFactory */
public SpanTracerFactory(TraceManager traceManager) {
this(traceManager, ApiTracerContext.newBuilder().build());
}

/**
* Pass in a Map of client level attributes which will be added to every single AppCentricTracer
* created from the ApiTracerFactory. This is package private since span attributes are determined
* Pass in a Map of client level attributes which will be added to every single SpanTracer created
* from the ApiTracerFactory. This is package private since span attributes are determined
* internally.
*/
@VisibleForTesting
AppCentricTracerFactory(TraceManager traceManager, ApiTracerContext apiTracerContext) {
SpanTracerFactory(TraceManager traceManager, ApiTracerContext apiTracerContext) {
this.traceManager = traceManager;
this.apiTracerContext = apiTracerContext;
}
Expand All @@ -71,13 +71,12 @@ public ApiTracer newTracer(ApiTracer parent, SpanName spanName, OperationType op
// feature is developed.
String attemptSpanName = spanName.getClientName() + "/" + spanName.getMethodName() + "/attempt";

AppCentricTracer appCentricTracer =
new AppCentricTracer(traceManager, this.apiTracerContext, attemptSpanName);
return appCentricTracer;
SpanTracer spanTracer = new SpanTracer(traceManager, this.apiTracerContext, attemptSpanName);
return spanTracer;
}

@Override
public ApiTracerFactory withContext(ApiTracerContext context) {
return new AppCentricTracerFactory(traceManager, context);
return new SpanTracerFactory(traceManager, context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;

class AppCentricTracerFactoryTest {
class SpanTracerFactoryTest {

@Test
void testNewTracer_createsOpenTelemetryTracingTracer() {
TraceManager recorder = mock(TraceManager.class);
when(recorder.createSpan(anyString(), anyMap())).thenReturn(mock(TraceManager.Span.class));

AppCentricTracerFactory factory = new AppCentricTracerFactory(recorder);
SpanTracerFactory factory = new SpanTracerFactory(recorder);
ApiTracer tracer =
factory.newTracer(
null, SpanName.of("service", "method"), ApiTracerFactory.OperationType.Unary);
assertThat(tracer).isInstanceOf(AppCentricTracer.class);
assertThat(tracer).isInstanceOf(SpanTracer.class);
}

@Test
Expand All @@ -63,7 +63,7 @@ void testNewTracer_addsAttributes() {
when(recorder.createSpan(anyString(), anyMap())).thenReturn(attemptHandle);

ApiTracerFactory factory =
new AppCentricTracerFactory(recorder, ApiTracerContext.newBuilder().build());
new SpanTracerFactory(recorder, ApiTracerContext.newBuilder().build());
factory =
factory.withContext(ApiTracerContext.newBuilder().setServerAddress("test-address").build());
ApiTracer tracer =
Expand All @@ -88,7 +88,7 @@ void testWithContext_addsInferredAttributes() {
ApiTracerContext context =
ApiTracerContext.newBuilder().setServerAddress("example.com").build();

AppCentricTracerFactory factory = new AppCentricTracerFactory(recorder);
SpanTracerFactory factory = new SpanTracerFactory(recorder);
ApiTracerFactory factoryWithContext = factory.withContext(context);

ApiTracer tracer =
Expand All @@ -113,7 +113,7 @@ void testWithContext_noEndpointContext_doesNotAddAttributes() {

ApiTracerContext context = ApiTracerContext.newBuilder().build();

AppCentricTracerFactory factory = new AppCentricTracerFactory(recorder);
SpanTracerFactory factory = new SpanTracerFactory(recorder);
ApiTracerFactory factoryWithContext = factory.withContext(context);

ApiTracer tracer =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,15 @@
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
class AppCentricTracerTest {
class SpanTracerTest {
@Mock private TraceManager recorder;
@Mock private TraceManager.Span attemptHandle;
private AppCentricTracer tracer;
private SpanTracer tracer;
private static final String ATTEMPT_SPAN_NAME = "Service/Method/attempt";

@BeforeEach
void setUp() {
tracer =
new AppCentricTracer(recorder, ApiTracerContext.newBuilder().build(), ATTEMPT_SPAN_NAME);
tracer = new SpanTracer(recorder, ApiTracerContext.newBuilder().build(), ATTEMPT_SPAN_NAME);
}

@Test
Expand All @@ -75,6 +74,6 @@ void testAttemptStarted_includesLanguageAttribute() {
verify(recorder).createSpan(eq(ATTEMPT_SPAN_NAME), attributesCaptor.capture());

assertThat(attributesCaptor.getValue())
.containsEntry(AppCentricTracer.LANGUAGE_ATTRIBUTE, AppCentricTracer.DEFAULT_LANGUAGE);
.containsEntry(SpanTracer.LANGUAGE_ATTRIBUTE, SpanTracer.DEFAULT_LANGUAGE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
import static com.google.common.truth.Truth.assertThat;

import com.google.api.gax.tracing.AppCentricAttributes;
import com.google.api.gax.tracing.AppCentricTracer;
import com.google.api.gax.tracing.AppCentricTracerFactory;
import com.google.api.gax.tracing.OpenTelemetryTraceManager;
import com.google.api.gax.tracing.SpanTracer;
import com.google.api.gax.tracing.SpanTracerFactory;
import com.google.showcase.v1beta1.EchoClient;
import com.google.showcase.v1beta1.EchoRequest;
import com.google.showcase.v1beta1.it.util.TestClientInitializer;
Expand Down Expand Up @@ -81,8 +81,8 @@ void tearDown() {

@Test
void testTracing_successfulEcho_grpc() throws Exception {
AppCentricTracerFactory tracingFactory =
new AppCentricTracerFactory(new OpenTelemetryTraceManager(openTelemetrySdk));
SpanTracerFactory tracingFactory =
new SpanTracerFactory(new OpenTelemetryTraceManager(openTelemetrySdk));

try (EchoClient client =
TestClientInitializer.createGrpcEchoClientOpentelemetry(tracingFactory)) {
Expand All @@ -101,8 +101,8 @@ void testTracing_successfulEcho_grpc() throws Exception {
assertThat(
attemptSpan
.getAttributes()
.get(AttributeKey.stringKey(AppCentricTracer.LANGUAGE_ATTRIBUTE)))
.isEqualTo(AppCentricTracer.DEFAULT_LANGUAGE);
.get(AttributeKey.stringKey(SpanTracer.LANGUAGE_ATTRIBUTE)))
.isEqualTo(SpanTracer.DEFAULT_LANGUAGE);
assertThat(
attemptSpan
.getAttributes()
Expand All @@ -113,8 +113,8 @@ void testTracing_successfulEcho_grpc() throws Exception {

@Test
void testTracing_successfulEcho_httpjson() throws Exception {
AppCentricTracerFactory tracingFactory =
new AppCentricTracerFactory(new OpenTelemetryTraceManager(openTelemetrySdk));
SpanTracerFactory tracingFactory =
new SpanTracerFactory(new OpenTelemetryTraceManager(openTelemetrySdk));

try (EchoClient client =
TestClientInitializer.createHttpJsonEchoClientOpentelemetry(tracingFactory)) {
Expand All @@ -133,8 +133,8 @@ void testTracing_successfulEcho_httpjson() throws Exception {
assertThat(
attemptSpan
.getAttributes()
.get(AttributeKey.stringKey(AppCentricTracer.LANGUAGE_ATTRIBUTE)))
.isEqualTo(AppCentricTracer.DEFAULT_LANGUAGE);
.get(AttributeKey.stringKey(SpanTracer.LANGUAGE_ATTRIBUTE)))
.isEqualTo(SpanTracer.DEFAULT_LANGUAGE);
assertThat(
attemptSpan
.getAttributes()
Expand Down
Loading