diff --git a/instrumentation/lettuce/lettuce-5.1/library/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/OpenTelemetryTracing.java b/instrumentation/lettuce/lettuce-5.1/library/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/OpenTelemetryTracing.java index 6fb88f269b5e..3b2e06f3b64e 100644 --- a/instrumentation/lettuce/lettuce-5.1/library/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/OpenTelemetryTracing.java +++ b/instrumentation/lettuce/lettuce-5.1/library/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/OpenTelemetryTracing.java @@ -43,6 +43,8 @@ final class OpenTelemetryTracing implements Tracing { private static final AttributeKey DB_SYSTEM = AttributeKey.stringKey("db.system"); private static final AttributeKey DB_STATEMENT = AttributeKey.stringKey("db.statement"); private static final AttributeKey DB_QUERY_TEXT = AttributeKey.stringKey("db.query.text"); + private static final AttributeKey DB_REDIS_DATABASE_INDEX = + AttributeKey.longKey("db.redis.database_index"); // copied from DbIncubatingAttributes.DbSystemIncubatingValues private static final String REDIS = "redis"; @@ -313,6 +315,16 @@ public synchronized Tracer.Span tag(String key, String value) { argsString = value; return this; } + if (key.equals("db.namespace") && SemconvStability.emitOldDatabaseSemconv()) { + // map backwards into db.redis.database.index + long val = Long.parseLong(value); + if (span != null) { + span.setAttribute(DB_REDIS_DATABASE_INDEX, val); + } else { + spanBuilder.setAttribute(DB_REDIS_DATABASE_INDEX, val); + } + return this; + } if (span != null) { span.setAttribute(key, value); } else { diff --git a/instrumentation/lettuce/lettuce-5.1/testing/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceClientTest.java b/instrumentation/lettuce/lettuce-5.1/testing/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceClientTest.java index dff22a6a78e7..56573539a278 100644 --- a/instrumentation/lettuce/lettuce-5.1/testing/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceClientTest.java +++ b/instrumentation/lettuce/lettuce-5.1/testing/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceClientTest.java @@ -7,9 +7,11 @@ import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_NAMESPACE; +import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_REDIS_DATABASE_INDEX; import io.lettuce.core.RedisClient; import io.lettuce.core.api.StatefulRedisConnection; +import io.opentelemetry.instrumentation.api.internal.SemconvStability; import io.opentelemetry.instrumentation.testing.internal.AutoCleanupExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.sdk.testing.assertj.AttributeAssertion; @@ -80,10 +82,15 @@ private ContainerConnection(StatefulRedisConnection connection, } } + @SuppressWarnings("deprecation") // using deprecated semconv protected static List addExtraAttributes(AttributeAssertion... assertions) { List result = new ArrayList<>(Arrays.asList(assertions)); if (Boolean.getBoolean("testLatestDeps")) { - result.add(equalTo(DB_NAMESPACE, "0")); + if (SemconvStability.emitStableDatabaseSemconv()) { + result.add(equalTo(DB_NAMESPACE, "0")); + } else { + result.add(equalTo(DB_REDIS_DATABASE_INDEX, 0)); + } } return result; }