Skip to content

Commit 1a86e4f

Browse files
authored
fix: blanks span for session keepAlive traces (#797)
The keepAlive traces were being tracked along with the parent span set by the client, which clutters the tracing stack. Here, we set the tracing to blank before issueing the keepAlive query.
1 parent 90255ea commit 1a86e4f

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ void setCurrentSpan(Span span) {
113113
currentSpan = span;
114114
}
115115

116+
Span getCurrentSpan() {
117+
return currentSpan;
118+
}
119+
116120
@Override
117121
public long executePartitionedUpdate(Statement stmt, UpdateOption... options) {
118122
setActive(null);

google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionPool.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
import io.opencensus.metrics.Metrics;
7878
import io.opencensus.trace.Annotation;
7979
import io.opencensus.trace.AttributeValue;
80+
import io.opencensus.trace.BlankSpan;
8081
import io.opencensus.trace.Span;
8182
import io.opencensus.trace.Status;
8283
import io.opencensus.trace.Tracer;
@@ -1472,11 +1473,15 @@ public void prepareReadWriteTransaction() {
14721473

14731474
private void keepAlive() {
14741475
markUsed();
1476+
final Span previousSpan = delegate.getCurrentSpan();
1477+
delegate.setCurrentSpan(BlankSpan.INSTANCE);
14751478
try (ResultSet resultSet =
14761479
delegate
14771480
.singleUse(TimestampBound.ofMaxStaleness(60, TimeUnit.SECONDS))
14781481
.executeQuery(Statement.newBuilder("SELECT 1").build())) {
14791482
resultSet.next();
1483+
} finally {
1484+
delegate.setCurrentSpan(previousSpan);
14801485
}
14811486
}
14821487

0 commit comments

Comments
 (0)