From 6cf872e33096a38e69fcee4a0ae37a4ceca475c7 Mon Sep 17 00:00:00 2001 From: Lauri Tulmin Date: Thu, 30 Oct 2025 13:31:29 +0200 Subject: [PATCH] Add parent span to more lettuce tests --- .../v5_1/AbstractLettuceAsyncClientTest.java | 5 ++- .../AbstractLettuceReactiveClientTest.java | 20 ++++++---- .../v5_1/AbstractLettuceSyncClientTest.java | 40 ++++++++++++++----- 3 files changed, 48 insertions(+), 17 deletions(-) diff --git a/instrumentation/lettuce/lettuce-5.1/testing/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceAsyncClientTest.java b/instrumentation/lettuce/lettuce-5.1/testing/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceAsyncClientTest.java index a7829ad43267..e7694752c288 100644 --- a/instrumentation/lettuce/lettuce-5.1/testing/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceAsyncClientTest.java +++ b/instrumentation/lettuce/lettuce-5.1/testing/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceAsyncClientTest.java @@ -147,7 +147,8 @@ void testConnectExceptionInsideTheConnectionFuture() { @Test void testSetCommandUsingFutureGetWithTimeout() throws Exception { - RedisFuture redisFuture = asyncCommands.set("TESTSETKEY", "TESTSETVAL"); + RedisFuture redisFuture = + testing().runWithSpan("parent", () -> asyncCommands.set("TESTSETKEY", "TESTSETVAL")); String res = redisFuture.get(3, TimeUnit.SECONDS); assertThat(res).isEqualTo("OK"); @@ -156,9 +157,11 @@ void testSetCommandUsingFutureGetWithTimeout() throws Exception { .waitAndAssertTraces( trace -> trace.hasSpansSatisfyingExactly( + span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(), span -> span.hasName("SET") .hasKind(SpanKind.CLIENT) + .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( addExtraAttributes( equalTo(NETWORK_TYPE, "ipv4"), diff --git a/instrumentation/lettuce/lettuce-5.1/testing/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceReactiveClientTest.java b/instrumentation/lettuce/lettuce-5.1/testing/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceReactiveClientTest.java index 906d69902f8e..fd4593d2ffd4 100644 --- a/instrumentation/lettuce/lettuce-5.1/testing/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceReactiveClientTest.java +++ b/instrumentation/lettuce/lettuce-5.1/testing/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceReactiveClientTest.java @@ -117,13 +117,17 @@ void testSetCommandWithSubscribeOnDefinedConsumer() throws Exception { void testGetCommandWithLambdaFunction() throws Exception { CompletableFuture future = new CompletableFuture<>(); - reactiveCommands - .get("TESTKEY") - .subscribe( - res -> { - assertThat(res).isEqualTo("TESTVAL"); - future.complete(res); - }); + testing() + .runWithSpan( + "parent", + () -> + reactiveCommands + .get("TESTKEY") + .subscribe( + res -> { + assertThat(res).isEqualTo("TESTVAL"); + future.complete(res); + })); assertThat(future.get(10, TimeUnit.SECONDS)).isEqualTo("TESTVAL"); @@ -131,9 +135,11 @@ void testGetCommandWithLambdaFunction() throws Exception { .waitAndAssertTraces( trace -> trace.hasSpansSatisfyingExactly( + span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(), span -> span.hasName("GET") .hasKind(SpanKind.CLIENT) + .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( addExtraAttributes( equalTo(NETWORK_TYPE, "ipv4"), diff --git a/instrumentation/lettuce/lettuce-5.1/testing/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceSyncClientTest.java b/instrumentation/lettuce/lettuce-5.1/testing/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceSyncClientTest.java index 9c96963aa0b4..154215fc5ab7 100644 --- a/instrumentation/lettuce/lettuce-5.1/testing/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceSyncClientTest.java +++ b/instrumentation/lettuce/lettuce-5.1/testing/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceSyncClientTest.java @@ -119,16 +119,19 @@ void testConnectException() { @Test void testSetCommand() { - String res = syncCommands.set("TESTSETKEY", "TESTSETVAL"); + String res = + testing().runWithSpan("parent", () -> syncCommands.set("TESTSETKEY", "TESTSETVAL")); assertThat(res).isEqualTo("OK"); testing() .waitAndAssertTraces( trace -> trace.hasSpansSatisfyingExactly( + span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(), span -> span.hasName("SET") .hasKind(SpanKind.CLIENT) + .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( addExtraAttributes( equalTo(NETWORK_TYPE, "ipv4"), @@ -161,16 +164,18 @@ private static AttributeKey[] toArray(List> expected) { @Test void testGetCommand() { - String res = syncCommands.get("TESTKEY"); + String res = testing().runWithSpan("parent", () -> syncCommands.get("TESTKEY")); assertThat(res).isEqualTo("TESTVAL"); testing() .waitAndAssertTraces( trace -> trace.hasSpansSatisfyingExactly( + span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(), span -> span.hasName("GET") .hasKind(SpanKind.CLIENT) + .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( addExtraAttributes( equalTo(NETWORK_TYPE, "ipv4"), @@ -185,16 +190,18 @@ void testGetCommand() { @Test void testGetNonExistentKeyCommand() { - String res = syncCommands.get("NON_EXISTENT_KEY"); + String res = testing().runWithSpan("parent", () -> syncCommands.get("NON_EXISTENT_KEY")); assertThat(res).isNull(); testing() .waitAndAssertTraces( trace -> trace.hasSpansSatisfyingExactly( + span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(), span -> span.hasName("GET") .hasKind(SpanKind.CLIENT) + .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( addExtraAttributes( equalTo(NETWORK_TYPE, "ipv4"), @@ -209,16 +216,18 @@ void testGetNonExistentKeyCommand() { @Test void testCommandWithNoArguments() { - String res = syncCommands.randomkey(); + String res = testing().runWithSpan("parent", () -> syncCommands.randomkey()); assertThat(res).isNotNull(); testing() .waitAndAssertTraces( trace -> trace.hasSpansSatisfyingExactly( + span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(), span -> span.hasName("RANDOMKEY") .hasKind(SpanKind.CLIENT) + .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( addExtraAttributes( equalTo(NETWORK_TYPE, "ipv4"), @@ -243,16 +252,19 @@ void testListCommand() { testing().clearData(); } - long res = commands.lpush("TESTLIST", "TESTLIST ELEMENT"); + long res = + testing().runWithSpan("parent", () -> commands.lpush("TESTLIST", "TESTLIST ELEMENT")); assertThat(res).isEqualTo(1); testing() .waitAndAssertTraces( trace -> trace.hasSpansSatisfyingExactly( + span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(), span -> span.hasName("LPUSH") .hasKind(SpanKind.CLIENT) + .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( addExtraAttributes( equalTo(NETWORK_TYPE, "ipv4"), @@ -267,16 +279,18 @@ void testListCommand() { @Test void testHashSetCommand() { - String res = syncCommands.hmset("user", testHashMap); + String res = testing().runWithSpan("parent", () -> syncCommands.hmset("user", testHashMap)); assertThat(res).isEqualTo("OK"); testing() .waitAndAssertTraces( trace -> trace.hasSpansSatisfyingExactly( + span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(), span -> span.hasName("HMSET") .hasKind(SpanKind.CLIENT) + .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( addExtraAttributes( equalTo(NETWORK_TYPE, "ipv4"), @@ -293,16 +307,18 @@ void testHashSetCommand() { @Test void testHashGetallCommand() { - Map res = syncCommands.hgetall("TESTHM"); + Map res = testing().runWithSpan("parent", () -> syncCommands.hgetall("TESTHM")); assertThat(res).isEqualTo(testHashMap); testing() .waitAndAssertTraces( trace -> trace.hasSpansSatisfyingExactly( + span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(), span -> span.hasName("HGETALL") .hasKind(SpanKind.CLIENT) + .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( addExtraAttributes( equalTo(NETWORK_TYPE, "ipv4"), @@ -321,8 +337,12 @@ void testEvalCommand() { "redis.call('lpush', KEYS[1], ARGV[1], ARGV[2]); return redis.call('llen', KEYS[1])"; Long result = - syncCommands.eval( - script, ScriptOutputType.INTEGER, new String[] {"TESTLIST"}, "abc", "def"); + testing() + .runWithSpan( + "parent", + () -> + syncCommands.eval( + script, ScriptOutputType.INTEGER, new String[] {"TESTLIST"}, "abc", "def")); assertThat(result).isEqualTo(2); String b64Script = Base64.getEncoder().encodeToString(script.getBytes(UTF_8)); @@ -331,9 +351,11 @@ void testEvalCommand() { .waitAndAssertTraces( trace -> trace.hasSpansSatisfyingExactly( + span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(), span -> span.hasName("EVAL") .hasKind(SpanKind.CLIENT) + .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( addExtraAttributes( equalTo(NETWORK_TYPE, "ipv4"),