Skip to content

Commit aa8400b

Browse files
author
Bot
committed
fix(spanner-executor): port secure_context to SpannerAction and handle empty serviceKeyFile
1 parent d5bc95f commit aa8400b

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

‎java-spanner/google-cloud-spanner-executor/src/main/java/com/google/cloud/executor/spanner/CloudClientExecutor.java‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,10 @@ private synchronized Spanner initializeClient(long timeoutSeconds, boolean useMu
863863
throws IOException {
864864
// Create a cloud spanner client
865865
Credentials credentials;
866-
if (WorkerProxy.serviceKeyFile.isEmpty()) {
866+
if (WorkerProxy.serviceKeyFile == null
867+
|| WorkerProxy.serviceKeyFile.isEmpty()
868+
|| !new File(WorkerProxy.serviceKeyFile).exists()
869+
|| new File(WorkerProxy.serviceKeyFile).isDirectory()) {
867870
credentials = NoCredentials.getInstance();
868871
} else {
869872
credentials =
@@ -945,7 +948,10 @@ private synchronized TraceServiceClient getTraceServiceClient() throws IOExcepti
945948
}
946949
// Create a trace service client
947950
Credentials credentials;
948-
if (WorkerProxy.serviceKeyFile.isEmpty()) {
951+
if (WorkerProxy.serviceKeyFile == null
952+
|| WorkerProxy.serviceKeyFile.isEmpty()
953+
|| !new File(WorkerProxy.serviceKeyFile).exists()
954+
|| new File(WorkerProxy.serviceKeyFile).isDirectory()) {
949955
credentials = NoCredentials.getInstance();
950956
} else {
951957
credentials =

‎java-spanner/google-cloud-spanner-executor/src/main/java/com/google/cloud/executor/spanner/WorkerProxy.java‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@ public class WorkerProxy {
8484
private static final double MIN_RATIO = 0.0, MAX_RATIO = 1.0, TRACE_SAMPLING_RATE = 0.01;
8585

8686
public static OpenTelemetrySdk setupOpenTelemetrySdk() throws Exception {
87+
if (serviceKeyFile == null
88+
|| serviceKeyFile.isEmpty()
89+
|| !new File(serviceKeyFile).exists()
90+
|| new File(serviceKeyFile).isDirectory()) {
91+
LOGGER.log(
92+
Level.WARNING,
93+
"serviceKeyFile is empty or invalid; starting without OpenTelemetry trace export: "
94+
+ serviceKeyFile);
95+
return OpenTelemetrySdk.builder()
96+
.setPropagators(ContextPropagators.create(W3CTraceContextPropagator.getInstance()))
97+
.build();
98+
}
8799
// Read credentials from the serviceKeyFile.
88100
HttpTransportFactory HTTP_TRANSPORT_FACTORY = NetHttpTransport::new;
89101
Credentials credentials =

0 commit comments

Comments
 (0)