Skip to content

Commit

Permalink
fix: remove unused DmlBatch span (#3147)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
olavloite committed Jun 21, 2024
1 parent e00b884 commit f7891c1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ B setSpan(@Nullable Span span) {
this.span = Preconditions.checkNotNull(builder.span);
}

@Override
public Span getSpan() {
return this.span;
}

ApiFuture<Void> asyncEndUnitOfWorkSpan() {
return this.statementExecutor.submit(this::endUnitOfWorkSpan);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ class ConnectionImpl implements Connection {
private static final String SINGLE_USE_TRANSACTION = "SingleUseTransaction";
private static final String READ_ONLY_TRANSACTION = "ReadOnlyTransaction";
private static final String READ_WRITE_TRANSACTION = "ReadWriteTransaction";
private static final String DML_BATCH = "DmlBatch";
private static final String DDL_BATCH = "DdlBatch";
private static final String DDL_STATEMENT = "DdlStatement";

Expand Down Expand Up @@ -1932,7 +1931,8 @@ UnitOfWork createNewUnitOfWork(
.setStatementTag(statementTag)
.setExcludeTxnFromChangeStreams(excludeTxnFromChangeStreams)
.setRpcPriority(rpcPriority)
.setSpan(createSpanForUnitOfWork(DML_BATCH))
// Use the transaction Span for the DML batch.
.setSpan(transactionStack.peek().getSpan())
.build();
case DDL_BATCH:
return DdlBatch.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.google.cloud.spanner.TransactionContext;
import com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement;
import com.google.spanner.v1.ResultSetStats;
import io.opentelemetry.api.trace.Span;
import java.util.concurrent.ExecutionException;
import javax.annotation.Nonnull;

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

/** @return the {@link Span} that is used by this {@link UnitOfWork}. */
Span getSpan();

/** Returns true if this transaction can only be used for a single statement. */
boolean isSingleUse();

Expand Down

0 comments on commit f7891c1

Please sign in to comment.