Skip to content

Commit de27128

Browse files
authored
Lettuce metadata (#15439)
1 parent 4b502a6 commit de27128

File tree

15 files changed

+411
-19
lines changed

15 files changed

+411
-19
lines changed

docs/instrumentation-list.yaml

Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7801,20 +7801,193 @@ libraries:
78017801
type: STRING
78027802
lettuce:
78037803
- name: lettuce-4.0
7804+
description: |
7805+
This instrumentation enables database client spans and database client metrics for the Lettuce Redis client.
7806+
semantic_conventions:
7807+
- DATABASE_CLIENT_SPANS
7808+
- DATABASE_CLIENT_METRICS
7809+
library_link: https://github.com/redis/lettuce
78047810
source_path: instrumentation/lettuce/lettuce-4.0
78057811
scope:
78067812
name: io.opentelemetry.lettuce-4.0
78077813
target_versions:
78087814
javaagent:
78097815
- biz.paluch.redis:lettuce:[4.0.Final,)
7816+
configurations:
7817+
- name: otel.instrumentation.lettuce.connection-telemetry.enabled
7818+
description: Enables connection telemetry spans for Redis connections.
7819+
type: boolean
7820+
default: false
7821+
- name: otel.instrumentation.lettuce.experimental-span-attributes
7822+
description: Enables experimental span attribute `lettuce.command.cancelled`.
7823+
type: boolean
7824+
default: false
7825+
- name: otel.instrumentation.common.peer-service-mapping
7826+
description: Used to specify a mapping from host names or IP addresses to peer
7827+
services.
7828+
type: map
7829+
default: ''
7830+
telemetry:
7831+
- when: default
7832+
spans:
7833+
- span_kind: CLIENT
7834+
attributes:
7835+
- name: db.operation
7836+
type: STRING
7837+
- name: db.system
7838+
type: STRING
7839+
- name: peer.service
7840+
type: STRING
7841+
- name: server.address
7842+
type: STRING
7843+
- name: server.port
7844+
type: LONG
7845+
- when: otel.instrumentation.lettuce.experimental-span-attributes=true
7846+
spans:
7847+
- span_kind: CLIENT
7848+
attributes:
7849+
- name: db.operation
7850+
type: STRING
7851+
- name: db.system
7852+
type: STRING
7853+
- name: lettuce.command.cancelled
7854+
type: BOOLEAN
7855+
- name: peer.service
7856+
type: STRING
7857+
- name: server.address
7858+
type: STRING
7859+
- name: server.port
7860+
type: LONG
7861+
- when: otel.semconv-stability.opt-in=database
7862+
metrics:
7863+
- name: db.client.operation.duration
7864+
description: Duration of database client operations.
7865+
type: HISTOGRAM
7866+
unit: s
7867+
attributes:
7868+
- name: db.operation.name
7869+
type: STRING
7870+
- name: db.system.name
7871+
type: STRING
7872+
spans:
7873+
- span_kind: CLIENT
7874+
attributes:
7875+
- name: db.operation.name
7876+
type: STRING
7877+
- name: db.system.name
7878+
type: STRING
7879+
- name: error.type
7880+
type: STRING
7881+
- name: peer.service
7882+
type: STRING
7883+
- name: server.address
7884+
type: STRING
7885+
- name: server.port
7886+
type: LONG
78107887
- name: lettuce-5.0
7888+
description: |
7889+
This instrumentation enables database client spans and database client metrics for the Lettuce Redis client.
7890+
semantic_conventions:
7891+
- DATABASE_CLIENT_SPANS
7892+
- DATABASE_CLIENT_METRICS
7893+
library_link: https://github.com/redis/lettuce
78117894
source_path: instrumentation/lettuce/lettuce-5.0
78127895
scope:
78137896
name: io.opentelemetry.lettuce-5.0
78147897
target_versions:
78157898
javaagent:
78167899
- io.lettuce:lettuce-core:[5.0.0.RELEASE,5.1.0.RELEASE)
7900+
configurations:
7901+
- name: otel.instrumentation.lettuce.connection-telemetry.enabled
7902+
description: Enables connection telemetry spans for Redis connections.
7903+
type: boolean
7904+
default: false
7905+
- name: otel.instrumentation.lettuce.experimental-span-attributes
7906+
description: |
7907+
Enables experimental span attributes `lettuce.command.cancelled` and `lettuce.command.results.count`.
7908+
type: boolean
7909+
default: false
7910+
- name: otel.instrumentation.common.db-statement-sanitizer.enabled
7911+
description: Enables statement sanitization for database queries.
7912+
type: boolean
7913+
default: true
7914+
- name: otel.instrumentation.common.peer-service-mapping
7915+
description: Used to specify a mapping from host names or IP addresses to peer
7916+
services.
7917+
type: map
7918+
default: ''
7919+
telemetry:
7920+
- when: default
7921+
spans:
7922+
- span_kind: CLIENT
7923+
attributes:
7924+
- name: db.operation
7925+
type: STRING
7926+
- name: db.statement
7927+
type: STRING
7928+
- name: db.system
7929+
type: STRING
7930+
- name: peer.service
7931+
type: STRING
7932+
- name: server.address
7933+
type: STRING
7934+
- name: server.port
7935+
type: LONG
7936+
- when: otel.instrumentation.lettuce.experimental-span-attributes=true
7937+
spans:
7938+
- span_kind: CLIENT
7939+
attributes:
7940+
- name: db.operation
7941+
type: STRING
7942+
- name: db.statement
7943+
type: STRING
7944+
- name: db.system
7945+
type: STRING
7946+
- name: lettuce.command.cancelled
7947+
type: BOOLEAN
7948+
- name: lettuce.command.results.count
7949+
type: LONG
7950+
- name: peer.service
7951+
type: STRING
7952+
- name: server.address
7953+
type: STRING
7954+
- name: server.port
7955+
type: LONG
7956+
- when: otel.semconv-stability.opt-in=database
7957+
metrics:
7958+
- name: db.client.operation.duration
7959+
description: Duration of database client operations.
7960+
type: HISTOGRAM
7961+
unit: s
7962+
attributes:
7963+
- name: db.operation.name
7964+
type: STRING
7965+
- name: db.system.name
7966+
type: STRING
7967+
spans:
7968+
- span_kind: CLIENT
7969+
attributes:
7970+
- name: db.operation.name
7971+
type: STRING
7972+
- name: db.query.text
7973+
type: STRING
7974+
- name: db.system.name
7975+
type: STRING
7976+
- name: error.type
7977+
type: STRING
7978+
- name: peer.service
7979+
type: STRING
7980+
- name: server.address
7981+
type: STRING
7982+
- name: server.port
7983+
type: LONG
78177984
- name: lettuce-5.1
7985+
description: |
7986+
This instrumentation enables database client spans and database client metrics for the Lettuce Redis client.
7987+
semantic_conventions:
7988+
- DATABASE_CLIENT_SPANS
7989+
- DATABASE_CLIENT_METRICS
7990+
library_link: https://github.com/redis/lettuce
78187991
source_path: instrumentation/lettuce/lettuce-5.1
78197992
scope:
78207993
name: io.opentelemetry.lettuce-5.1
@@ -7823,6 +7996,73 @@ libraries:
78237996
- io.lettuce:lettuce-core:[5.1.0.RELEASE,)
78247997
library:
78257998
- io.lettuce:lettuce-core:5.1.0.RELEASE
7999+
configurations:
8000+
- name: otel.instrumentation.lettuce.experimental.command-encoding-events.enabled
8001+
description: Enables capturing `redis.encode.start` and `redis.encode.end` span
8002+
events.
8003+
type: boolean
8004+
default: false
8005+
- name: otel.instrumentation.common.db-statement-sanitizer.enabled
8006+
description: Enables statement sanitization for database queries.
8007+
type: boolean
8008+
default: true
8009+
telemetry:
8010+
- when: default
8011+
spans:
8012+
- span_kind: CLIENT
8013+
attributes:
8014+
- name: db.statement
8015+
type: STRING
8016+
- name: db.system
8017+
type: STRING
8018+
- name: error
8019+
type: STRING
8020+
- name: network.peer.address
8021+
type: STRING
8022+
- name: network.peer.port
8023+
type: LONG
8024+
- name: network.type
8025+
type: STRING
8026+
- name: server.address
8027+
type: STRING
8028+
- name: server.port
8029+
type: LONG
8030+
- when: otel.semconv-stability.opt-in=database
8031+
metrics:
8032+
- name: db.client.operation.duration
8033+
description: Duration of database client operations.
8034+
type: HISTOGRAM
8035+
unit: s
8036+
attributes:
8037+
- name: db.system.name
8038+
type: STRING
8039+
- name: network.peer.address
8040+
type: STRING
8041+
- name: network.peer.port
8042+
type: LONG
8043+
- name: server.address
8044+
type: STRING
8045+
- name: server.port
8046+
type: LONG
8047+
spans:
8048+
- span_kind: CLIENT
8049+
attributes:
8050+
- name: db.query.text
8051+
type: STRING
8052+
- name: db.system.name
8053+
type: STRING
8054+
- name: error
8055+
type: STRING
8056+
- name: network.peer.address
8057+
type: STRING
8058+
- name: network.peer.port
8059+
type: LONG
8060+
- name: network.type
8061+
type: STRING
8062+
- name: server.address
8063+
type: STRING
8064+
- name: server.port
8065+
type: LONG
78268066
liberty:
78278067
- name: liberty-20.0
78288068
source_path: instrumentation/liberty/liberty-20.0

instrumentation-docs/instrumentations.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,14 @@ readonly INSTRUMENTATIONS=(
157157
"ktor:ktor-3.0:library:test"
158158
"kubernetes-client-7.0:javaagent:test"
159159
"kubernetes-client-7.0:javaagent:testExperimental"
160+
"lettuce:lettuce-4.0:javaagent:test"
161+
"lettuce:lettuce-4.0:javaagent:testExperimental"
162+
"lettuce:lettuce-4.0:javaagent:testStableSemconv"
163+
"lettuce:lettuce-5.0:javaagent:test"
164+
"lettuce:lettuce-5.0:javaagent:testExperimental"
165+
"lettuce:lettuce-5.0:javaagent:testStableSemconv"
166+
"lettuce:lettuce-5.1:javaagent:test"
167+
"lettuce:lettuce-5.1:javaagent:testStableSemconv"
160168
"nats:nats-2.17:javaagent:test"
161169
"nats:nats-2.17:javaagent:testExperimental"
162170
"netty:netty-3.8:javaagent:test"

instrumentation/lettuce/lettuce-4.0/javaagent/build.gradle.kts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,27 @@ dependencies {
2222

2323
tasks {
2424
withType<Test>().configureEach {
25-
// TODO run tests both with and without experimental span attributes and span events
26-
jvmArgs("-Dotel.instrumentation.lettuce.experimental-span-attributes=true")
2725
jvmArgs("-Dotel.instrumentation.lettuce.connection-telemetry.enabled=true")
28-
jvmArgs("-Dotel.instrumentation.lettuce.experimental.command-encoding-events.enabled=true")
2926
usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service)
27+
systemProperty("collectMetadata", findProperty("collectMetadata")?.toString() ?: "false")
28+
}
29+
30+
val testExperimental by registering(Test::class) {
31+
testClassesDirs = sourceSets.test.get().output.classesDirs
32+
classpath = sourceSets.test.get().runtimeClasspath
33+
34+
jvmArgs("-Dotel.instrumentation.lettuce.experimental-span-attributes=true")
35+
systemProperty("metadataConfig", "otel.instrumentation.lettuce.experimental-span-attributes=true")
3036
}
3137

3238
val testStableSemconv by registering(Test::class) {
3339
testClassesDirs = sourceSets.test.get().output.classesDirs
3440
classpath = sourceSets.test.get().runtimeClasspath
3541
jvmArgs("-Dotel.semconv-stability.opt-in=database")
42+
systemProperty("metadataConfig", "otel.semconv-stability.opt-in=database")
3643
}
3744

3845
check {
39-
dependsOn(testStableSemconv)
46+
dependsOn(testStableSemconv, testExperimental)
4047
}
4148
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.javaagent.instrumentation.lettuce.v4_0;
7+
8+
import javax.annotation.Nullable;
9+
10+
class ExperimentalHelper {
11+
12+
private static final boolean EXPERIMENTAL_ATTRIBUTES_ENABLED =
13+
Boolean.getBoolean("otel.instrumentation.lettuce.experimental-span-attributes");
14+
15+
@Nullable
16+
static <T> T experimental(T value) {
17+
return EXPERIMENTAL_ATTRIBUTES_ENABLED ? value : null;
18+
}
19+
20+
private ExperimentalHelper() {}
21+
}

instrumentation/lettuce/lettuce-4.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/lettuce/v4_0/LettuceAsyncClientTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import static io.opentelemetry.api.common.AttributeKey.booleanKey;
99
import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable;
10+
import static io.opentelemetry.javaagent.instrumentation.lettuce.v4_0.ExperimentalHelper.experimental;
1011
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
1112
import static io.opentelemetry.semconv.ErrorAttributes.ERROR_TYPE;
1213
import static io.opentelemetry.semconv.ServerAttributes.SERVER_ADDRESS;
@@ -476,7 +477,7 @@ void testCommandBeforeItFinished() {
476477
.hasAttributesSatisfyingExactly(
477478
equalTo(maybeStable(DB_SYSTEM), "redis"),
478479
equalTo(maybeStable(DB_OPERATION), "SADD"),
479-
equalTo(booleanKey("lettuce.command.cancelled"), true)),
480+
equalTo(booleanKey("lettuce.command.cancelled"), experimental(true))),
480481
span ->
481482
span.hasName("callback")
482483
.hasKind(SpanKind.INTERNAL)

instrumentation/lettuce/lettuce-4.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/lettuce/v4_0/LettuceSyncClientTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55

66
package io.opentelemetry.javaagent.instrumentation.lettuce.v4_0;
77

8+
import static io.opentelemetry.instrumentation.testing.junit.db.DbClientMetricsTestUtil.assertDurationMetric;
89
import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable;
910
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
11+
import static io.opentelemetry.semconv.DbAttributes.DB_OPERATION_NAME;
12+
import static io.opentelemetry.semconv.DbAttributes.DB_SYSTEM_NAME;
1013
import static io.opentelemetry.semconv.ServerAttributes.SERVER_ADDRESS;
1114
import static io.opentelemetry.semconv.ServerAttributes.SERVER_PORT;
1215
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_OPERATION;
@@ -43,7 +46,7 @@ class LettuceSyncClientTest {
4346
private static final Logger logger = LoggerFactory.getLogger(LettuceSyncClientTest.class);
4447

4548
@RegisterExtension
46-
protected static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
49+
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
4750

4851
@RegisterExtension static final AutoCleanupExtension cleanup = AutoCleanupExtension.create();
4952

@@ -169,6 +172,9 @@ void testSetCommand() {
169172
.hasAttributesSatisfyingExactly(
170173
equalTo(maybeStable(DB_SYSTEM), "redis"),
171174
equalTo(maybeStable(DB_OPERATION), "SET"))));
175+
176+
assertDurationMetric(
177+
testing, "io.opentelemetry.lettuce-4.0", DB_SYSTEM_NAME, DB_OPERATION_NAME);
172178
}
173179

174180
@Test

0 commit comments

Comments
 (0)