Skip to content

Commit f7891c1

Browse files
authored
fix: remove unused DmlBatch span (#3147)
The DmlBatch span that was created for DML batches was never used, as all traces were registered on the underlying transaction of the batch. The DmlBatch span was therefore always just an empty sibling span of the Transaction span, which did contain the traces of the statements that were executed.
1 parent e00b884 commit f7891c1

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/AbstractBaseUnitOfWork.java

+5
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ B setSpan(@Nullable Span span) {
165165
this.span = Preconditions.checkNotNull(builder.span);
166166
}
167167

168+
@Override
169+
public Span getSpan() {
170+
return this.span;
171+
}
172+
168173
ApiFuture<Void> asyncEndUnitOfWorkSpan() {
169174
return this.statementExecutor.submit(this::endUnitOfWorkSpan);
170175
}

google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ConnectionImpl.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ class ConnectionImpl implements Connection {
9696
private static final String SINGLE_USE_TRANSACTION = "SingleUseTransaction";
9797
private static final String READ_ONLY_TRANSACTION = "ReadOnlyTransaction";
9898
private static final String READ_WRITE_TRANSACTION = "ReadWriteTransaction";
99-
private static final String DML_BATCH = "DmlBatch";
10099
private static final String DDL_BATCH = "DdlBatch";
101100
private static final String DDL_STATEMENT = "DdlStatement";
102101

@@ -1932,7 +1931,8 @@ UnitOfWork createNewUnitOfWork(
19321931
.setStatementTag(statementTag)
19331932
.setExcludeTxnFromChangeStreams(excludeTxnFromChangeStreams)
19341933
.setRpcPriority(rpcPriority)
1935-
.setSpan(createSpanForUnitOfWork(DML_BATCH))
1934+
// Use the transaction Span for the DML batch.
1935+
.setSpan(transactionStack.peek().getSpan())
19361936
.build();
19371937
case DDL_BATCH:
19381938
return DdlBatch.newBuilder()

google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/UnitOfWork.java

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.google.cloud.spanner.TransactionContext;
3232
import com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement;
3333
import com.google.spanner.v1.ResultSetStats;
34+
import io.opentelemetry.api.trace.Span;
3435
import java.util.concurrent.ExecutionException;
3536
import javax.annotation.Nonnull;
3637

@@ -77,6 +78,9 @@ public boolean isActive() {
7778
/** @return <code>true</code> if this unit of work is still active. */
7879
boolean isActive();
7980

81+
/** @return the {@link Span} that is used by this {@link UnitOfWork}. */
82+
Span getSpan();
83+
8084
/** Returns true if this transaction can only be used for a single statement. */
8185
boolean isSingleUse();
8286

0 commit comments

Comments
 (0)