Skip to content

Commit ea35185

Browse files
committed
chore: address pr feedback
1 parent 19121c4 commit ea35185

5 files changed

Lines changed: 27 additions & 23 deletions

File tree

java-bigquery/google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryDriver.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,10 @@ public Connection connect(String url, Properties info) throws SQLException {
157157
if (logPath == null) {
158158
logPath = System.getenv(BigQueryJdbcUrlUtility.LOG_PATH_ENV_VAR);
159159
}
160-
if (logPath == null) {
161-
// Cloud-Only Mode: Suppress local file creation if GCP log exporter is enabled
162-
if (ds.getEnableGcpLogExporter() && logLevel != Level.OFF) {
163-
logPath = null;
164-
} else {
165-
logPath = BigQueryJdbcUrlUtility.DEFAULT_LOG_PATH;
166-
}
160+
161+
// Fallback to default path only if not specified and not in Cloud-Only mode
162+
if (logPath == null && !ds.getEnableGcpLogExporter()) {
163+
logPath = BigQueryJdbcUrlUtility.DEFAULT_LOG_PATH;
167164
}
168165

169166
BigQueryJdbcRootLogger.setLevel(logLevel, logPath);

java-bigquery/google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcOpenTelemetry.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class BigQueryJdbcOpenTelemetry {
2828

2929
static final String INSTRUMENTATION_SCOPE_NAME = "com.google.cloud.bigquery.jdbc";
3030
static final String BIGQUERY_NAMESPACE = "com.google.cloud.bigquery";
31+
public static final String CONNECTION_ID_BAGGAGE_KEY = "jdbc.connection_id";
3132

3233
static class TelemetryConfig {
3334
final OpenTelemetry openTelemetry;

java-bigquery/google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcRootLogger.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,14 @@ public static void setLevel(Level level, String logPath) throws IOException {
141141
if (logPath != null) {
142142
setPath(logPath, level);
143143
}
144-
logger.setLevel(level);
145144
} else {
146145
for (Handler h : logger.getHandlers()) {
147146
h.close();
148147
logger.removeHandler(h);
149148
}
150149
fileHandler = null;
151-
logger.setLevel(Level.OFF);
152150
}
151+
logger.setLevel(level);
153152
}
154153

155154
static void setPath(String logPath, Level level) {

java-bigquery/google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/OpenTelemetryJulHandler.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ public void publish(LogRecord record) {
5151
try {
5252
// Extract connection ID from baggage
5353
String connectionId =
54-
Baggage.fromContext(Context.current()).getEntryValue("jdbc.connection_id");
54+
Baggage.fromContext(Context.current())
55+
.getEntryValue(BigQueryJdbcOpenTelemetry.CONNECTION_ID_BAGGAGE_KEY);
5556

5657
// Fallback to MDC if not in baggage (if MDC is available and used)
5758
if (connectionId == null) {
@@ -85,9 +86,6 @@ private void publishToGcp(LogRecord record, String connectionId, Logging logging
8586
String spanId = spanContext.isValid() ? spanContext.getSpanId() : null;
8687

8788
// TODO(b/491238299): May require refinement for structured logging or error handling
88-
if (loggingClient == null) {
89-
return;
90-
}
9189

9290
LogEntry.Builder builder =
9391
LogEntry.newBuilder(Payload.StringPayload.of(formatMessage(record)))
@@ -101,7 +99,7 @@ private void publishToGcp(LogRecord record, String connectionId, Logging logging
10199
builder.setSpanId(spanId);
102100
}
103101
if (connectionId != null) {
104-
builder.addLabel("jdbc.connection_id", connectionId);
102+
builder.addLabel(BigQueryJdbcOpenTelemetry.CONNECTION_ID_BAGGAGE_KEY, connectionId);
105103
}
106104

107105
loggingClient.write(Collections.singleton(builder.build()));
@@ -117,10 +115,6 @@ private com.google.cloud.logging.Severity mapGcpSeverity(Level level) {
117115
}
118116

119117
private void publishToOTel(LogRecord record, String connectionId, OpenTelemetry openTelemetry) {
120-
if (openTelemetry == null) {
121-
return;
122-
}
123-
124118
String loggerName = record.getLoggerName();
125119
Logger logger =
126120
openTelemetry
@@ -139,7 +133,9 @@ private void publishToOTel(LogRecord record, String connectionId, OpenTelemetry
139133
.setContext(Context.current());
140134

141135
if (connectionId != null) {
142-
builder.setAttribute(AttributeKey.stringKey("jdbc.connection_id"), connectionId);
136+
builder.setAttribute(
137+
AttributeKey.stringKey(BigQueryJdbcOpenTelemetry.CONNECTION_ID_BAGGAGE_KEY),
138+
connectionId);
143139
}
144140

145141
builder.emit();

java-bigquery/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/OpenTelemetryJulHandlerTest.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ public void testPublishToOTel() {
6464
"test-uuid", otelTesting.getOpenTelemetry(), null, false);
6565

6666
BigQueryConnection mockConnection = mock(BigQueryConnection.class);
67-
Baggage baggage = Baggage.builder().put("jdbc.connection_id", "test-uuid").build();
67+
Baggage baggage =
68+
Baggage.builder()
69+
.put(BigQueryJdbcOpenTelemetry.CONNECTION_ID_BAGGAGE_KEY, "test-uuid")
70+
.build();
6871
try (Scope scope = baggage.makeCurrent();
6972
BigQueryJdbcMdc.MdcCloseable mdcScope =
7073
BigQueryJdbcMdc.registerInstance(mockConnection, "test-uuid")) {
@@ -77,7 +80,9 @@ public void testPublishToOTel() {
7780
assertEquals("Test message", log.getBody().asString());
7881
assertEquals(Severity.INFO, log.getSeverity());
7982
assertEquals(
80-
"test-uuid", log.getAttributes().get(AttributeKey.stringKey("jdbc.connection_id")));
83+
"test-uuid",
84+
log.getAttributes()
85+
.get(AttributeKey.stringKey(BigQueryJdbcOpenTelemetry.CONNECTION_ID_BAGGAGE_KEY)));
8186
}
8287

8388
@Test
@@ -87,7 +92,10 @@ public void testPublishWithFiltering() {
8792
"test-uuid", otelTesting.getOpenTelemetry(), null, false);
8893

8994
// Log with WRONG connection ID
90-
Baggage baggage = Baggage.builder().put("jdbc.connection_id", "wrong-uuid").build();
95+
Baggage baggage =
96+
Baggage.builder()
97+
.put(BigQueryJdbcOpenTelemetry.CONNECTION_ID_BAGGAGE_KEY, "wrong-uuid")
98+
.build();
9199
try (Scope scope = baggage.makeCurrent()) {
92100
logger.info("Test message");
93101
}
@@ -103,7 +111,10 @@ public void testPublishToGcp() {
103111
"gcp-uuid", otelTesting.getOpenTelemetry(), loggingClient, true);
104112

105113
BigQueryConnection mockConnection = mock(BigQueryConnection.class);
106-
Baggage baggage = Baggage.builder().put("jdbc.connection_id", "gcp-uuid").build();
114+
Baggage baggage =
115+
Baggage.builder()
116+
.put(BigQueryJdbcOpenTelemetry.CONNECTION_ID_BAGGAGE_KEY, "gcp-uuid")
117+
.build();
107118
try (Scope scope = baggage.makeCurrent();
108119
BigQueryJdbcMdc.MdcCloseable mdcScope =
109120
BigQueryJdbcMdc.registerInstance(mockConnection, "gcp-uuid")) {

0 commit comments

Comments
 (0)