Skip to content

Commit 76e277b

Browse files
committed
Reduce diffs
1 parent a17b1d2 commit 76e277b

File tree

2 files changed

+16
-46
lines changed

2 files changed

+16
-46
lines changed

instrumentation-api-incubator/src/test/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientAttributesExtractorTest.java

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@
88
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
99
import static org.assertj.core.api.Assertions.entry;
1010

11-
import io.opentelemetry.api.common.AttributeKey;
1211
import io.opentelemetry.api.common.Attributes;
1312
import io.opentelemetry.api.common.AttributesBuilder;
1413
import io.opentelemetry.context.Context;
1514
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
16-
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
1715
import io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil;
1816
import io.opentelemetry.semconv.incubating.DbIncubatingAttributes;
1917
import java.util.Collections;
@@ -37,8 +35,7 @@ public String getUser(Map<String, String> map) {
3735

3836
@Override
3937
public String getDbNamespace(Map<String, String> map) {
40-
return map.get(
41-
SemconvStabilityUtil.getAttributeKey(AttributeKey.stringKey("db.name")).getKey());
38+
return map.get("db.name");
4239
}
4340

4441
@Deprecated
@@ -49,14 +46,12 @@ public String getConnectionString(Map<String, String> map) {
4946

5047
@Override
5148
public String getDbQueryText(Map<String, String> map) {
52-
return map.get(
53-
SemconvStabilityUtil.getAttributeKey(AttributeKey.stringKey("db.statement")).getKey());
49+
return map.get("db.statement");
5450
}
5551

5652
@Override
5753
public String getDbOperationName(Map<String, String> map) {
58-
return map.get(
59-
SemconvStabilityUtil.getAttributeKey(AttributeKey.stringKey("db.operation")).getKey());
54+
return map.get("db.operation");
6055
}
6156
}
6257

@@ -66,18 +61,11 @@ void shouldExtractAllAvailableAttributes() {
6661
// given
6762
Map<String, String> request = new HashMap<>();
6863
request.put("db.system", "myDb");
69-
if (SemconvStability.emitOldDatabaseSemconv()) {
70-
request.put("db.user", "username");
71-
request.put("db.connection_string", "mydb:///potatoes");
72-
}
73-
request.put(
74-
SemconvStabilityUtil.getAttributeKey(DbIncubatingAttributes.DB_NAME).getKey(), "potatoes");
75-
request.put(
76-
SemconvStabilityUtil.getAttributeKey(DbIncubatingAttributes.DB_STATEMENT).getKey(),
77-
"SELECT * FROM potato");
78-
request.put(
79-
SemconvStabilityUtil.getAttributeKey(DbIncubatingAttributes.DB_OPERATION).getKey(),
80-
"SELECT");
64+
request.put("db.user", "username");
65+
request.put("db.name", "potatoes");
66+
request.put("db.connection_string", "mydb:///potatoes");
67+
request.put("db.statement", "SELECT * FROM potato");
68+
request.put("db.operation", "SELECT");
8169

8270
Context context = Context.root();
8371

instrumentation-api-incubator/src/test/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/SqlClientAttributesExtractorTest.java

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
99
import static org.assertj.core.api.Assertions.entry;
1010

11-
import io.opentelemetry.api.common.AttributeKey;
1211
import io.opentelemetry.api.common.Attributes;
1312
import io.opentelemetry.api.common.AttributesBuilder;
1413
import io.opentelemetry.context.Context;
@@ -28,8 +27,7 @@ static final class TestAttributesGetter
2827

2928
@Override
3029
public String getRawQueryText(Map<String, String> map) {
31-
return map.get(
32-
SemconvStabilityUtil.getAttributeKey(AttributeKey.stringKey("db.statement")).getKey());
30+
return map.get("db.statement");
3331
}
3432

3533
@Override
@@ -45,8 +43,7 @@ public String getUser(Map<String, String> map) {
4543

4644
@Override
4745
public String getDbNamespace(Map<String, String> map) {
48-
return map.get(
49-
SemconvStabilityUtil.getAttributeKey(AttributeKey.stringKey("db.name")).getKey());
46+
return map.get("db.name");
5047
}
5148

5249
@Deprecated
@@ -62,15 +59,10 @@ void shouldExtractAllAttributes() {
6259
// given
6360
Map<String, String> request = new HashMap<>();
6461
request.put("db.system", "myDb");
65-
if (SemconvStability.emitOldDatabaseSemconv()) {
66-
request.put("db.user", "username");
67-
request.put("db.connection_string", "mydb:///potatoes");
68-
request.put("db.name", "potatoes");
69-
request.put("db.statement", "SELECT * FROM potato WHERE id=12345");
70-
} else if (SemconvStability.emitStableDatabaseSemconv()) {
71-
request.put("db.namespace", "potatoes");
72-
request.put("db.query.text", "SELECT * FROM potato WHERE id=12345");
73-
}
62+
request.put("db.user", "username");
63+
request.put("db.name", "potatoes");
64+
request.put("db.connection_string", "mydb:///potatoes");
65+
request.put("db.statement", "SELECT * FROM potato WHERE id=12345");
7466

7567
Context context = Context.root();
7668

@@ -119,11 +111,7 @@ void shouldExtractAllAttributes() {
119111
void shouldNotExtractTableIfAttributeIsNotSet() {
120112
// given
121113
Map<String, String> request = new HashMap<>();
122-
if (SemconvStability.emitOldDatabaseSemconv()) {
123-
request.put("db.statement", "SELECT *");
124-
} else {
125-
request.put("db.query.text", "SELECT *");
126-
}
114+
request.put("db.statement", "SELECT *");
127115

128116
Context context = Context.root();
129117

@@ -149,13 +137,7 @@ void shouldNotExtractTableIfAttributeIsNotSet() {
149137
void shouldExtractTableToSpecifiedKey() {
150138
// given
151139
Map<String, String> request = new HashMap<>();
152-
if (SemconvStability.emitOldDatabaseSemconv()) {
153-
request.put("db.statement", "SELECT * FROM table");
154-
}
155-
156-
if (SemconvStability.emitStableDatabaseSemconv()) {
157-
request.put("db.query.text", "SELECT * FROM table");
158-
}
140+
request.put("db.statement", "SELECT * FROM table");
159141

160142
Context context = Context.root();
161143

0 commit comments

Comments
 (0)