Skip to content

Conversation

@muskan124947
Copy link
Contributor

@muskan124947 muskan124947 commented Dec 11, 2024

Use case: Update the application name to "Microsoft JDBC - {OS}, {Platform} - {architecture}"

@muskan124947 muskan124947 self-assigned this Dec 11, 2024
Copy link
Contributor

@machavan machavan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to set the appname in the format

Microsoft JDBC - {OS}, {Platform} - {architecture}

in the enum SQLServerDriverStringProperty .

Currently it is set to default value

APPLICATION_NAME("applicationName", SQLServerDriver.DEFAULT_APP_NAME),

@codecov
Copy link

codecov bot commented Dec 11, 2024

Codecov Report

Attention: Patch coverage is 78.57143% with 3 lines in your changes missing coverage. Please review.

Project coverage is 51.05%. Comparing base (6829848) to head (9a7b948).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
.../com/microsoft/sqlserver/jdbc/SQLServerDriver.java 76.92% 0 Missing and 3 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #2561      +/-   ##
============================================
- Coverage     51.12%   51.05%   -0.07%     
+ Complexity     3940     3925      -15     
============================================
  Files           147      147              
  Lines         33456    33468      +12     
  Branches       5604     5607       +3     
============================================
- Hits          17105    17088      -17     
- Misses        13963    13971       +8     
- Partials       2388     2409      +21     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

"Microsoft JDBC Driver " + SQLJdbcVersion.MAJOR + "." + SQLJdbcVersion.MINOR + "."
+ SQLJdbcVersion.PATCH + "." + SQLJdbcVersion.BUILD + SQLJdbcVersion.RELEASE_EXT
+ " for SQL Server");
logClientOSAndArchInfo();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this meant to be used elsewhere? if only used once here then there's no need to create a sep method


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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should add e.getMessage() for more info


// If all values are empty, return the default app name
if (osName.isEmpty() && platform.isEmpty() && osArch.isEmpty()) {
return DEFAULT_APP_NAME;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If osName, platform and osArch are empty, then we can avoid String formatting:

if (!osName.isEmpty() && !platform.isEmpty() && !osArch.isEmpty()) {
return String.format(APP_NAME_TEMPLATE, osName, platform, osArch);
}
return DEFAULT_APP_NAME;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be a static and only done once

drLogger.finer("Error registering driver: " + e);
}
}
if (loggerExternal.isLoggable(Level.INFO)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistent logging level, please use Level.FINE

new String[] {ApplicationIntent.READ_ONLY.toString(), ApplicationIntent.READ_WRITE.toString()}),
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.APPLICATION_NAME.toString(),
SQLServerDriverStringProperty.APPLICATION_NAME.getDefaultValue(), false, null),
"", false, null),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep this unchanged to default to DEFAULT_APP_NAME

public void testApplicationName() throws SQLException {
try (Connection conn = DriverManager.getConnection(connectionString);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT program_name FROM sys.dm_exec_sessions WHERE session_id = @@SPID")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to have this test which is actually querying the program name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

@lilgreenbird lilgreenbird added this to the 12.10.0 milestone Dec 17, 2024
@muskan124947 muskan124947 merged commit 565ee02 into main Dec 20, 2024
19 checks passed
@muskan124947 muskan124947 deleted the users/muskgupta/issue#32957 branch December 20, 2024 07:33
@muskan124947 muskan124947 restored the users/muskgupta/issue#32957 branch January 2, 2025 05:30
muskan124947 added a commit that referenced this pull request Jan 2, 2025
Ananya2 pushed a commit that referenced this pull request Jan 10, 2025
* Capture Client Guest OS and architecture in JDBC

* Added app name with format Microsoft JDBC - {os}, {platform} - {arch}

* Adding log info and getAppNameWithProperties()

* Updated the application name to be set dynamically

* Added log level as FINE

* Added test case to verify application name

* Updated the SQLServerDriverPropertyInfo with default name

* Added static block for initialization

* Added test case for code coverage

* Updated app Name
@Jeffery-Wasty Jeffery-Wasty deleted the users/muskgupta/issue#32957 branch February 12, 2025 20:03
@machavan machavan mentioned this pull request Mar 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Closed/Merged PRs

Development

Successfully merging this pull request may close these issues.

6 participants