Skip to content

Commit 0f5e9b5

Browse files
committed
chore: rename startSpan to createSpan
1 parent 2415c6b commit 0f5e9b5

6 files changed

Lines changed: 23 additions & 22 deletions

File tree

gax-java/gax/src/main/java/com/google/api/gax/tracing/OpenTelemetryTracingRecorder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ public OpenTelemetryTracingRecorder(OpenTelemetry openTelemetry) {
5454
}
5555

5656
@Override
57-
public GaxSpan startSpan(String name, Map<String, String> attributes) {
58-
return startSpan(name, attributes, null);
57+
public GaxSpan createSpan(String name, Map<String, String> attributes) {
58+
return createSpan(name, attributes, null);
5959
}
6060

6161
@Override
62-
public GaxSpan startSpan(String name, Map<String, String> attributes, GaxSpan parent) {
62+
public GaxSpan createSpan(String name, Map<String, String> attributes, GaxSpan parent) {
6363
SpanBuilder spanBuilder = tracer.spanBuilder(name);
6464

6565
// Operation and Attempt spans are INTERNAL and CLIENT respectively.

gax-java/gax/src/main/java/com/google/api/gax/tracing/TracingRecorder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@
4444
@InternalApi
4545
public interface TracingRecorder {
4646
/** Starts a span and returns a handle to manage its lifecycle. */
47-
GaxSpan startSpan(String name, Map<String, String> attributes);
47+
GaxSpan createSpan(String name, Map<String, String> attributes);
4848

4949
/** Starts a span with a parent and returns a handle to manage its lifecycle. */
50-
GaxSpan startSpan(String name, Map<String, String> attributes, GaxSpan parent);
50+
GaxSpan createSpan(String name, Map<String, String> attributes, GaxSpan parent);
5151

5252
interface GaxSpan {
5353
void end();

gax-java/gax/src/main/java/com/google/api/gax/tracing/TracingTracer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ public TracingTracer(
6161
this.attemptAttributes.put(LANGUAGE_ATTRIBUTE, DEFAULT_LANGUAGE);
6262

6363
// Start the long-lived operation span.
64-
this.operationHandle = recorder.startSpan(operationSpanName, operationAttributes);
64+
this.operationHandle = recorder.createSpan(operationSpanName, operationAttributes);
6565
}
6666

6767
@Override
6868
public void attemptStarted(Object request, int attemptNumber) {
6969
Map<String, String> attemptAttributes = new HashMap<>(this.attemptAttributes);
7070
// Start the specific attempt span with the operation span as parent
71-
this.attemptHandle = recorder.startSpan(attemptSpanName, attemptAttributes, operationHandle);
71+
this.attemptHandle = recorder.createSpan(attemptSpanName, attemptAttributes, operationHandle);
7272
}
7373

7474
@Override

gax-java/gax/src/test/java/com/google/api/gax/tracing/OpenTelemetryTracingRecorderTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,33 +66,33 @@ void setUp() {
6666
}
6767

6868
@Test
69-
void testStartSpan_operation_isInternal() {
69+
void testCreateSpan_operation_isInternal() {
7070
String spanName = "operation-span";
7171
when(tracer.spanBuilder(spanName)).thenReturn(spanBuilder);
7272
when(spanBuilder.setSpanKind(SpanKind.INTERNAL)).thenReturn(spanBuilder);
7373
when(spanBuilder.startSpan()).thenReturn(span);
7474

75-
recorder.startSpan(spanName, null);
75+
recorder.createSpan(spanName, null);
7676

7777
verify(spanBuilder).setSpanKind(SpanKind.INTERNAL);
7878
}
7979

8080
@Test
81-
void testStartSpan_attempt_isClient() {
81+
void testCreateSpan_attempt_isClient() {
8282
String spanName = "attempt-span";
8383
TracingRecorder.GaxSpan parent = mock(TracingRecorder.GaxSpan.class);
8484

8585
when(tracer.spanBuilder(spanName)).thenReturn(spanBuilder);
8686
when(spanBuilder.setSpanKind(SpanKind.CLIENT)).thenReturn(spanBuilder);
8787
when(spanBuilder.startSpan()).thenReturn(span);
8888

89-
recorder.startSpan(spanName, null, parent);
89+
recorder.createSpan(spanName, null, parent);
9090

9191
verify(spanBuilder).setSpanKind(SpanKind.CLIENT);
9292
}
9393

9494
@Test
95-
void testStartSpan_recordsSpan() {
95+
void testCreateSpan_recordsSpan() {
9696
String spanName = "test-span";
9797
Map<String, String> attributes = ImmutableMap.of("key1", "value1");
9898

@@ -101,7 +101,7 @@ void testStartSpan_recordsSpan() {
101101
when(spanBuilder.setAttribute("key1", "value1")).thenReturn(spanBuilder);
102102
when(spanBuilder.startSpan()).thenReturn(span);
103103

104-
TracingRecorder.GaxSpan handle = recorder.startSpan(spanName, attributes);
104+
TracingRecorder.GaxSpan handle = recorder.createSpan(spanName, attributes);
105105
handle.end();
106106

107107
verify(span).end();

gax-java/gax/src/test/java/com/google/api/gax/tracing/TracingTracerFactoryTest.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ class TracingTracerFactoryTest {
5050
@Test
5151
void testNewTracer_createsOpenTelemetryTracingTracer() {
5252
TracingRecorder recorder = mock(TracingRecorder.class);
53-
when(recorder.startSpan(anyString(), anyMap())).thenReturn(mock(TracingRecorder.GaxSpan.class));
53+
when(recorder.createSpan(anyString(), anyMap()))
54+
.thenReturn(mock(TracingRecorder.GaxSpan.class));
5455

5556
TracingTracerFactory factory = new TracingTracerFactory(recorder);
5657
ApiTracer tracer =
@@ -63,7 +64,7 @@ void testNewTracer_createsOpenTelemetryTracingTracer() {
6364
void testNewTracer_addsAttributes() {
6465
TracingRecorder recorder = mock(TracingRecorder.class);
6566
TracingRecorder.GaxSpan operationHandle = mock(TracingRecorder.GaxSpan.class);
66-
when(recorder.startSpan(anyString(), anyMap())).thenReturn(operationHandle);
67+
when(recorder.createSpan(anyString(), anyMap())).thenReturn(operationHandle);
6768

6869
TracingTracerFactory factory =
6970
new TracingTracerFactory(
@@ -76,7 +77,7 @@ void testNewTracer_addsAttributes() {
7677

7778
ArgumentCaptor<Map<String, String>> attributesCaptor = ArgumentCaptor.forClass(Map.class);
7879
verify(recorder, atLeastOnce())
79-
.startSpan(anyString(), attributesCaptor.capture(), eq(operationHandle));
80+
.createSpan(anyString(), attributesCaptor.capture(), eq(operationHandle));
8081

8182
Map<String, String> attemptAttributes = attributesCaptor.getValue();
8283
assertThat(attemptAttributes).containsEntry("server.port", "443");
@@ -86,7 +87,7 @@ void testNewTracer_addsAttributes() {
8687
void testWithContext_addsInferredAttributes() {
8788
TracingRecorder recorder = mock(TracingRecorder.class);
8889
TracingRecorder.GaxSpan operationHandle = mock(TracingRecorder.GaxSpan.class);
89-
when(recorder.startSpan(anyString(), anyMap())).thenReturn(operationHandle);
90+
when(recorder.createSpan(anyString(), anyMap())).thenReturn(operationHandle);
9091

9192
EndpointContext endpointContext = mock(EndpointContext.class);
9293
when(endpointContext.resolvedServerAddress()).thenReturn("example.com");
@@ -105,7 +106,7 @@ void testWithContext_addsInferredAttributes() {
105106

106107
ArgumentCaptor<Map<String, String>> attributesCaptor = ArgumentCaptor.forClass(Map.class);
107108
verify(recorder, atLeastOnce())
108-
.startSpan(anyString(), attributesCaptor.capture(), eq(operationHandle));
109+
.createSpan(anyString(), attributesCaptor.capture(), eq(operationHandle));
109110

110111
Map<String, String> attemptAttributes = attributesCaptor.getValue();
111112
assertThat(attemptAttributes)
@@ -116,7 +117,7 @@ void testWithContext_addsInferredAttributes() {
116117
void testWithContext_noEndpointContext_doesNotAddAttributes() {
117118
TracingRecorder recorder = mock(TracingRecorder.class);
118119
TracingRecorder.GaxSpan operationHandle = mock(TracingRecorder.GaxSpan.class);
119-
when(recorder.startSpan(anyString(), anyMap())).thenReturn(operationHandle);
120+
when(recorder.createSpan(anyString(), anyMap())).thenReturn(operationHandle);
120121

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

@@ -131,7 +132,7 @@ void testWithContext_noEndpointContext_doesNotAddAttributes() {
131132

132133
ArgumentCaptor<Map<String, String>> attributesCaptor = ArgumentCaptor.forClass(Map.class);
133134
verify(recorder, atLeastOnce())
134-
.startSpan(anyString(), attributesCaptor.capture(), eq(operationHandle));
135+
.createSpan(anyString(), attributesCaptor.capture(), eq(operationHandle));
135136

136137
Map<String, String> attemptAttributes = attributesCaptor.getValue();
137138
assertThat(attemptAttributes).doesNotContainKey(TracingTracer.SERVER_ADDRESS_ATTRIBUTE);

gax-java/gax/src/test/java/com/google/api/gax/tracing/TracingTracerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class TracingTracerTest {
5252

5353
@BeforeEach
5454
void setUp() {
55-
when(recorder.startSpan(eq(OPERATION_SPAN_NAME), anyMap())).thenReturn(operationHandle);
55+
when(recorder.createSpan(eq(OPERATION_SPAN_NAME), anyMap())).thenReturn(operationHandle);
5656
tracer =
5757
new TracingTracer(
5858
recorder, OPERATION_SPAN_NAME, ATTEMPT_SPAN_NAME, new HashMap<>(), new HashMap<>());
@@ -66,7 +66,7 @@ void testOperationSucceeded_endsSpan() {
6666

6767
@Test
6868
void testAttemptLifecycle_startsAndEndsAttemptSpan() {
69-
when(recorder.startSpan(eq(ATTEMPT_SPAN_NAME), anyMap(), eq(operationHandle)))
69+
when(recorder.createSpan(eq(ATTEMPT_SPAN_NAME), anyMap(), eq(operationHandle)))
7070
.thenReturn(attemptHandle);
7171
tracer.attemptStarted(new Object(), 1);
7272
tracer.attemptSucceeded();

0 commit comments

Comments
 (0)