Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add more error handling #2203

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -21,6 +21,8 @@
import com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStub;
import io.opentelemetry.api.OpenTelemetry;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nonnull;

/**
Expand Down Expand Up @@ -63,6 +65,9 @@
*/
@BetaApi("This feature is currently experimental and can change in the future")
public final class BigtableDataClientFactory implements AutoCloseable {

private static final Logger logger = Logger.getLogger(BigtableDataClientFactory.class.getName());

private final BigtableDataSettings defaultSettings;
private final ClientContext sharedClientContext;
private final OpenTelemetry openTelemetry;
Expand All @@ -77,11 +82,18 @@ public static BigtableDataClientFactory create(BigtableDataSettings defaultSetti
throws IOException {
ClientContext sharedClientContext =
EnhancedBigtableStub.createClientContext(defaultSettings.getStubSettings());
OpenTelemetry openTelemetry =
EnhancedBigtableStub.getOpenTelemetry(
defaultSettings.getProjectId(),
defaultSettings.getMetricsProvider(),
sharedClientContext.getCredentials());
OpenTelemetry openTelemetry = null;
try {
// We don't want client side metrics to crash the client, so catch any exception when getting
// the OTEL instance and log the exception instead.
openTelemetry =
EnhancedBigtableStub.getOpenTelemetry(
defaultSettings.getProjectId(),
defaultSettings.getMetricsProvider(),
sharedClientContext.getCredentials());
} catch (Throwable t) {
logger.log(Level.WARNING, "Failed to get OTEL, will skip exporting client side metrics", t);
}
return new BigtableDataClientFactory(sharedClientContext, defaultSettings, openTelemetry);
}

Expand Down
Expand Up @@ -203,15 +203,23 @@ public class EnhancedBigtableStub implements AutoCloseable {
public static EnhancedBigtableStub create(EnhancedBigtableStubSettings settings)
throws IOException {
ClientContext clientContext = createClientContext(settings);
OpenTelemetry openTelemetry =
getOpenTelemetry(
settings.getProjectId(), settings.getMetricsProvider(), clientContext.getCredentials());
OpenTelemetry openTelemetry = null;
try {
// We don't want client side metrics to crash the client, so catch any exception when getting
// the OTEL instance and log the exception instead.
openTelemetry =
getOpenTelemetry(
settings.getProjectId(),
settings.getMetricsProvider(),
clientContext.getCredentials());
} catch (Throwable t) {
logger.log(Level.WARNING, "Failed to get OTEL, will skip exporting client side metrics", t);
}
ClientContext contextWithTracer =
clientContext
.toBuilder()
.setTracerFactory(createBigtableTracerFactory(settings, openTelemetry))
.build();

return new EnhancedBigtableStub(settings, contextWithTracer);
}

Expand Down
Expand Up @@ -82,7 +82,7 @@ public final class BigtableCloudMonitoringExporter implements MetricExporter {
System.getProperty("bigtable.test-monitoring-endpoint"),
MetricServiceSettings.getDefaultEndpoint());

private static String APPLICATION_RESOURCE_PROJECT_ID = "project_id";
private static final String APPLICATION_RESOURCE_PROJECT_ID = "project_id";

private final MetricServiceClient client;

Expand Down Expand Up @@ -133,7 +133,15 @@ public static BigtableCloudMonitoringExporter create(
// Detect the resource that the client application is running on. For example,
// this could be a GCE instance or a GKE pod. Currently, we only support GCE instance and
// GKE pod. This method will return null for everything else.
MonitoredResource applicationResource = BigtableExporterUtils.detectResource();
MonitoredResource applicationResource = null;
try {
applicationResource = BigtableExporterUtils.detectResource();
} catch (Exception e) {
logger.log(
Level.WARNING,
"Failed to detect resource, will skip exporting application level metrics ",
e);
}

return new BigtableCloudMonitoringExporter(
projectId,
Expand Down