Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -43,6 +43,8 @@ final class OpenTelemetryTracing implements Tracing {
private static final AttributeKey<String> DB_SYSTEM = AttributeKey.stringKey("db.system");
private static final AttributeKey<String> DB_STATEMENT = AttributeKey.stringKey("db.statement");
private static final AttributeKey<String> DB_QUERY_TEXT = AttributeKey.stringKey("db.query.text");
private static final AttributeKey<Long> DB_REDIS_DATABASE_INDEX =
AttributeKey.longKey("db.redis.database_index");
// copied from DbIncubatingAttributes.DbSystemIncubatingValues
private static final String REDIS = "redis";

Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -80,10 +82,15 @@ private ContainerConnection(StatefulRedisConnection<String, String> connection,
}
}

@SuppressWarnings("deprecation") // using deprecated semconv
protected static List<AttributeAssertion> addExtraAttributes(AttributeAssertion... assertions) {
List<AttributeAssertion> 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;
}
Expand Down
Loading