Class UrlParsingUtils
java.lang.Object
io.opentelemetry.instrumentation.jdbc.internal.parser.UrlParsingUtils
Utility methods for parsing JDBC URLs.
This class is internal and is hence not for public use. Its APIs are unstable and can change at any time.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classResult of parsing a server string into host and port components.static final classLightweight wrapper for URL parameters that provides cleaner access patterns. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic StringbuildShortUrl(String type, String subtype, String host, Integer port) Build the short URL for db.connection_string attribute.static StringextractAuthority(String url) Extract the authority from a JDBC URL without reporting ambiguous credential text.static UrlParsingUtils.HostPortextractHostPort(String serverName) Extract host and port from a server string, handling IPv6 addresses.extractParams(String jdbcUrl, String startDelimiter, String splitSeparator) Extract parameters from a JDBC URL.extractQueryParams(String jdbcUrl, String separator) Extract query-style URL parameters from a JDBC URL.extractSemicolonParams(String jdbcUrl) Extract semicolon-delimited URL parameters from a JDBC URL.static StringextractSubtype(String jdbcUrl) Extract subtype from a JDBC URL of the form "type:subtype://...".static booleanhasMultipleTargets(String jdbcUrl) Returns whether a JDBC URL contains more than one configured target.static intindexOfAny(String str, char... chars) Find the index of the first occurrence of any of the specified characters.static IntegerParse an integer value, returning null if parsing fails.static io.opentelemetry.instrumentation.api.incubator.semconv.db.internal.DbServerTargetparseServerTargetGroup(String authority, Integer defaultPort) Parse and normalize a comma-separated configured server group.static StringsanitizeHostList(String authority) Sanitize a comma-separated host list, returningnullwhen it is not valid.splitQuery(String query, String separator) Split a query string into key-value pairs.static StringstripIpv6Brackets(String host) Remove the enclosing brackets from a literal IPv6 address, e.g.
-
Field Details
-
IPV6_PATTERN
-
-
Method Details
-
splitQuery
-
parsePort
-
buildShortUrl
public static String buildShortUrl(String type, @Nullable String subtype, @Nullable String host, @Nullable Integer port) Build the short URL for db.connection_string attribute.- Parameters:
type- the JDBC type (e.g., "postgresql", "mysql")subtype- optional subtype (e.g., "thin" for Oracle, "aurora" for MySQL)host- the host nameport- the port number- Returns:
- the short URL in format "type:[subtype:]//host:port" or "type:" if no host
-
extractParams
public static Map<String,String> extractParams(String jdbcUrl, String startDelimiter, String splitSeparator) Extract parameters from a JDBC URL.- Parameters:
jdbcUrl- the JDBC URLstartDelimiter- the delimiter marking the start of parameters (";" or "?")splitSeparator- the separator between parameters (";" or "&")- Returns:
- a map of parameter key-value pairs
-
extractSemicolonParams
-
extractQueryParams
Extract query-style URL parameters from a JDBC URL.- Parameters:
jdbcUrl- the JDBC URL containing parameters after "?"separator- the parameter separator (typically "&")- Returns:
- a map of parameter key-value pairs
-
extractSubtype
Extract subtype from a JDBC URL of the form "type:subtype://...".For example, "mysql:aurora://host:port/db" returns "aurora", "oceanbase:oracle://host/db" returns "oracle".
- Parameters:
jdbcUrl- the JDBC URL- Returns:
- the subtype, or null if no subtype is present
-
indexOfAny
Find the index of the first occurrence of any of the specified characters.- Parameters:
str- the string to searchchars- the characters to search for- Returns:
- the index of the first occurrence, or -1 if none found
-
extractAuthority
-
hasMultipleTargets
Returns whether a JDBC URL contains more than one configured target. -
sanitizeHostList
-
parseServerTargetGroup
-
extractHostPort
Extract host and port from a server string, handling IPv6 addresses. Supports formats: host, host:port, [ipv6], [ipv6]:port, ipv6.The returned host never carries the enclosing brackets of a literal IPv6 address, matching the
server.addresssemantic convention, which holds the address alone.- Parameters:
serverName- the server string to parse- Returns:
- the extracted host and port
-
stripIpv6Brackets
-