Skip to content

Commit 236dab3

Browse files
committed
Rename getDbSystem and getResponseStatus to getDbSystemName and getResponseStatusCode
1 parent 82942c2 commit 236dab3

File tree

30 files changed

+83
-38
lines changed

30 files changed

+83
-38
lines changed

instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientAttributesExtractor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static <REQUEST, RESPONSE> void onStartCommon(
7777
internalSet(
7878
attributes,
7979
DB_SYSTEM_NAME,
80-
SemconvStability.stableDbSystemName(getter.getDbSystem(request)));
80+
SemconvStability.stableDbSystemName(getter.getDbSystemName(request)));
8181
internalSet(attributes, DB_NAMESPACE, getter.getDbNamespace(request));
8282
internalSet(attributes, DB_QUERY_TEXT, getter.getDbQueryText(request));
8383
internalSet(attributes, DB_OPERATION_NAME, getter.getDbOperationName(request));
@@ -114,7 +114,8 @@ static <REQUEST, RESPONSE> void onEndCommon(
114114
internalSet(attributes, ERROR_TYPE, error.getClass().getName());
115115
}
116116
if (error != null || response != null) {
117-
internalSet(attributes, DB_RESPONSE_STATUS_CODE, getter.getResponseStatus(response, error));
117+
internalSet(
118+
attributes, DB_RESPONSE_STATUS_CODE, getter.getResponseStatusCode(response, error));
118119
}
119120
}
120121
}

instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientAttributesGetter.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,31 @@ default String getOperation(REQUEST request) {
6161
default String getDbOperationName(REQUEST request) {
6262
return getOperation(request);
6363
}
64+
65+
// TODO: make this required to implement
66+
default String getDbSystemName(REQUEST request) {
67+
String dbSystem = getDbSystem(request);
68+
if (dbSystem == null) {
69+
throw new UnsupportedOperationException(
70+
"Must override getDbSystemName() or getDbSystem() (deprecated)");
71+
}
72+
return dbSystem;
73+
}
74+
75+
/**
76+
* @deprecated Use {@link #getDbSystemName} instead.
77+
*/
78+
@Deprecated
79+
@Nullable
80+
default String getDbSystem(REQUEST request) {
81+
// overriding in order to provide a default implementation temporarily,
82+
// so subclasses don't need to override this method
83+
return null;
84+
}
85+
86+
// TODO: make this required to implement
87+
@Nullable
88+
default String getResponseStatusCode(@Nullable RESPONSE response, @Nullable Throwable error) {
89+
return getResponseStatus(response, error);
90+
}
6491
}

instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientCommonAttributesGetter.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,40 @@
1515
@Deprecated
1616
public interface DbClientCommonAttributesGetter<REQUEST, RESPONSE> {
1717

18+
/**
19+
* @deprecated Use {@link DbClientAttributesGetter#getDbSystemName} instead.
20+
*/
21+
@Deprecated
22+
@Nullable
1823
String getDbSystem(REQUEST request);
1924

25+
/**
26+
* @deprecated There is no replacement at this time.
27+
*/
2028
@Deprecated
2129
@Nullable
2230
default String getUser(REQUEST request) {
2331
return null;
2432
}
2533

2634
@Nullable
27-
String getDbNamespace(REQUEST request);
35+
default String getDbNamespace(REQUEST request) {
36+
return null;
37+
}
2838

39+
/**
40+
* @deprecated There is no replacement at this time.
41+
*/
2942
@Deprecated
3043
@Nullable
3144
default String getConnectionString(REQUEST request) {
3245
return null;
3346
}
3447

48+
/**
49+
* @deprecated Use {@link DbClientAttributesGetter#getResponseStatusCode} instead.
50+
*/
51+
@Deprecated
3552
@Nullable
3653
default String getResponseStatus(@Nullable RESPONSE response, @Nullable Throwable error) {
3754
return null;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class DbClientAttributesExtractorTest {
2626
static final class TestAttributesGetter
2727
implements DbClientAttributesGetter<Map<String, String>, Void> {
2828
@Override
29-
public String getDbSystem(Map<String, String> map) {
29+
public String getDbSystemName(Map<String, String> map) {
3030
return map.get("db.system");
3131
}
3232

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public Collection<String> getRawQueryTexts(Map<String, Object> map) {
3939
}
4040

4141
@Override
42-
public String getDbSystem(Map<String, Object> map) {
42+
public String getDbSystemName(Map<String, Object> map) {
4343
return read(map, "db.system");
4444
}
4545

instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/internal/InstrumenterContextTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void testSqlSanitizer() {
3535
SqlClientAttributesGetter<Object, Void> getter =
3636
new SqlClientAttributesGetter<Object, Void>() {
3737
@Override
38-
public String getDbSystem(Object o) {
38+
public String getDbSystemName(Object o) {
3939
return "testdb";
4040
}
4141

instrumentation/cassandra/cassandra-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v3_0/CassandraSqlAttributesGetter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ final class CassandraSqlAttributesGetter
1919

2020
@SuppressWarnings("deprecation") // using deprecated DbSystemIncubatingValues
2121
@Override
22-
public String getDbSystem(CassandraRequest request) {
22+
public String getDbSystemName(CassandraRequest request) {
2323
return DbIncubatingAttributes.DbSystemIncubatingValues.CASSANDRA;
2424
}
2525

instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraSqlAttributesGetter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ final class CassandraSqlAttributesGetter
2222

2323
@SuppressWarnings("deprecation") // using deprecated DbSystemIncubatingValues
2424
@Override
25-
public String getDbSystem(CassandraRequest request) {
25+
public String getDbSystemName(CassandraRequest request) {
2626
return DbIncubatingAttributes.DbSystemIncubatingValues.CASSANDRA;
2727
}
2828

instrumentation/cassandra/cassandra-4.4/library/src/main/java/io/opentelemetry/instrumentation/cassandra/v4_4/CassandraSqlAttributesGetter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ final class CassandraSqlAttributesGetter
2323
private static final String CASSANDRA = "cassandra";
2424

2525
@Override
26-
public String getDbSystem(CassandraRequest request) {
26+
public String getDbSystemName(CassandraRequest request) {
2727
return CASSANDRA;
2828
}
2929

instrumentation/clickhouse/clickhouse-client-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/clickhouse/common/ClickHouseAttributesGetter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public String getDbOperationName(ClickHouseDbRequest request) {
3939

4040
@SuppressWarnings("deprecation") // using deprecated DbSystemIncubatingValues
4141
@Override
42-
public String getDbSystem(ClickHouseDbRequest request) {
42+
public String getDbSystemName(ClickHouseDbRequest request) {
4343
return DbIncubatingAttributes.DbSystemIncubatingValues.CLICKHOUSE;
4444
}
4545

@@ -55,7 +55,7 @@ public String getDbNamespace(ClickHouseDbRequest request) {
5555

5656
@Nullable
5757
@Override
58-
public String getResponseStatus(@Nullable Void response, @Nullable Throwable error) {
58+
public String getResponseStatusCode(@Nullable Void response, @Nullable Throwable error) {
5959
return errorCodeExtractor.apply(error);
6060
}
6161
}

0 commit comments

Comments
 (0)