Skip to content

fix(bigquery-jdbc): migrate direct Cloud Logging export to GAPIC LoggingClient - #15346

Open
keshavdandeva wants to merge 4 commits into
fix/jdbc-telemetry-3-otel-proxy-truststorefrom
fix/jdbc-telemetry-4-gapic-cloud-logging
Open

keshavdandeva wants to merge 4 commits into
fix/jdbc-telemetry-3-otel-proxy-truststorefrom
fix/jdbc-telemetry-4-gapic-cloud-logging

Conversation

@keshavdandeva

Copy link
Copy Markdown
Contributor

Summary

Replaces the legacy com.google.cloud.logging.Logging / LoggingOptions client inside the driver with a package-private GcpLogWriter backed by the generated GAPIC com.google.cloud.logging.v2.LoggingClient so direct Cloud Logging export honors universeDomain, ProxyHost/ProxyPort/ProxyUid/ProxyPwd, SSLTrustStore*, and EndpointOverrides (OAUTH2).

Key Decisions

  • GAPIC LoggingClient over legacy LoggingOptions: LoggingOptions does not accept a gRPC TransportChannelProvider without a custom LoggingRpc adapter. Using the generated GAPIC LoggingClient (already in google-cloud-logging) accepts BigQueryJdbcProxyUtility's TransportChannelProvider, universeDomain, HeaderProvider, and write-scoped credentials natively with zero pom.xml changes.
  • Coordinated teardown & flow control: Uses GAX batching (LimitExceededBehavior.Block), a ThreadLocal re-entrancy guard, and a ReentrantReadWriteLock between write() and close(). close() waits up to 6s for in-flight writes and escalates to loggingClient.shutdownNow() on timeout or interrupt so stalled endpoints do not hang connection close.
  • Per-project cached MonitoredResource detection: Calls MonitoredResourceUtil.getResource(projectId, null) behind a per-project cache in GcpLogWriter to preserve GKE/GCE/Cloud Run resource association while avoiding repeated 5s metadata-server probes on every connection (working around MonitoredResourceUtil's cache miss on null resource type).
  • Bounded async failure reporting: Logs only the first async write failure at WARNING and logs a single dropped-write count on close() to avoid log storms while preserving visibility into export errors.

Behavior Changes

  • Full proxy, TrustStore, and universe support for enableGcpLogExporter=true: Direct Cloud Logging now uses the connection's gRPC TransportChannelProvider (including ProxyUid/ProxyPwd and SSLTrustStore*), universeDomain, and credential HTTP transport/overrides.
  • Log entry format: trace is now formatted as projects/<projectId>/traces/<traceId> (instead of the raw trace ID string), and the legacy LoggingImpl DEBUG sourceLocation auto-population is no longer attached.
  • Async failure reporting: Replaces legacy LoggingImpl's per-failure stderr prints with one WARNING on first failure plus a dropped-write summary on close().
  • Project ID resolution: Resolves project ID in order: explicit gcpTelemetryProjectId / ProjectId, ServiceAccountCredentials.getProjectId(), ServiceOptions.getDefaultProjectId(), throwing BigQueryJdbcRuntimeException if none is available.
  • Removed unused factory overloads: Replaced internal BigQueryJdbcOpenTelemetry.createLoggingClient(...) with package-private GcpLogWriter.create(...).

@keshavdandeva
keshavdandeva requested review from a team as code owners December 1, 2026 18:46

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request replaces the standard Google Cloud Logging client with a custom GcpLogWriter backed by the GAPIC LoggingClient to coordinate concurrent log writes with connection teardown and enforce a bounded flush on close. Feedback on the changes highlights a potential NullPointerException in GcpLogWriter.java if connectionId is null, as protobuf maps do not accept null values; a guard should be added to only include the label when it is non-null.

Comment on lines +252 to +263
LogEntry.Builder entryBuilder =
LogEntry.newBuilder()
.setLogName(LogName.ofProjectLogName(projectId, logId).toString())
.setResource(resource)
.setSeverity(severity)
.setTimestamp(
Timestamp.newBuilder()
.setSeconds(timestamp.getEpochSecond())
.setNanos(timestamp.getNano())
.build())
.setTextPayload(message)
.putLabels(BigQueryJdbcOpenTelemetry.CONNECTION_ID_BAGGAGE_KEY, connectionId);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

If connectionId is null (which can happen if a log is published from a thread without an active connection context), calling putLabels with a null value will throw a NullPointerException because protobuf map values cannot be null.

We should guard the putLabels call to only add the connection ID label if it is non-null.

        LogEntry.Builder entryBuilder =
            LogEntry.newBuilder()
                .setLogName(LogName.ofProjectLogName(projectId, logId).toString())
                .setResource(resource)
                .setSeverity(severity)
                .setTimestamp(
                    Timestamp.newBuilder()
                        .setSeconds(timestamp.getEpochSecond())
                        .setNanos(timestamp.getNano())
                        .build())
                .setTextPayload(message);

        if (connectionId != null) {
          entryBuilder.putLabels(BigQueryJdbcOpenTelemetry.CONNECTION_ID_BAGGAGE_KEY, connectionId);
        }

This branch has not been deployed

No deployments
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.

1 participant