Skip to content

Commit 85254c9

Browse files
committed
Prefactor DbInfo
1 parent aa5cf64 commit 85254c9

30 files changed

+2798
-1294
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ static <REQUEST, RESPONSE> void onStartCommon(
109109
if (emitOldDatabaseSemconv()) {
110110
attributes.put(DB_SYSTEM, getter.getDbSystem(request));
111111
attributes.put(DB_USER, getter.getUser(request));
112-
attributes.put(DB_NAME, getter.getDbNamespace(request));
112+
attributes.put(DB_NAME, getter.getDbName(request));
113113
attributes.put(DB_CONNECTION_STRING, getter.getConnectionString(request));
114114
attributes.put(DB_STATEMENT, getter.getDbQueryText(request));
115115
attributes.put(DB_OPERATION, getter.getDbOperationName(request));

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ default String getDbSystem(REQUEST request) {
5555
@Nullable
5656
String getDbNamespace(REQUEST request);
5757

58+
/**
59+
* Returns the old db.name value. This is only used for old semantic conventions.
60+
*
61+
* @deprecated Use {@link #getDbNamespace(Object)} instead.
62+
*/
63+
@Deprecated // to be removed in 3.0
64+
@Nullable
65+
default String getDbName(REQUEST request) {
66+
return getDbNamespace(request);
67+
}
68+
5869
/**
5970
* Returns the database user name. This is only used for old semantic conventions.
6071
*

instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/DataSourceDbAttributesExtractor.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,14 @@ public void onEnd(
4444
return;
4545
}
4646
if (emitStableDatabaseSemconv()) {
47-
attributes.put(DB_NAMESPACE, getName(dbInfo));
48-
attributes.put(DB_SYSTEM_NAME, SemconvStability.stableDbSystemName(dbInfo.getSystem()));
47+
attributes.put(DB_NAMESPACE, dbInfo.getDbNamespace());
48+
attributes.put(DB_SYSTEM_NAME, SemconvStability.stableDbSystemName(dbInfo.getDbSystemName()));
4949
}
5050
if (emitOldDatabaseSemconv()) {
51-
attributes.put(DB_USER, dbInfo.getUser());
52-
attributes.put(DB_NAME, getName(dbInfo));
53-
attributes.put(DB_CONNECTION_STRING, dbInfo.getShortUrl());
54-
attributes.put(DB_SYSTEM, dbInfo.getSystem());
51+
attributes.put(DB_USER, dbInfo.getDbUser());
52+
attributes.put(DB_NAME, dbInfo.getDbName());
53+
attributes.put(DB_CONNECTION_STRING, dbInfo.getDbConnectionString());
54+
attributes.put(DB_SYSTEM, dbInfo.getDbSystem());
5555
}
5656
}
57-
58-
private static String getName(DbInfo dbInfo) {
59-
return dbInfo.getName();
60-
}
6157
}

instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/JdbcAttributesGetter.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,42 @@ public final class JdbcAttributesGetter implements SqlClientAttributesGetter<DbR
1919

2020
public static final JdbcAttributesGetter INSTANCE = new JdbcAttributesGetter();
2121

22-
@Nullable
2322
@Override
2423
public String getDbSystemName(DbRequest request) {
25-
return request.getDbInfo().getSystem();
24+
return request.getDbInfo().getDbSystemName();
25+
}
26+
27+
@Deprecated // to be removed in 3.0
28+
@Override
29+
public String getDbSystem(DbRequest request) {
30+
return request.getDbInfo().getDbSystem();
2631
}
2732

2833
@Deprecated // to be removed in 3.0
2934
@Nullable
3035
@Override
3136
public String getUser(DbRequest request) {
32-
return request.getDbInfo().getUser();
37+
return request.getDbInfo().getDbUser();
3338
}
3439

3540
@Nullable
3641
@Override
3742
public String getDbNamespace(DbRequest request) {
38-
return request.getDbInfo().getName();
43+
return request.getDbInfo().getDbNamespace();
44+
}
45+
46+
@Deprecated // to be removed in 3.0
47+
@Nullable
48+
@Override
49+
public String getDbName(DbRequest request) {
50+
return request.getDbInfo().getDbName();
3951
}
4052

4153
@Deprecated // to be removed in 3.0
4254
@Nullable
4355
@Override
4456
public String getConnectionString(DbRequest request) {
45-
return request.getDbInfo().getShortUrl();
57+
return request.getDbInfo().getDbConnectionString();
4658
}
4759

4860
@Override
@@ -77,12 +89,12 @@ public boolean isParameterizedQuery(DbRequest request) {
7789
@Nullable
7890
@Override
7991
public String getServerAddress(DbRequest request) {
80-
return request.getDbInfo().getHost();
92+
return request.getDbInfo().getServerAddress();
8193
}
8294

8395
@Nullable
8496
@Override
8597
public Integer getServerPort(DbRequest request) {
86-
return request.getDbInfo().getPort();
98+
return request.getDbInfo().getServerPort();
8799
}
88100
}

0 commit comments

Comments
 (0)