File tree

11 files changed

+652
-21
lines changed

11 files changed

+652
-21
lines changed
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,37 @@
3838
</execution>
3939
</executions>
4040
</plugin>
41+
<plugin>
42+
<groupId>org.apache.maven.plugins</groupId>
43+
<artifactId>maven-surefire-plugin</artifactId>
44+
<configuration>
45+
<reportNameSuffix>sponge_log</reportNameSuffix>
46+
</configuration>
47+
<executions>
48+
<execution>
49+
<id>default-test</id>
50+
<configuration>
51+
<excludedGroups>com.google.cloud.spanner.TracerTest,com.google.cloud.spanner.IntegrationTest</excludedGroups>
52+
</configuration>
53+
</execution>
54+
<execution>
55+
<id>tracer</id>
56+
<goals>
57+
<goal>test</goal>
58+
</goals>
59+
<configuration>
60+
<groups>com.google.cloud.spanner.TracerTest</groups>
61+
</configuration>
62+
</execution>
63+
</executions>
64+
</plugin>
4165
</plugins>
4266
<pluginManagement>
4367
<plugins>
4468
<plugin>
4569
<groupId>org.apache.maven.plugins</groupId>
4670
<artifactId>maven-surefire-plugin</artifactId>
4771
<version>3.0.0-M4</version>
48-
<configuration>
49-
<excludedGroups>com.google.cloud.spanner.IntegrationTest</excludedGroups>
50-
<reportNameSuffix>sponge_log</reportNameSuffix>
51-
</configuration>
5272
</plugin>
5373
<plugin>
5474
<groupId>org.apache.maven.plugins</groupId>
@@ -60,15 +80,15 @@
6080
<spanner.testenv.instance>projects/gcloud-devel/instances/spanner-testing</spanner.testenv.instance>
6181
</systemPropertyVariables>
6282
<groups>com.google.cloud.spanner.IntegrationTest</groups>
63-
<excludedGroups>com.google.cloud.spanner.FlakyTest</excludedGroups>
83+
<excludedGroups>com.google.cloud.spanner.FlakyTest,com.google.cloud.spanner.TracerTest</excludedGroups>
6484
<forkedProcessTimeoutInSeconds>2400</forkedProcessTimeoutInSeconds>
6585
</configuration>
6686
</plugin>
6787
<plugin>
6888
<groupId>org.apache.maven.plugins</groupId>
6989
<artifactId>maven-dependency-plugin</artifactId>
7090
<configuration>
71-
<ignoredDependencies>io.grpc:grpc-protobuf-lite,org.hamcrest:hamcrest,org.hamcrest:hamcrest-core</ignoredDependencies>
91+
<ignoredDependencies>io.grpc:grpc-protobuf-lite,org.hamcrest:hamcrest,org.hamcrest:hamcrest-core,com.google.errorprone:error_prone_annotations</ignoredDependencies>
7292
</configuration>
7393
</plugin>
7494
</plugins>
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,7 @@ public void close(@Nullable String message) {
922922
if (stream != null) {
923923
stream.close(message);
924924
span.end(TraceUtil.END_SPAN_OPTIONS);
925+
stream = null;
925926
}
926927
}
927928

