Skip to content

Commit

Permalink
Update attribute names as recommend
Browse files Browse the repository at this point in the history
  • Loading branch information
thachlp committed Oct 7, 2024
1 parent daab0a8 commit 9abe7f3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/main/java/io/lettuce/core/protocol/CommandHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -482,12 +482,12 @@ private void attachTracing(ChannelHandlerContext ctx, RedisCommand<?, ?, ?> comm
Tracer.Span span = tracer.nextSpan(context);
span.name(command.getType().name());

String redisUriStr = ctx.channel().attr(ConnectionBuilder.REDIS_URI).get();
RedisURI redisURI = RedisURI.create(redisUriStr);
span.tag("db.uri", redisURI.toString());
span.tag("db.number", String.valueOf(redisURI.getDatabase()));
span.tag("db.user", Optional.ofNullable(redisURI.getCredentialsProvider().resolveCredentials().block())
.map(RedisCredentials::getUsername).orElse(""));
if (channel.hasAttr(ConnectionBuilder.REDIS_URI)) {
String redisUriStr = channel.attr(ConnectionBuilder.REDIS_URI).get();
RedisURI redisURI = RedisURI.create(redisUriStr);
span.tag("server.address", redisURI.toString());
span.tag("db.namespace", String.valueOf(redisURI.getDatabase()));
}

if (tracedEndpoint != null) {
span.remoteEndpoint(tracedEndpoint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,8 @@ public SampleTestRunnerConsumer yourCode() {
.containsEntry("net.sock.peer.addr", TestSettings.host())
.containsEntry("net.sock.peer.port", "" + TestSettings.port());
assertThat(finishedSpan.getTags()).containsKeys("db.operation");
assertThat(finishedSpan.getTags()).containsKeys("db.uri");
assertThat(finishedSpan.getTags()).containsKeys("db.number");
assertThat(finishedSpan.getTags()).containsKeys("db.user");
assertThat(finishedSpan.getTags()).containsKeys("server.address");
assertThat(finishedSpan.getTags()).containsKeys("db.namespace");
}

assertThat(commands).extracting(RedisCommand::getType).contains(CommandType.PING, CommandType.HELLO);
Expand Down

0 comments on commit 9abe7f3

Please sign in to comment.