Skip to content

Commit

Permalink
fix: allow factory to export to different projects
Browse files Browse the repository at this point in the history
  • Loading branch information
mutianf committed Oct 8, 2024
1 parent fa87c62 commit 592f47d
Showing 1 changed file with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public final class BigtableDataClientFactory implements AutoCloseable {

private final BigtableDataSettings defaultSettings;
private final ClientContext sharedClientContext;
private final OpenTelemetry openTelemetry;
private final OpenTelemetry defaultOpenTelemetry;

/**
* Create a instance of this factory.
Expand Down Expand Up @@ -104,7 +104,7 @@ private BigtableDataClientFactory(
OpenTelemetry openTelemetry) {
this.sharedClientContext = sharedClientContext;
this.defaultSettings = defaultSettings;
this.openTelemetry = openTelemetry;
this.defaultOpenTelemetry = openTelemetry;
}

/**
Expand Down Expand Up @@ -135,7 +135,7 @@ public BigtableDataClient createDefault() {
.toBuilder()
.setTracerFactory(
EnhancedBigtableStub.createBigtableTracerFactory(
defaultSettings.getStubSettings(), openTelemetry))
defaultSettings.getStubSettings(), defaultOpenTelemetry))
.build();

return BigtableDataClient.createWithClientContext(defaultSettings, clientContext);
Expand Down Expand Up @@ -164,7 +164,7 @@ public BigtableDataClient createForAppProfile(@Nonnull String appProfileId) thro
.toBuilder()
.setTracerFactory(
EnhancedBigtableStub.createBigtableTracerFactory(
settings.getStubSettings(), openTelemetry))
settings.getStubSettings(), defaultOpenTelemetry))
.build();
return BigtableDataClient.createWithClientContext(settings, clientContext);
}
Expand All @@ -180,6 +180,21 @@ public BigtableDataClient createForAppProfile(@Nonnull String appProfileId) thro
*/
public BigtableDataClient createForInstance(@Nonnull String projectId, @Nonnull String instanceId)
throws IOException {
OpenTelemetry openTelemetry = null;
if (!projectId.equals(defaultSettings.getProjectId())) {
try {
openTelemetry =
EnhancedBigtableStub.getOpenTelemetry(
projectId,
defaultSettings.getMetricsProvider(),
sharedClientContext.getCredentials(),
defaultSettings.getStubSettings().getMetricsEndpoint());
} catch (Throwable t) {
logger.log(Level.WARNING, "Failed to get OTEL, will skip exporting client side metrics", t);
}
} else {
openTelemetry = defaultOpenTelemetry;
}
BigtableDataSettings settings =
defaultSettings
.toBuilder()
Expand Down Expand Up @@ -211,6 +226,21 @@ public BigtableDataClient createForInstance(@Nonnull String projectId, @Nonnull
public BigtableDataClient createForInstance(
@Nonnull String projectId, @Nonnull String instanceId, @Nonnull String appProfileId)
throws IOException {
OpenTelemetry openTelemetry = null;
if (!projectId.equals(defaultSettings.getProjectId())) {
try {
openTelemetry =
EnhancedBigtableStub.getOpenTelemetry(
projectId,
defaultSettings.getMetricsProvider(),
sharedClientContext.getCredentials(),
defaultSettings.getStubSettings().getMetricsEndpoint());
} catch (Throwable t) {
logger.log(Level.WARNING, "Failed to get OTEL, will skip exporting client side metrics", t);
}
} else {
openTelemetry = defaultOpenTelemetry;
}
BigtableDataSettings settings =
defaultSettings
.toBuilder()
Expand Down

0 comments on commit 592f47d

Please sign in to comment.