Class ParseContext
java.lang.Object
io.opentelemetry.instrumentation.jdbc.internal.parser.ParseContext
Mutable context for building up connection info during JDBC URL parsing.
This class is internal and is hence not for public use. Its APIs are unstable and can change at any time.
-
Method Summary
Modifier and TypeMethodDescriptionvoidapplyCommonParams(String jdbcUrl, String startDelimiter, String splitSeparator) Apply common parameters from URL parameters to the context.voidApply common DataSource properties to this context.voidApply only the user property from DataSource properties.The database name value accumulated so far.voiddatabaseName(String databaseName) Set the database name value.dbName()Deprecated.voidDeprecated.host()The host value accumulated so far.voidSet the host value.The namespace value accumulated so far.voidSet the namespace value.static ParseContextof(String type, Properties props) Create a context with the JDBC type and optional properties.Deprecated.voidoldSemconvSystem(String oldSemconvSystem) Deprecated.voidParse a URL-style JDBC connection string that uses semicolons for properties.port()The port value accumulated so far.voidSet the port value.props()DataSource connection properties.subtype()The optional subtype (e.g., "tcp", "aurora").voidSet the subtype value.system()The database system identifier (stable/new value, e.g., "postgresql", "h2database").voidSet the database system identifier (stable/new value).toDbInfo()Build the final DbInfo from the accumulated context values.type()The JDBC type (e.g., "mysql", "postgresql").user()Deprecated.voidDeprecated.
-
Method Details
-
of
Create a context with the JDBC type and optional properties. -
type
The JDBC type (e.g., "mysql", "postgresql"). -
system
The database system identifier (stable/new value, e.g., "postgresql", "h2database"). -
system
Set the database system identifier (stable/new value). For systems where old and new values differ, also calloldSemconvSystem(String). -
oldSemconvSystem
Deprecated.The old semconv database system identifier (e.g., "mssql", "h2"). -
oldSemconvSystem
Deprecated.Set the old semconv database system identifier (only required when different from system). -
subtype
The optional subtype (e.g., "tcp", "aurora"). -
subtype
Set the subtype value. -
host
The host value accumulated so far. -
host
Set the host value. -
port
The port value accumulated so far. -
port
Set the port value. -
user
Deprecated.The user value accumulated so far. -
user
Deprecated.Set the user value. -
databaseName
The database name value accumulated so far. -
databaseName
Set the database name value. -
namespace
The namespace value accumulated so far. -
namespace
Set the namespace value. -
dbName
Deprecated.Override for the dbName field in the resulting DbInfo. When set, this value takes precedence over the databaseName-derived value. Used by SQL Server parsers to preserve old behavior where dbName is the instance name when both instance and database are present. -
dbName
Deprecated. -
props
DataSource connection properties. -
applyCommonParams
Apply common parameters from URL parameters to the context.Extracts the same properties as
applyDataSourceProperties()but using lowercase keys (servername, portnumber, databasename, user) as URL params are typically lowercased.- Parameters:
jdbcUrl- the JDBC URL containing parametersstartDelimiter- the delimiter marking the start of parameters (";" or "?")splitSeparator- the separator between individual parameters (";" or "&")
-
applyDataSourceProperties
public void applyDataSourceProperties()Apply common DataSource properties to this context. These properties are defined by the JDBC specification (JSR 221, Section 9.4.1).Extracts serverName, portNumber, databaseName, and user from the properties if present.
-
applyUserProperty
public void applyUserProperty()Apply only the user property from DataSource properties. Use this for drivers that don't support the standard serverName/portNumber/databaseName DataSource properties (e.g., SAP HANA, H2, HSQLDB, Derby).TODO: Currently delegates to
applyDataSourceProperties()to avoid a behavioral change in this refactoring. In the future, this will be changed to only apply the user property. -
parseUrl
Parse a URL-style JDBC connection string that uses semicolons for properties. Updates this context with extracted values (user, host, port, path).If the URL contains a database path, it is applied to this context and overrides any previously set database name.
- Parameters:
jdbcUrl- the JDBC URL to parse
-
toDbInfo
Build the final DbInfo from the accumulated context values.- Returns:
- the complete DbInfo
-