Skip to content

Commit fc4f525

Browse files
authored
Couchbase metadata (#14466)
1 parent a549527 commit fc4f525

File tree

23 files changed

+480
-61
lines changed

23 files changed

+480
-61
lines changed

docs/instrumentation-list.yaml

Lines changed: 117 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2082,19 +2082,52 @@ libraries:
20822082
type: LONG
20832083
couchbase:
20842084
- name: couchbase-2.0
2085+
description: |
2086+
This instrumentation enables database CLIENT spans and metrics for Couchbase 2.0 operations. It automatically traces key-value operations (get, upsert, replace, remove), view queries, N1QL queries, and cluster management operations.
20852087
source_path: instrumentation/couchbase/couchbase-2.0
20862088
scope:
20872089
name: io.opentelemetry.couchbase-2.0
20882090
target_versions:
20892091
javaagent:
20902092
- com.couchbase.client:java-client:[2,3)
2091-
configurations:
2092-
- name: otel.instrumentation.couchbase.experimental-span-attributes
2093-
description: Enables experimental span attributes `couchbase.operation_id` and
2094-
`couchbase.local.address`
2095-
type: boolean
2096-
default: false
2093+
telemetry:
2094+
- when: default
2095+
spans:
2096+
- span_kind: CLIENT
2097+
attributes:
2098+
- name: db.name
2099+
type: STRING
2100+
- name: db.operation
2101+
type: STRING
2102+
- name: db.statement
2103+
type: STRING
2104+
- name: db.system
2105+
type: STRING
2106+
- when: otel.semconv-stability.opt-in=database
2107+
metrics:
2108+
- name: db.client.operation.duration
2109+
description: Duration of database client operations.
2110+
type: HISTOGRAM
2111+
unit: s
2112+
attributes:
2113+
- name: db.operation.name
2114+
type: STRING
2115+
- name: db.system.name
2116+
type: STRING
2117+
spans:
2118+
- span_kind: CLIENT
2119+
attributes:
2120+
- name: db.namespace
2121+
type: STRING
2122+
- name: db.operation.name
2123+
type: STRING
2124+
- name: db.query.text
2125+
type: STRING
2126+
- name: db.system.name
2127+
type: STRING
20972128
- name: couchbase-2.6
2129+
description: |
2130+
This instrumentation enables database CLIENT spans and metrics for Couchbase 2.6 operations. It automatically traces key-value operations (get, upsert, replace, remove), view queries, N1QL queries, and cluster management operations.
20982131
source_path: instrumentation/couchbase/couchbase-2.6
20992132
scope:
21002133
name: io.opentelemetry.couchbase-2.6
@@ -2103,13 +2136,86 @@ libraries:
21032136
- com.couchbase.client:java-client:[2.6.0,3)
21042137
configurations:
21052138
- name: otel.instrumentation.couchbase.experimental-span-attributes
2106-
description: Enables experimental span attributes couchbase.operation_id and
2107-
couchbase.local.address
2139+
description: |
2140+
Enables experimental span attributes `couchbase.operation_id` and `couchbase.local.address`. Different operation types receive different experimental attributes.
21082141
type: boolean
21092142
default: false
2143+
telemetry:
2144+
- when: default
2145+
spans:
2146+
- span_kind: CLIENT
2147+
attributes:
2148+
- name: db.name
2149+
type: STRING
2150+
- name: db.operation
2151+
type: STRING
2152+
- name: db.statement
2153+
type: STRING
2154+
- name: db.system
2155+
type: STRING
2156+
- name: network.peer.address
2157+
type: STRING
2158+
- name: network.peer.port
2159+
type: LONG
2160+
- name: network.type
2161+
type: STRING
2162+
- when: otel.instrumentation.couchbase.experimental-span-attributes=true
2163+
spans:
2164+
- span_kind: CLIENT
2165+
attributes:
2166+
- name: couchbase.local.address
2167+
type: STRING
2168+
- name: couchbase.operation_id
2169+
type: STRING
2170+
- name: db.name
2171+
type: STRING
2172+
- name: db.operation
2173+
type: STRING
2174+
- name: db.statement
2175+
type: STRING
2176+
- name: db.system
2177+
type: STRING
2178+
- name: network.peer.address
2179+
type: STRING
2180+
- name: network.peer.port
2181+
type: LONG
2182+
- name: network.type
2183+
type: STRING
2184+
- when: otel.semconv-stability.opt-in=database
2185+
metrics:
2186+
- name: db.client.operation.duration
2187+
description: Duration of database client operations.
2188+
type: HISTOGRAM
2189+
unit: s
2190+
attributes:
2191+
- name: db.operation.name
2192+
type: STRING
2193+
- name: db.system.name
2194+
type: STRING
2195+
- name: network.peer.address
2196+
type: STRING
2197+
- name: network.peer.port
2198+
type: LONG
2199+
spans:
2200+
- span_kind: CLIENT
2201+
attributes:
2202+
- name: db.namespace
2203+
type: STRING
2204+
- name: db.operation.name
2205+
type: STRING
2206+
- name: db.query.text
2207+
type: STRING
2208+
- name: db.system.name
2209+
type: STRING
2210+
- name: network.peer.address
2211+
type: STRING
2212+
- name: network.peer.port
2213+
type: LONG
2214+
- name: network.type
2215+
type: STRING
21102216
- name: couchbase-3.1
21112217
description: |
2112-
Couchbase instrumentation is owned by the Couchbase project. This instrumentation automatically configures the instrumentation provided by the Couchbase library.
2218+
Couchbase instrumentation is owned by the Couchbase project for versions 3+. This instrumentation automatically configures the instrumentation provided by the Couchbase library.
21132219
source_path: instrumentation/couchbase/couchbase-3.1
21142220
scope:
21152221
name: io.opentelemetry.couchbase-3.1
@@ -2118,7 +2224,7 @@ libraries:
21182224
- com.couchbase.client:java-client:[3.1,3.1.6)
21192225
- name: couchbase-3.1.6
21202226
description: |
2121-
Couchbase instrumentation is owned by the Couchbase project. This instrumentation automatically configures the instrumentation provided by the Couchbase library.
2227+
Couchbase instrumentation is owned by the Couchbase project for versions 3+. This instrumentation automatically configures the instrumentation provided by the Couchbase library.
21222228
source_path: instrumentation/couchbase/couchbase-3.1.6
21232229
scope:
21242230
name: io.opentelemetry.couchbase-3.1.6
@@ -2127,7 +2233,7 @@ libraries:
21272233
- com.couchbase.client:java-client:[3.1.6,3.2.0)
21282234
- name: couchbase-3.2
21292235
description: |
2130-
Couchbase instrumentation is owned by the Couchbase project. This instrumentation automatically configures the instrumentation provided by the Couchbase library.
2236+
Couchbase instrumentation is owned by the Couchbase project for versions 3+. This instrumentation automatically configures the instrumentation provided by the Couchbase library.
21312237
source_path: instrumentation/couchbase/couchbase-3.2
21322238
scope:
21332239
name: io.opentelemetry.couchbase-3.2

instrumentation-docs/instrumentations.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ readonly INSTRUMENTATIONS=(
125125
"camel-2.20:javaagent:test"
126126
"camel-2.20:javaagent:testStableSemconv"
127127
"camel-2.20:javaagent:testExperimental"
128+
"couchbase:couchbase-2.0:javaagent:test"
129+
"couchbase:couchbase-2.0:javaagent:testStableSemconv"
130+
"couchbase:couchbase-2.6:javaagent:test"
131+
"couchbase:couchbase-2.6:javaagent:testStableSemconv"
132+
"couchbase:couchbase-2.6:javaagent:testExperimental"
128133
)
129134

130135
# Some instrumentation test suites don't run ARM, so we use colima to run them in an x86_64

instrumentation-docs/src/main/java/io/opentelemetry/instrumentation/docs/parsers/TelemetryParser.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ class TelemetryParser {
1212

1313
// Key is the scope of the module being analyzed, value is a set of additional allowed scopes.
1414
private static final Map<String, Set<String>> scopeAllowList =
15-
Map.of("io.opentelemetry.armeria-grpc-1.14", Set.of("io.opentelemetry.grpc-1.6"));
15+
Map.of(
16+
// armeria-grpc uses grpc-1.6 instrumenter.
17+
"io.opentelemetry.armeria-grpc-1.14", Set.of("io.opentelemetry.grpc-1.6"),
18+
// couchbase-2.6 extends couchbase-2.0 instrumentation with more attributes.
19+
"io.opentelemetry.couchbase-2.6", Set.of("io.opentelemetry.couchbase-2.0"));
1620

1721
/**
1822
* Checks if the given telemetry scope is valid for the specified module scope.

instrumentation/couchbase/couchbase-2.0/javaagent/build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,13 @@ tasks {
3636
jvmArgs("--add-opens=java.base/java.lang=ALL-UNNAMED")
3737
jvmArgs("--add-opens=java.base/java.lang.invoke=ALL-UNNAMED")
3838
jvmArgs("-XX:+IgnoreUnrecognizedVMOptions")
39+
40+
systemProperty("collectMetadata", findProperty("collectMetadata")?.toString() ?: "false")
3941
}
4042

4143
val testStableSemconv by registering(Test::class) {
4244
jvmArgs("-Dotel.semconv-stability.opt-in=database")
45+
systemProperty("metadataConfig", "otel.semconv-stability.opt-in=database")
4346
}
4447

4548
check {

instrumentation/couchbase/couchbase-2.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_0/CouchbaseAsyncClientTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import com.couchbase.client.java.cluster.BucketSettings;
99
import com.couchbase.client.java.env.DefaultCouchbaseEnvironment;
1010
import io.opentelemetry.instrumentation.couchbase.AbstractCouchbaseAsyncClientTest;
11+
import io.opentelemetry.sdk.testing.assertj.AttributeAssertion;
12+
import java.util.List;
1113

1214
class CouchbaseAsyncClientTest extends AbstractCouchbaseAsyncClientTest {
1315

@@ -16,4 +18,24 @@ protected DefaultCouchbaseEnvironment.Builder envBuilder(
1618
BucketSettings bucketSettings, int carrierDirectPort, int httpDirectPort) {
1719
return CouchbaseUtil.envBuilder(bucketSettings, carrierDirectPort, httpDirectPort);
1820
}
21+
22+
@Override
23+
protected List<AttributeAssertion> couchbaseAttributes() {
24+
return CouchbaseUtil.couchbaseAttributes();
25+
}
26+
27+
@Override
28+
protected List<AttributeAssertion> couchbaseQueryAttributes() {
29+
return CouchbaseUtil.couchbaseQueryAttributes();
30+
}
31+
32+
@Override
33+
protected List<AttributeAssertion> couchbaseClusterManagerAttributes() {
34+
return CouchbaseUtil.couchbaseClusterManagerAttributes();
35+
}
36+
37+
@Override
38+
protected List<AttributeAssertion> couchbaseN1qlAttributes() {
39+
return CouchbaseUtil.couchbaseN1qlAttributes();
40+
}
1941
}

instrumentation/couchbase/couchbase-2.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_0/CouchbaseClientTest.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,19 @@
55

66
package io.opentelemetry.javaagent.instrumentation.couchbase.v2_0;
77

8+
import static io.opentelemetry.instrumentation.testing.junit.db.DbClientMetricsTestUtil.assertDurationMetric;
9+
import static io.opentelemetry.semconv.DbAttributes.DB_OPERATION_NAME;
10+
import static io.opentelemetry.semconv.DbAttributes.DB_SYSTEM_NAME;
11+
import static org.assertj.core.api.Assertions.assertThat;
12+
13+
import com.couchbase.client.java.CouchbaseCluster;
814
import com.couchbase.client.java.cluster.BucketSettings;
15+
import com.couchbase.client.java.cluster.ClusterManager;
916
import com.couchbase.client.java.env.DefaultCouchbaseEnvironment;
1017
import io.opentelemetry.instrumentation.couchbase.AbstractCouchbaseClientTest;
18+
import io.opentelemetry.sdk.testing.assertj.AttributeAssertion;
19+
import java.util.List;
20+
import org.junit.jupiter.api.Test;
1121

1222
class CouchbaseClientTest extends AbstractCouchbaseClientTest {
1323

@@ -16,4 +26,39 @@ protected DefaultCouchbaseEnvironment.Builder envBuilder(
1626
BucketSettings bucketSettings, int carrierDirectPort, int httpDirectPort) {
1727
return CouchbaseUtil.envBuilder(bucketSettings, carrierDirectPort, httpDirectPort);
1828
}
29+
30+
@Override
31+
protected List<AttributeAssertion> couchbaseAttributes() {
32+
return CouchbaseUtil.couchbaseAttributes();
33+
}
34+
35+
@Override
36+
protected List<AttributeAssertion> couchbaseQueryAttributes() {
37+
return CouchbaseUtil.couchbaseQueryAttributes();
38+
}
39+
40+
@Override
41+
protected List<AttributeAssertion> couchbaseClusterManagerAttributes() {
42+
return CouchbaseUtil.couchbaseClusterManagerAttributes();
43+
}
44+
45+
@Override
46+
protected List<AttributeAssertion> couchbaseN1qlAttributes() {
47+
return CouchbaseUtil.couchbaseN1qlAttributes();
48+
}
49+
50+
@Test
51+
void hasDurationMetric() {
52+
CouchbaseCluster cluster = prepareCluster(bucketCouchbase);
53+
ClusterManager manager = cluster.clusterManager(USERNAME, PASSWORD);
54+
55+
testing.waitForTraces(1);
56+
testing.clearData();
57+
58+
boolean hasBucket = manager.hasBucket(bucketCouchbase.name());
59+
assertThat(hasBucket).isTrue();
60+
61+
assertDurationMetric(
62+
testing, "io.opentelemetry.couchbase-2.0", DB_SYSTEM_NAME, DB_OPERATION_NAME);
63+
}
1964
}

instrumentation/couchbase/couchbase-2.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_0/CouchbaseUtil.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,38 @@
55

66
package io.opentelemetry.javaagent.instrumentation.couchbase.v2_0;
77

8+
import static java.util.Collections.emptyList;
9+
810
import com.couchbase.client.core.metrics.DefaultLatencyMetricsCollectorConfig;
911
import com.couchbase.client.core.metrics.DefaultMetricsCollectorConfig;
1012
import com.couchbase.client.java.cluster.BucketSettings;
1113
import com.couchbase.client.java.env.DefaultCouchbaseEnvironment;
14+
import io.opentelemetry.sdk.testing.assertj.AttributeAssertion;
15+
import java.util.List;
1216
import java.util.concurrent.TimeUnit;
1317

1418
public class CouchbaseUtil {
1519

20+
public static List<AttributeAssertion> couchbaseAttributes() {
21+
return couchbaseKvAttributes();
22+
}
23+
24+
public static List<AttributeAssertion> couchbaseKvAttributes() {
25+
return emptyList();
26+
}
27+
28+
public static List<AttributeAssertion> couchbaseQueryAttributes() {
29+
return emptyList();
30+
}
31+
32+
public static List<AttributeAssertion> couchbaseClusterManagerAttributes() {
33+
return emptyList();
34+
}
35+
36+
public static List<AttributeAssertion> couchbaseN1qlAttributes() {
37+
return emptyList();
38+
}
39+
1640
public static DefaultCouchbaseEnvironment.Builder envBuilder(
1741
BucketSettings bucketSettings, int carrierDirectPort, int httpDirectPort) {
1842
// Couchbase seems to be really slow to start sometimes

instrumentation/couchbase/couchbase-2.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_0/springdata/CouchbaseSpringRepositoryTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import io.opentelemetry.instrumentation.couchbase.springdata.TestDocument;
1212
import io.opentelemetry.instrumentation.couchbase.springdata.TestRepository;
1313
import io.opentelemetry.javaagent.instrumentation.couchbase.v2_0.CouchbaseUtil;
14+
import io.opentelemetry.sdk.testing.assertj.AttributeAssertion;
15+
import java.util.List;
1416

1517
class CouchbaseSpringRepositoryTest extends AbstractCouchbaseSpringRepositoryTest {
1618

@@ -20,6 +22,26 @@ protected DefaultCouchbaseEnvironment.Builder envBuilder(
2022
return CouchbaseUtil.envBuilder(bucketSettings, carrierDirectPort, httpDirectPort);
2123
}
2224

25+
@Override
26+
protected List<AttributeAssertion> couchbaseAttributes() {
27+
return CouchbaseUtil.couchbaseAttributes();
28+
}
29+
30+
@Override
31+
protected List<AttributeAssertion> couchbaseQueryAttributes() {
32+
return CouchbaseUtil.couchbaseQueryAttributes();
33+
}
34+
35+
@Override
36+
protected List<AttributeAssertion> couchbaseClusterManagerAttributes() {
37+
return CouchbaseUtil.couchbaseClusterManagerAttributes();
38+
}
39+
40+
@Override
41+
protected List<AttributeAssertion> couchbaseN1qlAttributes() {
42+
return CouchbaseUtil.couchbaseN1qlAttributes();
43+
}
44+
2345
@Override
2446
protected TestDocument findById(TestRepository repository, String id) {
2547
return repository.findOne(id);

0 commit comments

Comments
 (0)