Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ public String getDbOperationName(RedissonRequest request) {
return request.getOperationName();
}

@Nullable
@Override
public Long getDbOperationBatchSize(RedissonRequest request) {
return request.getOperationBatchSize();
}

@Override
@Nullable
public InetSocketAddress getNetworkPeerInetSocketAddress(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,24 @@ public String getOperationName() {
return null;
}

@Nullable
public Long getOperationBatchSize() {
Object command = getCommand();
if (!(command instanceof CommandsData)) {
return null;
}
List<CommandData<?, ?>> commands = ((CommandsData) command).getCommands();
if (commands.isEmpty()) {
return null;
}
int batchSize = commands.size();
if (commands.get(0).getCommand().getName().equals(MULTI)) {
// MULTI is a transaction wrapper command, not a user operation in the batch.
batchSize--;
}
return batchSize > 1 ? (long) batchSize : null;
}

@Nullable
private static String getBatchOperationName(List<CommandData<?, ?>> commands) {
if (commands.size() < 2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ void atomicBatchCommand() {
equalTo(
DB_OPERATION_NAME,
emitStableDatabaseSemconv() ? "MULTI SET" : null),
// db.operation.batch.size is not emitted because MULTI transaction
// telemetry is split across wrapper and command spans, so this span
// does not represent the full logical batch.
equalTo(maybeStable(DB_STATEMENT), "MULTI;SET batch1 ?"))
.hasParent(trace.getSpan(0)),
span ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import static io.opentelemetry.instrumentation.testing.util.TestLatestDeps.testLatestDeps;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
import static io.opentelemetry.semconv.DbAttributes.DB_OPERATION_BATCH_SIZE;
import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PEER_ADDRESS;
import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PEER_PORT;
import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_TYPE;
Expand Down Expand Up @@ -268,6 +269,8 @@ void batchCommand() throws ReflectiveOperationException {
equalTo(
DB_OPERATION_NAME,
emitStableDatabaseSemconv() ? "PIPELINE SET" : null),
equalTo(
DB_OPERATION_BATCH_SIZE, emitStableDatabaseSemconv() ? 2L : null),
equalTo(maybeStable(DB_STATEMENT), "SET batch1 ?;SET batch2 ?"))));
}

Expand Down Expand Up @@ -297,6 +300,8 @@ void mixedBatchCommand() throws ReflectiveOperationException {
equalTo(maybeStable(DB_SYSTEM), REDIS),
equalTo(
DB_OPERATION_NAME, emitStableDatabaseSemconv() ? "PIPELINE" : null),
equalTo(
DB_OPERATION_BATCH_SIZE, emitStableDatabaseSemconv() ? 2L : null),
equalTo(maybeStable(DB_STATEMENT), "SET batch1 ?;GET batch1"))));
}

Expand Down Expand Up @@ -330,6 +335,8 @@ void largeBatchCommand() throws ReflectiveOperationException {
equalTo(
DB_OPERATION_NAME,
emitStableDatabaseSemconv() ? "PIPELINE SET" : null),
equalTo(
DB_OPERATION_BATCH_SIZE, emitStableDatabaseSemconv() ? 4L : null),
equalTo(
maybeStable(DB_STATEMENT),
"SET " + bucketName + " ?;SET " + bucketName + " ?"))));
Expand Down Expand Up @@ -370,6 +377,9 @@ void atomicBatchCommand() {
equalTo(
DB_OPERATION_NAME,
emitStableDatabaseSemconv() ? "MULTI SET" : null),
// db.operation.batch.size is not emitted because MULTI transaction
// telemetry is split across wrapper and command spans, so this span
// does not represent the full logical batch.
equalTo(maybeStable(DB_STATEMENT), "MULTI;SET batch1 ?"))
.hasParent(trace.getSpan(0)),
span ->
Expand Down
Loading