Skip to content

Commit 8626a85

Browse files
authored
fix: blanks span for session keepAlive traces (#855)
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 0fd859d commit 8626a85

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
@@ -112,6 +112,10 @@ void setCurrentSpan(Span span) {
112112
currentSpan = span;
113113
}
114114

115+
Span getCurrentSpan() {
116+
return currentSpan;
117+
}
118+
115119
@Override
116120
public long executePartitionedUpdate(Statement stmt) {
117121
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
@@ -76,6 +76,7 @@
7676
import io.opencensus.metrics.Metrics;
7777
import io.opencensus.trace.Annotation;
7878
import io.opencensus.trace.AttributeValue;
79+
import io.opencensus.trace.BlankSpan;
7980
import io.opencensus.trace.Span;
8081
import io.opencensus.trace.Status;
8182
import io.opencensus.trace.Tracer;
@@ -1463,11 +1464,15 @@ public void prepareReadWriteTransaction() {
14631464

14641465
private void keepAlive() {
14651466
markUsed();
1467+
final Span previousSpan = delegate.getCurrentSpan();
1468+
delegate.setCurrentSpan(BlankSpan.INSTANCE);
14661469
try (ResultSet resultSet =
14671470
delegate
14681471
.singleUse(TimestampBound.ofMaxStaleness(60, TimeUnit.SECONDS))
14691472
.executeQuery(Statement.newBuilder("SELECT 1").build())) {
14701473
resultSet.next();
1474+
} finally {
1475+
delegate.setCurrentSpan(previousSpan);
14711476
}
14721477
}
14731478

0 commit comments

Comments
 (0)