Skip to content

Conversation

@vikrantpuppala
Copy link
Collaborator

Description

Improve logging when jdbc is shaded

Testing

Unit tests + manually in benchmarking

Additional Notes to the Reviewer

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances logging behavior in the JDBC driver by improving package prefix detection when the JAR is shaded (i.e., when packages are relocated during the build process). The changes enable the logger to automatically detect and use the correct package prefix, whether the driver is used in its original or shaded form.

Key Changes:

  • Added auto-detection logic to determine the actual package prefix at runtime by inspecting the JulLogger class's package name
  • Implemented shaded package detection for both main JDBC classes and driver classes
  • Added comprehensive test coverage for package prefix detection in both shaded and unshaded scenarios

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/main/java/com/databricks/jdbc/log/JulLogger.java Added auto-detection logic for package prefixes to handle shaded JARs, including methods to extract shading prefixes and apply them to both JDBC and driver packages
src/test/java/com/databricks/jdbc/log/JulLoggerTest.java Added three new test methods to verify package prefix detection works correctly for both shaded and unshaded JARs, and that logger configuration applies to the correct package hierarchy

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

// Auto-detect the actual package prefix by using the current class
// This handles shaded JARs where the package might be relocated
String actualPackageName = JulLogger.class.getPackage().getName();
// Extract the root prefix (e.g., "jdbc.shaded.v1.0.12.OSS.com.databricks.jdbc"
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

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

The comment shows an example shaded package path but has an inconsistent format with a period at the start. The example should be: shaded.jdbc.v1.0.12.OSS.com.databricks.jdbc or clarify if 'jdbc.' is intentional as part of the shading prefix.

Suggested change
// Extract the root prefix (e.g., "jdbc.shaded.v1.0.12.OSS.com.databricks.jdbc"
// Extract the root prefix (e.g., "shaded.jdbc.v1.0.12.OSS.com.databricks.jdbc"

Copilot uses AI. Check for mistakes.
actualPackageName, packagePrefix));

// If the jar is shaded, the prefix should include the shading prefix
if (actualPackageName.contains(".") && !actualPackageName.startsWith("com.databricks.jdbc")) {
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

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

The condition actualPackageName.contains(\".\") is redundant since Java package names always contain periods. This check should be removed, leaving only the !actualPackageName.startsWith(\"com.databricks.jdbc\") condition.

Suggested change
if (actualPackageName.contains(".") && !actualPackageName.startsWith("com.databricks.jdbc")) {
if (!actualPackageName.startsWith("com.databricks.jdbc")) {

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

@samikshya-db samikshya-db left a comment

Choose a reason for hiding this comment

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

I have always needed this, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants