Skip to content

Commit ccf4871

Browse files
committed
review
1 parent 3fcba47 commit ccf4871

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ private JdbcConnectionUrlParser() {}
107107
*
108108
* @param connectionUrl the JDBC connection URL
109109
* @param props optional connection properties
110-
* @return the parsed DbInfo, or DbInfo.DEFAULT if parsing fails
110+
* @return the parsed DbInfo, or DbInfo.DEFAULT for null/invalid non-JDBC inputs; parser failures
111+
* return the best-effort result accumulated before the failure
111112
*/
112113
public static DbInfo parse(String connectionUrl, Properties props) {
113114
if (connectionUrl == null) {
@@ -129,13 +130,11 @@ public static DbInfo parse(String connectionUrl, Properties props) {
129130
}
130131

131132
String type = jdbcUrl.substring(0, typeLoc);
133+
JdbcUrlParser parser = TYPE_PARSERS.get(type);
134+
ParseContext ctx = ParseContext.of(type, props);
132135

133136
try {
134-
JdbcUrlParser parser = TYPE_PARSERS.get(type);
135-
136-
ParseContext ctx = ParseContext.of(type, props);
137137
if (parser == null) {
138-
// Unknown JDBC type: apply all standard DataSource properties and use generic parser
139138
ctx.applyDataSourceProperties();
140139
GenericUrlParser.INSTANCE.parse(jdbcUrl, ctx);
141140
} else {
@@ -145,7 +144,7 @@ public static DbInfo parse(String connectionUrl, Properties props) {
145144
return ctx.toDbInfo();
146145
} catch (RuntimeException e) {
147146
logger.log(FINE, "Error parsing URL", e);
148-
return DEFAULT;
147+
return ctx.toDbInfo();
149148
}
150149
}
151150

instrumentation/jdbc/library/src/test/java/io/opentelemetry/instrumentation/jdbc/internal/JdbcConnectionUrlParserTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,23 @@ void testNullUrlReturnsDefault() {
6262
assertThat(JdbcConnectionUrlParser.parse(null, null)).isEqualTo(DEFAULT);
6363
}
6464

65+
@Test
66+
void testParserExceptionReturnsBestEffortInfo() {
67+
// Intentionally malformed Oracle URL: missing subtype/connect info, which triggers the
68+
// Oracle parser's substring-based failure path after it has already applied defaults/props.
69+
testVerifySystemSubtypeParsingOfUrl(
70+
arg("jdbc:oracle:")
71+
.setProperties(stdProps())
72+
.setShortUrl("oracle://stdServerName:9999")
73+
.setSystem("oracle.db")
74+
.setOldSystem("oracle")
75+
.setUser("stdUserName")
76+
.setHost("stdServerName")
77+
.setPort(9999)
78+
.setName("stdDatabaseName")
79+
.build());
80+
}
81+
6582
private static Stream<Arguments> mySqlArguments() {
6683
return args(
6784
// https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-reference-jdbc-url-format.html

0 commit comments

Comments
 (0)