@@ -997,11 +998,11 @@ protected PartialResultSet computeNext() {
997998
continue;
998999
}
9991000
span.addAnnotation("Stream broken. Not safe to retry");
1000-
TraceUtil.endSpanWithFailure(span, e);
1001+
TraceUtil.setWithFailure(span, e);
10011002
throw e;
10021003
} catch (RuntimeException e) {
10031004
span.addAnnotation("Stream broken. Not safe to retry");
1004-
TraceUtil.endSpanWithFailure(span, e);
1005+
TraceUtil.setWithFailure(span, e);
10051006
throw e;
10061007
}
10071008
}
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public Timestamp apply(Session session) {
6666
}
6767
});
6868
} catch (RuntimeException e) {
69-
TraceUtil.endSpanWithFailure(span, e);
69+
TraceUtil.setWithFailure(span, e);
7070
throw e;
7171
} finally {
7272
span.end(TraceUtil.END_SPAN_OPTIONS);
@@ -86,7 +86,7 @@ public Timestamp apply(Session session) {
8686
}
8787
});
8888
} catch (RuntimeException e) {
89-
TraceUtil.endSpanWithFailure(span, e);
89+
TraceUtil.setWithFailure(span, e);
9090
throw e;
9191
} finally {
9292
span.end(TraceUtil.END_SPAN_OPTIONS);
@@ -165,8 +165,10 @@ public TransactionRunner readWriteTransaction() {
165165
try (Scope s = tracer.withSpan(span)) {
166166
return getReadWriteSession().readWriteTransaction();
167167
} catch (RuntimeException e) {
168-
TraceUtil.endSpanWithFailure(span, e);
168+
TraceUtil.setWithFailure(span, e);
169169
throw e;
170+
} finally {
171+
span.end(TraceUtil.END_SPAN_OPTIONS);
170172
}
171173
}
172174

Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public void run() {
135135
try {
136136
sessions = internalBatchCreateSessions(remainingSessionsToCreate, channelHint);
137137
} catch (Throwable t) {
138-
TraceUtil.endSpanWithFailure(SpannerImpl.tracer.getCurrentSpan(), t);
138+
TraceUtil.setWithFailure(SpannerImpl.tracer.getCurrentSpan(), t);
139139
consumer.onSessionCreateFailure(t, remainingSessionsToCreate);
140140
break;
141141
}
@@ -207,11 +207,12 @@ SessionImpl createSession() {
207207
spanner
208208
.getRpc()
209209
.createSession(db.getName(), spanner.getOptions().getSessionLabels(), options);
210-
span.end(TraceUtil.END_SPAN_OPTIONS);
211210
return new SessionImpl(spanner, session.getName(), options);
212211
} catch (RuntimeException e) {
213-
TraceUtil.endSpanWithFailure(span, e);
212+
TraceUtil.setWithFailure(span, e);
214213
throw e;
214+
} finally {
215+
span.end(TraceUtil.END_SPAN_OPTIONS);
215216
}
216217
}
217218

Original file line numberDiff line numberDiff line change
@@ -140,14 +140,15 @@ public Timestamp writeAtLeastOnce(Iterable<Mutation> mutations) throws SpannerEx
140140
try (Scope s = tracer.withSpan(span)) {
141141
CommitResponse response = spanner.getRpc().commit(request, options);
142142
Timestamp t = Timestamp.fromProto(response.getCommitTimestamp());
143-
span.end(TraceUtil.END_SPAN_OPTIONS);
144143
return t;
145144
} catch (IllegalArgumentException e) {
146-
TraceUtil.endSpanWithFailure(span, e);
145+
TraceUtil.setWithFailure(span, e);
147146
throw newSpannerException(ErrorCode.INTERNAL, "Could not parse commit timestamp", e);
148147
} catch (RuntimeException e) {
149-
TraceUtil.endSpanWithFailure(span, e);
148+
TraceUtil.setWithFailure(span, e);
150149
throw e;
150+
} finally {
151+
span.end(TraceUtil.END_SPAN_OPTIONS);
151152
}
152153
}
153154

@@ -208,10 +209,11 @@ public void close() {
208209
Span span = tracer.spanBuilder(SpannerImpl.DELETE_SESSION).startSpan();
209210
try (Scope s = tracer.withSpan(span)) {
210211
spanner.getRpc().deleteSession(name, options);
211-
span.end(TraceUtil.END_SPAN_OPTIONS);
212212
} catch (RuntimeException e) {
213-
TraceUtil.endSpanWithFailure(span, e);
213+
TraceUtil.setWithFailure(span, e);
214214
throw e;
215+
} finally {
216+
span.end(TraceUtil.END_SPAN_OPTIONS);
215217
}
216218
}
217219

Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ private PooledSession take() throws SpannerException {
895895
return s.session;
896896
}
897897
} catch (Exception e) {
898-
TraceUtil.endSpanWithFailure(tracer.getCurrentSpan(), e);
898+
TraceUtil.setWithFailure(span, e);
899899
throw e;
900900
} finally {
901901
span.end(TraceUtil.END_SPAN_OPTIONS);
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ static ImmutableMap<String, AttributeValue> getExceptionAnnotations(SpannerExcep
5454
"Status", AttributeValue.stringAttributeValue(e.getErrorCode().toString()));
5555
}
5656

57+
static void setWithFailure(Span span, Throwable e) {
58+
if (e instanceof SpannerException) {
59+
span.setStatus(
60+
StatusConverter.fromGrpcStatus(((SpannerException) e).getErrorCode().getGrpcStatus())
61+
.withDescription(e.getMessage()));
62+
} else {
63+
span.setStatus(Status.INTERNAL.withDescription(e.getMessage()));
64+
}
65+
}
66+
5767
static void endSpanWithFailure(Span span, Throwable e) {
5868
if (e instanceof SpannerException) {
5969
endSpanWithFailure(span, (SpannerException) e);
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ public <T> T run(TransactionCallable<T> callable) {
294294
}
295295
return runInternal(callable);
296296
} catch (RuntimeException e) {
297-
TraceUtil.endSpanWithFailure(span, e);
297+
TraceUtil.setWithFailure(span, e);
298298
throw e;
299299
} finally {
300300
// Remove threadLocal rather than set to FALSE to avoid a possible memory .

0 commit comments

Comments
 (0)