Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
28bbbe7
Initial plan
Copilot Oct 20, 2026
5102160
Classify Redisson server errors
Copilot Oct 20, 2026
36a4c0b
Capture Redisson server error replies
Copilot Oct 20, 2026
d88c597
Document Redisson latest test range
Copilot Oct 20, 2026
8ea8079
Restore Redisson latest release coverage
Copilot Oct 21, 2026
748681d
Handle dedicated Redisson server errors
Copilot Oct 21, 2026
c66ccc7
Preserve Redisson error prefixes across supported versions
trask Oct 21, 2026
ffdcff1
Use literal Unicode in Redis prefix tests
trask Oct 21, 2026
b03040e
Merge branch 'main' into copilot/redisson-redis-error-classification
trask Oct 21, 2026
775a387
Use shared Redis prefix extraction
Copilot Oct 21, 2026
67ca1b0
Remove redundant Redisson getter test
Copilot Oct 21, 2026
c4e9ffa
Capture Redisson batch failure prefixes
Copilot Oct 21, 2026
e6c95e6
Merge main into Redisson error classification
trask Oct 22, 2026
f581f15
Simplify Redisson decoder capture
Copilot Oct 22, 2026
baf0436
Consume captured Redisson server error prefix before completion callb…
Copilot Oct 22, 2026
7955b92
Test reentrant Redisson completion callbacks
Copilot Oct 22, 2026
110a764
Apply suggestion from @trask
trask Oct 23, 2026
281ede5
Refactor Redisson CRLF scanning
Copilot Oct 23, 2026
e1db51d
Use named Redis error virtual field
Copilot Oct 23, 2026
75b55b6
Pin Redisson helper unit-test baseline
Copilot Oct 23, 2026
7670cc9
Simplify checked exceptions in Redisson tests
Copilot Oct 23, 2026
693bf82
Rename Redisson error assertion helper
Copilot Oct 23, 2026
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 @@ -13,6 +13,7 @@
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import io.opentelemetry.javaagent.instrumentation.redisson.common.v3_0.CompletableFutureWrapper;
import io.opentelemetry.javaagent.instrumentation.redisson.common.v3_0.RedissonErrorCapture;
import java.util.concurrent.CompletableFuture;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.asm.Advice.AssignReturned;
Expand All @@ -26,7 +27,9 @@ class RedisCommandDataInstrumentation implements TypeInstrumentation {
@Override
public ElementMatcher<TypeDescription> typeMatcher() {
return namedOneOf(
"org.redisson.client.protocol.CommandData", "org.redisson.client.protocol.CommandsData");
"org.redisson.client.protocol.CommandData",
"org.redisson.client.protocol.CommandsData",
"org.redisson.client.protocol.BatchCommandData");
}

@Override
Expand All @@ -39,6 +42,9 @@ public void transform(TypeTransformer transformer) {
transformer.applyAdviceToMethod(
isConstructor().and(takesArgument(0, CompletableFuture.class)),
getClass().getName() + "$WrapCompletableFutureAdvice");
transformer.applyAdviceToMethod(
named("tryFailure").and(takesArgument(0, Throwable.class)),
getClass().getName() + "$CaptureErrorAdvice");
}

@SuppressWarnings("unused")
Expand All @@ -61,4 +67,13 @@ public static CompletableFuture<?> onEnter(
return CompletableFutureWrapper.wrap(completableFuture);
}
}

