Skip to content

Commit

Permalink
Capture Client Guest OS and architecture in JDBC
Browse files Browse the repository at this point in the history
  • Loading branch information
muskan124947 committed Dec 11, 2024
1 parent 6829848 commit f979936
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,21 @@ static String getPropertyOnlyName(String name, Logger logger) {
"java.specification.version", "java.class.path", "java.class.version", "java.runtime.name",
"java.runtime.version", "java.vendor", "java.version", "java.vm.name", "java.vm.vendor", "java.vm.version",
"java.vm.specification.vendor", "java.vm.specification.version", "os.name", "os.version", "os.arch"};

/**
* This method retrieves the OS name and architecture using Java system properties
* and logs this information.
*/
private void logClientOSAndArchInfo() {
try {
String osName = System.getProperty("os.name");
String osArch = System.getProperty("os.arch");

loggerExternal.log(Level.FINE, "Client OS: " + osName + ", Architecture: " + osArch);
} catch (Exception e) {
loggerExternal.warning("Unable to capture client OS and architecture information.");

Check warning on line 1255 in src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java#L1254-L1255

Added lines #L1254 - L1255 were not covered by tests
}
}

@Override
public java.sql.Connection connect(String url, Properties suppliedProperties) throws SQLServerException {
Expand All @@ -1251,6 +1266,7 @@ public java.sql.Connection connect(String url, Properties suppliedProperties) th
"Microsoft JDBC Driver " + SQLJdbcVersion.MAJOR + "." + SQLJdbcVersion.MINOR + "."
+ SQLJdbcVersion.PATCH + "." + SQLJdbcVersion.BUILD + SQLJdbcVersion.RELEASE_EXT
+ " for SQL Server");
logClientOSAndArchInfo();
if (loggerExternal.isLoggable(Level.FINER)) {
for (String propertyKeyName : systemPropertiesToLog) {
String propertyValue = System.getProperty(propertyKeyName);
Expand Down

0 comments on commit f979936

Please sign in to comment.