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.voidapplyCommonParams(Map<String, String> params) Apply common parameters from a pre-parsed parameter map.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.voiddefaultHost(String host) Set a parser default host without marking it as configured.voiddefaultPort(Integer port) Set a parser default port without marking it as configured.voidPrevent single-server fallback without discarding an already resolved target.host()The legacy host accumulated so far, including any parser default.voidRecord a parsed host for legacy output and, when allowed, single-server fallback.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 legacy port accumulated so far, including any parser default.voidRecord a parsed port for legacy output and, when allowed, single-server fallback.props()DataSource connection properties.voidresolveConfiguredServerTarget(io.opentelemetry.instrumentation.api.incubator.semconv.db.internal.DbServerTarget configuredServerTarget) Resolve the configured target, ornullwhen it cannot be represented safely.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
-
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
-
subtype
-
host
-
host
-
defaultHost
-
port
-
port
-
defaultPort
-
resolveConfiguredServerTarget
public void resolveConfiguredServerTarget(@Nullable io.opentelemetry.instrumentation.api.incubator.semconv.db.internal.DbServerTarget configuredServerTarget) Resolve the configured target, ornullwhen it cannot be represented safely. Disables single-server fallback in either case. -
disableSingleServerFallback
public void disableSingleServerFallback()Prevent single-server fallback without discarding an already resolved target. -
user
-
user
-
databaseName
-
databaseName
-
namespace
-
namespace
-
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 "&")
-
applyCommonParams
Apply common parameters from a pre-parsed parameter map. Equivalent toapplyCommonParams(String, String, String)but avoids re-parsing the URL when the caller has already extracted the parameters.- Parameters:
params- the parameter map (keys must be lowercase)
-
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
-