@SuppressWarnings("unused")
public static class CaptureErrorAdvice {

@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
public static void onEnter(@Advice.Argument(0) Throwable error) {
RedissonErrorCapture.captureServerError(error);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.google.auto.service.AutoService;
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.instrumentation.redisson.common.v3_0.RedisCommandDecoderInstrumentation;
import java.util.List;
import net.bytebuddy.matcher.ElementMatcher;

Expand All @@ -35,6 +36,7 @@ public List<TypeInstrumentation> typeInstrumentations() {
new ConnectionManagerConnectionFutureInstrumentation(),
new MasterSlaveConnectionManagerInstrumentation(),
new RedisConnectionInstrumentation(),
new RedisCommandDecoderInstrumentation(),
new RedisCommandDataInstrumentation());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,12 @@
package io.opentelemetry.javaagent.instrumentation.redisson.v3_0;

import io.opentelemetry.javaagent.instrumentation.redisson.AbstractRedissonAsyncClientTest;
import org.redisson.api.RBatch;
import org.redisson.api.RedissonClient;

class RedissonAsyncClientTest extends AbstractRedissonAsyncClientTest {}
class RedissonAsyncClientTest extends AbstractRedissonAsyncClientTest {
@Override
protected RBatch createBatch(RedissonClient redisson) {
return redisson.createBatch();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
package io.opentelemetry.javaagent.instrumentation.redisson.v3_17;

import static net.bytebuddy.matcher.ElementMatchers.isConstructor;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.namedOneOf;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;

import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import io.opentelemetry.javaagent.instrumentation.redisson.common.v3_0.CompletableFutureWrapper;
import io.opentelemetry.javaagent.instrumentation.redisson.common.v3_0.RedissonErrorCapture;
import java.util.concurrent.CompletableFuture;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.asm.Advice.AssignReturned;
Expand All @@ -24,14 +26,19 @@ class RedisCommandDataInstrumentation implements TypeInstrumentation {
@Override
public ElementMatcher<TypeDescription> typeMatcher() {
return namedOneOf(
"org.redisson.client.protocol.CommandData", "org.redisson.client.protocol.CommandsData");
"org.redisson.client.protocol.CommandData",
"org.redisson.client.protocol.CommandsData",
"org.redisson.client.protocol.BatchCommandData");
}

@Override
public void transform(TypeTransformer transformer) {
transformer.applyAdviceToMethod(
isConstructor().and(takesArgument(0, CompletableFuture.class)),
getClass().getName() + "$WrapCompletableFutureAdvice");
transformer.applyAdviceToMethod(
named("tryFailure").and(takesArgument(0, Throwable.class)),
getClass().getName() + "$CaptureErrorAdvice");
Comment thread
trask marked this conversation as resolved.
Comment thread
trask marked this conversation as resolved.
}

@SuppressWarnings("unused")
Expand All @@ -44,4 +51,13 @@ public static CompletableFuture<?> onEnter(
return CompletableFutureWrapper.wrap(completableFuture);
}
}

@SuppressWarnings("unused")
public static class CaptureErrorAdvice {

@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
public static void onEnter(@Advice.Argument(0) Throwable error) {
RedissonErrorCapture.captureServerError(error);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.google.auto.service.AutoService;
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.instrumentation.redisson.common.v3_0.RedisCommandDecoderInstrumentation;
import java.util.List;
import net.bytebuddy.matcher.ElementMatcher;

Expand All @@ -34,6 +35,7 @@ public List<TypeInstrumentation> typeInstrumentations() {
new MasterSlaveConnectionManagerInstrumentation(),
new RedisExecutorConnectionFutureInstrumentation(),
new RedisConnectionInstrumentation(),
new RedisCommandDecoderInstrumentation(),
new RedisCommandDataInstrumentation());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,21 @@ dependencies {
compileOnly("com.google.auto.value:auto-value-annotations")
annotationProcessor("com.google.auto.value:auto-value")
}

testing {
suites {
register<JvmTestSuite>("unitTests") {
dependencies {
implementation(project())
implementation(project(":instrumentation-api-incubator"))
implementation("org.redisson:redisson:3.0.0")
}
}
}
}

tasks {
check {
dependsOn(testing.suites)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public EndOperationListener(

@Override
public void accept(@Nullable T unused, @Nullable Throwable error) {
instrumenter.end(context, request, null, error);
try {
instrumenter.end(context, request, null, error);
} finally {
RedissonErrorCapture.clearServerError(error);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.redisson.common.v3_0;

import static io.opentelemetry.javaagent.instrumentation.redisson.common.v3_0.RedissonErrorCapture.currentServerErrorType;
import static io.opentelemetry.javaagent.instrumentation.redisson.common.v3_0.RedissonErrorCapture.parseServerErrorType;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;

import io.netty.buffer.ByteBuf;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import javax.annotation.Nullable;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;

public class RedisCommandDecoderInstrumentation implements TypeInstrumentation {

@Override
public ElementMatcher<TypeDescription> typeMatcher() {
return named("org.redisson.client.handler.CommandDecoder");
}

@Override
public void transform(TypeTransformer transformer) {
transformer.applyAdviceToMethod(
named("decode")
.and(takesArgument(0, named("io.netty.buffer.ByteBuf")))
.and(takesArgument(1, named("org.redisson.client.protocol.CommandData"))),
getClass().getName() + "$DecodeAdvice");
}

@SuppressWarnings("unused")
public static class DecodeAdvice {

@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
public static String onEnter(@Advice.Argument(0) ByteBuf input) {
return currentServerErrorType().set(parseServerErrorType(input));
}

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class, inline = false)
public static void onExit(@Advice.Enter @Nullable String previousErrorType) {
currentServerErrorType().restore(previousErrorType);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ public Long getDbOperationBatchSize(RedissonRequest request) {
return request.getOperationBatchSize();
}

@Override
@Nullable
public String getErrorType(
RedissonRequest request, @Nullable Void response, @Nullable Throwable error) {
return RedissonErrorCapture.getServerErrorType(error);
}

@Nullable
@Override
public String getServerAddress(RedissonRequest request) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.redisson.common.v3_0;

import static java.nio.charset.StandardCharsets.UTF_8;

import io.netty.buffer.ByteBuf;
import io.opentelemetry.instrumentation.api.incubator.semconv.db.internal.RedisErrorPrefix;
import io.opentelemetry.instrumentation.api.internal.ScopedThreadValue;
import io.opentelemetry.instrumentation.api.util.VirtualField;
import javax.annotation.Nullable;
import org.redisson.client.RedisException;

/**
* Captures the first token from RESP error replies before Redisson completes the command promise.
*
* <p>Redisson's {@code CommandDecoder} calls {@code CommandData.tryFailure} while decoding a {@code
* -} reply, so the token is scoped to that decoder frame and attached to the resulting Redisson
* exception before completion callbacks can run. The operation listener clears it after extracting
* telemetry; all other errors use the shared exception-class fallback.
*
* @see <a
* href="https://redis.io/docs/latest/develop/reference/protocol-spec/#resp-protocol-description">RESP
* specification</a>
* @see <a
* href="https://github.com/redisson/redisson/blob/3.52.0/redisson/src/main/java/org/redisson/client/handler/CommandDecoder.java">Redisson
* CommandDecoder</a>
*/
public final class RedissonErrorCapture {

private static final ScopedThreadValue<String> currentServerErrorType = new ScopedThreadValue<>();

private static final VirtualField<RedisException, String> SERVER_ERROR =
VirtualField.find(RedisException.class, String.class, "redissonServerErrorType");

public static ScopedThreadValue<String> currentServerErrorType() {
return currentServerErrorType;
}

@Nullable
public static String parseServerErrorType(ByteBuf input) {
Comment thread
trask marked this conversation as resolved.
try {
int replyStart = input.readerIndex();
if (input.getByte(replyStart) != '-') {
return null;
}

int lineStart = replyStart + 1;
int lineEnd = findCrlf(input, lineStart);
if (lineEnd == -1) {
return null;
}

return RedisErrorPrefix.extract(input.toString(lineStart, lineEnd - lineStart, UTF_8));
} catch (Throwable ignored) {
// ReplayingDecoder retries incomplete replies; leave buffer handling to Redisson.
return null;
}
}

private static int findCrlf(ByteBuf input, int start) {
int end = input.writerIndex();
for (int i = start; i + 1 < end; i++) {
if (input.getByte(i) == '\r' && input.getByte(i + 1) == '\n') {
return i;
}
}
return -1;
}

public static void captureServerError(@Nullable Throwable error) {
if (!(error instanceof RedisException)) {
return;
}

String errorType = currentServerErrorType.get();
Comment thread
trask marked this conversation as resolved.
Comment thread
trask marked this conversation as resolved.
if (errorType != null) {
SERVER_ERROR.set((RedisException) error, errorType);
// consume so completion callbacks run by tryFailure cannot attribute it to another command
currentServerErrorType.set(null);
}
}

@Nullable
public static String getServerErrorType(@Nullable Throwable error) {
if (!(error instanceof RedisException)) {
return null;
}

return SERVER_ERROR.get((RedisException) error);
}

public static void clearServerError(@Nullable Throwable error) {
if (error instanceof RedisException) {
SERVER_ERROR.set((RedisException) error, null);
}
}

private RedissonErrorCapture() {}
}
Loading
Loading