diff --git a/instrumentation/lettuce/lettuce-5.1/library/src/main/java/io/lettuce/core/protocol/OtelCommandArgsUtil.java b/instrumentation/lettuce/lettuce-5.1/library/src/main/java/io/lettuce/core/protocol/OtelCommandArgsUtil.java index ee0b3e3d0886..7e04eea0ad04 100644 --- a/instrumentation/lettuce/lettuce-5.1/library/src/main/java/io/lettuce/core/protocol/OtelCommandArgsUtil.java +++ b/instrumentation/lettuce/lettuce-5.1/library/src/main/java/io/lettuce/core/protocol/OtelCommandArgsUtil.java @@ -5,6 +5,7 @@ package io.lettuce.core.protocol; +import io.lettuce.core.codec.StringCodec; import io.lettuce.core.protocol.CommandArgs.KeyArgument; import io.lettuce.core.protocol.CommandArgs.SingularArgument; import io.lettuce.core.protocol.CommandArgs.ValueArgument; @@ -22,19 +23,27 @@ public final class OtelCommandArgsUtil { */ public static List getCommandArgs(CommandArgs commandArgs) { List result = new ArrayList<>(); + StringCodec stringCodec = new StringCodec(); + for (SingularArgument argument : commandArgs.singularArguments) { - String value = argument.toString(); - if (argument instanceof KeyArgument && value.startsWith("key<") && value.endsWith(">")) { - value = value.substring("key<".length(), value.length() - 1); - } else if (argument instanceof ValueArgument - && value.startsWith("value<") - && value.endsWith(">")) { - value = value.substring("value<".length(), value.length() - 1); - } + String value = getArgValue(stringCodec, argument); result.add(value); } return result; } + @SuppressWarnings({"rawtypes", "unchecked"}) + private static String getArgValue(StringCodec stringCodec, SingularArgument argument) { + if (argument instanceof KeyArgument) { + KeyArgument keyArg = (KeyArgument) argument; + return stringCodec.decodeValue(keyArg.codec.encodeValue(keyArg.key)); + } + if (argument instanceof ValueArgument) { + ValueArgument valueArg = (ValueArgument) argument; + return stringCodec.decodeValue(valueArg.codec.encodeValue(valueArg.val)); + } + return argument.toString(); + } + private OtelCommandArgsUtil() {} }