Skip to content

Commit d140cf9

Browse files
author
Mateusz Rzeszutek
authored
Add support for the AWS Secrets Manager JDBC URLs (#9335)
1 parent 68da349 commit d140cf9

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -863,11 +863,15 @@ public static DbInfo parse(String connectionUrl, Properties props) {
863863
// Make this easier and ignore case.
864864
connectionUrl = connectionUrl.toLowerCase(Locale.ROOT);
865865

866-
if (!connectionUrl.startsWith("jdbc:")) {
866+
String jdbcUrl;
867+
if (connectionUrl.startsWith("jdbc:")) {
868+
jdbcUrl = connectionUrl.substring("jdbc:".length());
869+
} else if (connectionUrl.startsWith("jdbc-secretsmanager:")) {
870+
jdbcUrl = connectionUrl.substring("jdbc-secretsmanager:".length());
871+
} else {
867872
return DEFAULT;
868873
}
869874

870-
String jdbcUrl = connectionUrl.substring("jdbc:".length());
871875
int typeLoc = jdbcUrl.indexOf(':');
872876

873877
if (typeLoc < 1) {

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

+6
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,12 @@ class JdbcConnectionUrlParserTest extends Specification {
219219
"jdbc:tibcosoftware:postgresql://server_name:5432;DatabaseName=dbname" | null | "tibcosoftware:postgresql://server_name:5432" | "postgresql" | "postgresql" | null | "server_name" | 5432 | null | "dbname"
220220
"jdbc:tibcosoftware:db2://server_name:50000;DatabaseName=dbname" | null | "tibcosoftware:db2://server_name:50000" | "db2" | "db2" | null | "server_name" | 50000 | null | "dbname"
221221

222+
// https://docs.aws.amazon.com/secretsmanager/latest/userguide/retrieving-secrets_jdbc.html
223+
"jdbc-secretsmanager:mysql://example.com:50000" | null | "mysql://example.com:50000" | "mysql" | null | null | "example.com" | 50000 | null | null
224+
"jdbc-secretsmanager:postgresql://example.com:50000/dbname" | null | "postgresql://example.com:50000" | "postgresql" | null | null | "example.com" | 50000 | null | "dbname"
225+
"jdbc-secretsmanager:oracle:thin:@example.com:50000/ORCL" | null | "oracle:thin://example.com:50000" | "oracle" | "thin" | null | "example.com" | 50000 | "orcl" | null
226+
"jdbc-secretsmanager:sqlserver://example.com:50000" | null | "sqlserver://example.com:50000" | "mssql" | null | null | "example.com" | 50000 | null | null
227+
222228
expected = DbInfo.builder().system(system).subtype(subtype).user(user).name(name).db(db).host(host).port(port).shortUrl(shortUrl).build()
223229
}
224230
}

0 commit comments

Comments
 (0)