-
Notifications
You must be signed in to change notification settings - Fork 909
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update jedis-1.4 to Instrumenter API (#3064)
- Loading branch information
Showing
8 changed files
with
174 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 0 additions & 90 deletions
90
...rc/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v1_4/JedisClientTracer.java
This file was deleted.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
...ava/io/opentelemetry/javaagent/instrumentation/jedis/v1_4/JedisDbAttributesExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.jedis.v1_4; | ||
|
||
import io.opentelemetry.instrumentation.api.db.RedisCommandSanitizer; | ||
import io.opentelemetry.instrumentation.api.instrumenter.db.DbAttributesExtractor; | ||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; | ||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
||
final class JedisDbAttributesExtractor extends DbAttributesExtractor<JedisRequest> { | ||
@Override | ||
protected String system(JedisRequest request) { | ||
return SemanticAttributes.DbSystemValues.REDIS; | ||
} | ||
|
||
@Override | ||
@Nullable | ||
protected String user(JedisRequest request) { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected String name(JedisRequest request) { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected String connectionString(JedisRequest request) { | ||
return request.getConnectionString(); | ||
} | ||
|
||
@Override | ||
protected String statement(JedisRequest request) { | ||
return RedisCommandSanitizer.sanitize(request.getCommand().name(), request.getArgs()); | ||
} | ||
|
||
@Override | ||
protected String operation(JedisRequest request) { | ||
return request.getCommand().name(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...c/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v1_4/JedisInstrumenters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.jedis.v1_4; | ||
|
||
import io.opentelemetry.api.GlobalOpenTelemetry; | ||
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; | ||
import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor; | ||
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; | ||
import io.opentelemetry.instrumentation.api.instrumenter.db.DbAttributesExtractor; | ||
import io.opentelemetry.instrumentation.api.instrumenter.db.DbSpanNameExtractor; | ||
|
||
public final class JedisInstrumenters { | ||
private static final String INSTRUMENTATION_NAME = "io.opentelemetry.javaagent.jedis-1.4"; | ||
|
||
private static final Instrumenter<JedisRequest, Void> INSTRUMENTER; | ||
|
||
static { | ||
DbAttributesExtractor<JedisRequest> attributesExtractor = new JedisDbAttributesExtractor(); | ||
SpanNameExtractor<JedisRequest> spanName = DbSpanNameExtractor.create(attributesExtractor); | ||
|
||
INSTRUMENTER = | ||
Instrumenter.<JedisRequest, Void>newBuilder( | ||
GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, spanName) | ||
.addAttributesExtractor(attributesExtractor) | ||
.addAttributesExtractor(new JedisNetAttributesExtractor()) | ||
.newInstrumenter(SpanKindExtractor.alwaysClient()); | ||
} | ||
|
||
public static Instrumenter<JedisRequest, Void> instrumenter() { | ||
return INSTRUMENTER; | ||
} | ||
|
||
private JedisInstrumenters() {} | ||
} |
34 changes: 34 additions & 0 deletions
34
...va/io/opentelemetry/javaagent/instrumentation/jedis/v1_4/JedisNetAttributesExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.jedis.v1_4; | ||
|
||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; | ||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
||
final class JedisNetAttributesExtractor extends NetAttributesExtractor<JedisRequest, Void> { | ||
|
||
@Override | ||
@Nullable | ||
protected String transport(JedisRequest request) { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected String peerName(JedisRequest request, @Nullable Void response) { | ||
return request.getConnection().getHost(); | ||
} | ||
|
||
@Override | ||
protected Integer peerPort(JedisRequest request, @Nullable Void response) { | ||
return request.getConnection().getPort(); | ||
} | ||
|
||
@Override | ||
@Nullable | ||
protected String peerIp(JedisRequest request, @Nullable Void response) { | ||
return null; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...ent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v1_4/JedisRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.jedis.v1_4; | ||
|
||
import static java.util.Collections.emptyList; | ||
|
||
import com.google.auto.value.AutoValue; | ||
import java.util.List; | ||
import redis.clients.jedis.Connection; | ||
import redis.clients.jedis.Protocol; | ||
|
||
@AutoValue | ||
public abstract class JedisRequest { | ||
|
||
public abstract Connection getConnection(); | ||
|
||
public abstract Protocol.Command getCommand(); | ||
|
||
public abstract List<byte[]> getArgs(); | ||
|
||
public String getConnectionString() { | ||
return getConnection().getHost() + ":" + getConnection().getPort(); | ||
} | ||
|
||
public static JedisRequest create(Connection connection, Protocol.Command command) { | ||
return new AutoValue_JedisRequest(connection, command, emptyList()); | ||
} | ||
|
||
public static JedisRequest create( | ||
Connection connection, Protocol.Command command, List<byte[]> args) { | ||
return new AutoValue_JedisRequest(connection, command, args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters