Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -5,9 +5,6 @@

package io.opentelemetry.javaagent.instrumentation.redisson;

import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;

import com.google.auto.value.AutoValue;
import io.netty.buffer.ByteBuf;
import io.opentelemetry.instrumentation.api.incubator.semconv.db.RedisCommandSanitizer;
Expand All @@ -20,7 +17,6 @@
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import org.redisson.client.protocol.CommandData;
import org.redisson.client.protocol.CommandsData;
Expand Down Expand Up @@ -48,37 +44,30 @@ public String getOperation() {
CommandsData commandsData = (CommandsData) command;
if (commandsData.getCommands().size() == 1) {
return commandsData.getCommands().get(0).getCommand().getName();
} else {
return "BATCH EXECUTE";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the spec allow this? From what I understand from https://github.com/open-telemetry/semantic-conventions/blob/main/docs/database/database-spans.md#call-level-attributes operation should not be set if there is more than one operation.

Copy link
Member Author

@AlchemyDing AlchemyDing Jul 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

db.operation.name
I noticed that there is a description of the db.operation.name for batch statements in semantic-conventions, but I'm not sure if this is the one adjusted after this pull request

}
}
return null;
}

@Nullable
public String getStatement() {
List<String> sanitizedStatements = sanitizeStatement();
switch (sanitizedStatements.size()) {
case 0:
return null;
// optimize for the most common case
case 1:
return sanitizedStatements.get(0);
default:
return String.join(";", sanitizedStatements);
}
return sanitizeStatement();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of omitting the statement when multiple statements are executed you could have changed it to only capture some small number X statements or limit the total length of the statement (there is a size limit to attributes anyway). Did you consider solving it this way?

}

private List<String> sanitizeStatement() {
private String sanitizeStatement() {
Object command = getCommand();
// get command
if (command instanceof CommandsData) {
List<CommandData<?, ?>> commands = ((CommandsData) command).getCommands();
return commands.stream()
.map(RedissonRequest::normalizeSingleCommand)
.collect(Collectors.toList());
if (commands.size() == 1) {
return normalizeSingleCommand(commands.get(0));
}
} else if (command instanceof CommandData) {
return singletonList(normalizeSingleCommand((CommandData<?, ?>) command));
return normalizeSingleCommand((CommandData<?, ?>) command);
}
return emptyList();
return null;
}

private static String normalizeSingleCommand(CommandData<?, ?> command) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,14 @@ void atomicBatchCommand() throws ExecutionException, InterruptedException, Timeo
trace.hasSpansSatisfyingExactly(
span -> span.hasName("parent").hasKind(INTERNAL).hasNoParent(),
span ->
span.hasName("DB Query")
span.hasName("BATCH EXECUTE")
.hasKind(CLIENT)
.hasAttributesSatisfyingExactly(
equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"),
equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"),
equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port),
equalTo(SemanticAttributes.DB_SYSTEM, "redis"),
equalTo(SemanticAttributes.DB_STATEMENT, "MULTI;SET batch1 ?"))
equalTo(SemanticAttributes.DB_OPERATION, "BATCH EXECUTE"))
.hasParent(trace.getSpan(0)),
span ->
span.hasName("SET")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,14 @@ void batchCommand()
trace ->
trace.hasSpansSatisfyingExactly(
span ->
span.hasName("DB Query")
span.hasName("BATCH EXECUTE")
.hasKind(CLIENT)
.hasAttributesSatisfyingExactly(
equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"),
equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"),
equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port),
equalTo(SemanticAttributes.DB_SYSTEM, "redis"),
equalTo(
SemanticAttributes.DB_STATEMENT, "SET batch1 ?;SET batch2 ?"))));
equalTo(SemanticAttributes.DB_OPERATION, "BATCH EXECUTE"))));
}

private static void invokeExecute(RBatch batch)
Expand Down Expand Up @@ -188,14 +187,14 @@ void atomicBatchCommand() {
trace.hasSpansSatisfyingExactly(
span -> span.hasName("parent").hasNoParent().hasKind(INTERNAL),
span ->
span.hasName("DB Query")
span.hasName("BATCH EXECUTE")
.hasKind(CLIENT)
.hasAttributesSatisfyingExactly(
equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"),
equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"),
equalTo(NetworkAttributes.NETWORK_PEER_PORT, (long) port),
equalTo(SemanticAttributes.DB_SYSTEM, "redis"),
equalTo(SemanticAttributes.DB_STATEMENT, "MULTI;SET batch1 ?"))
equalTo(SemanticAttributes.DB_OPERATION, "BATCH EXECUTE"))
.hasParent(trace.getSpan(0)),
span ->
span.hasName("SET")
Expand Down