Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ void shouldUseQuerySummaryWhenAvailable() {
// given
DbRequest dbRequest = new DbRequest();

// Needs to be lenient because not called during this test under old semconv mode
if (emitStableDatabaseSemconv()) {
when(dbAttributesGetter.getDbQuerySummary(dbRequest)).thenReturn("SELECT users");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,14 @@ public void onEnd(
return;
}
if (emitStableDatabaseSemconv()) {
attributes.put(DB_NAMESPACE, getName(dbInfo));
attributes.put(DB_SYSTEM_NAME, SemconvStability.stableDbSystemName(dbInfo.getSystem()));
attributes.put(DB_NAMESPACE, dbInfo.getDbNamespace());
attributes.put(DB_SYSTEM_NAME, SemconvStability.stableDbSystemName(dbInfo.getDbSystemName()));
}
if (emitOldDatabaseSemconv()) {
attributes.put(DB_USER, dbInfo.getUser());
attributes.put(DB_NAME, getName(dbInfo));
attributes.put(DB_CONNECTION_STRING, dbInfo.getShortUrl());
attributes.put(DB_SYSTEM, dbInfo.getSystem());
attributes.put(DB_USER, dbInfo.getDbUser());
attributes.put(DB_NAME, dbInfo.getDbName());
attributes.put(DB_CONNECTION_STRING, dbInfo.getDbConnectionString());
attributes.put(DB_SYSTEM, dbInfo.getDbSystem());
}
}

private static String getName(DbInfo dbInfo) {
return dbInfo.getName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public final class JdbcAttributesGetter implements SqlClientAttributesGetter<DbRequest, Void> {

// Databases where double quotes are exclusively identifiers and cannot be string literals.
private static final Set<String> DOUBLE_QUOTES_FOR_IDENTIFIERS_SYSTEMS =
private static final Set<String> DOUBLE_QUOTES_FOR_IDENTIFIERS_SYSTEM_NAMES =
new HashSet<>(
asList(
// "A string constant in SQL is an arbitrary sequence of characters
Expand All @@ -35,11 +35,11 @@ public final class JdbcAttributesGetter implements SqlClientAttributesGetter<DbR
// "Text, character, and string literals are always surrounded
// by single quotation marks."
// https://docs.oracle.com/en/database/oracle/oracle-database/23/sqlrf/Literals.html
"oracle",
"oracle.db",
// "A sequence of characters that starts and ends with a string delimiter,
// which is an apostrophe (')"
// https://www.ibm.com/docs/en/db2/12.1?topic=elements-constants
"db2",
"ibm.db2",
// "Single quotation marks delimit character strings."
// "Double quotation marks delimit special identifiers"
// https://db.apache.org/derby/docs/10.17/ref/rrefsqlj28468.html
Expand All @@ -51,44 +51,56 @@ public final class JdbcAttributesGetter implements SqlClientAttributesGetter<DbR
// <string_literal> ::= <single_quote>[<any_character>...]<single_quote>
// <special_identifier> ::= <double_quotes><any_character>...<double_quotes>
// https://help.sap.com/docs/hana-cloud-database/sap-hana-cloud-sap-hana-database-sql-reference-guide/sql-notation-conventions
"hanadb",
"sap.hana",
// "String literals must be enclosed in single quotes.
// Double quotes are not supported."
// https://clickhouse.com/docs/en/sql-reference/syntax#string
"clickhouse",
// PostgreSQL-compatible fork, inherits PG string literal rules
"polardb"));

@Nullable
@Override
public String getDbSystemName(DbRequest request) {
return request.getDbInfo().getSystem();
return request.getDbInfo().getDbSystemName();
}

@Deprecated // to be removed in 3.0
@Override
public String getDbSystem(DbRequest request) {
return request.getDbInfo().getDbSystem();
}

@Deprecated // to be removed in 3.0
@Nullable
@Override
public String getUser(DbRequest request) {
return request.getDbInfo().getUser();
return request.getDbInfo().getDbUser();
}

@Nullable
@Override
public String getDbNamespace(DbRequest request) {
return request.getDbInfo().getName();
return request.getDbInfo().getDbNamespace();
}

@Deprecated // to be removed in 3.0
@Nullable
@Override
public String getDbName(DbRequest request) {
return request.getDbInfo().getDbName();
}

@Deprecated // to be removed in 3.0
@Nullable
@Override
public String getConnectionString(DbRequest request) {
return request.getDbInfo().getShortUrl();
return request.getDbInfo().getDbConnectionString();
}

@Override
public SqlDialect getSqlDialect(DbRequest request) {
String system = request.getDbInfo().getSystem();
if (system != null && DOUBLE_QUOTES_FOR_IDENTIFIERS_SYSTEMS.contains(system)) {
String systemName = request.getDbInfo().getDbSystemName();
if (systemName != null && DOUBLE_QUOTES_FOR_IDENTIFIERS_SYSTEM_NAMES.contains(systemName)) {
return DOUBLE_QUOTES_ARE_IDENTIFIERS;
}
// default to treating double-quoted tokens as string literals for safety, ensuring that
Expand Down Expand Up @@ -129,12 +141,12 @@ public boolean isParameterizedQuery(DbRequest request) {
@Nullable
@Override
public String getServerAddress(DbRequest request) {
return request.getDbInfo().getHost();
return request.getDbInfo().getServerAddress();
}

@Nullable
@Override
public Integer getServerPort(DbRequest request) {
return request.getDbInfo().getPort();
return request.getDbInfo().getServerPort();
}
}
Loading
Loading