Skip to content
This repository was archived by the owner on May 8, 2026. It is now read-only.

Commit aa3051d

Browse files
chore: plumb ClientInfo
Change-Id: I01806d0bbaa6ba95b3a8e66d9b3fa24806c928f0
1 parent 333c1ee commit aa3051d

5 files changed

Lines changed: 51 additions & 42 deletions

File tree

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataClientFactory.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ public BigtableDataClient createDefault() {
109109
try {
110110
BigtableClientContext ctx =
111111
sharedClientContext.createChild(
112-
sharedClientContext.getInstanceName(), sharedClientContext.getAppProfileId());
112+
sharedClientContext.getClientInfo().getInstanceName(),
113+
sharedClientContext.getClientInfo().getAppProfileId());
113114

114115
return new BigtableDataClient(new EnhancedBigtableStub(perOpSettings, ctx));
115116
} catch (IOException e) {
@@ -130,7 +131,8 @@ public BigtableDataClient createDefault() {
130131
*/
131132
public BigtableDataClient createForAppProfile(@Nonnull String appProfileId) throws IOException {
132133
BigtableClientContext ctx =
133-
sharedClientContext.createChild(sharedClientContext.getInstanceName(), appProfileId);
134+
sharedClientContext.createChild(
135+
sharedClientContext.getClientInfo().getInstanceName(), appProfileId);
134136

135137
return new BigtableDataClient(new EnhancedBigtableStub(perOpSettings, ctx));
136138
}

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/RequestContext.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import com.google.api.core.InternalApi;
1919
import com.google.auto.value.AutoValue;
20+
import com.google.cloud.bigtable.data.v2.internal.csm.attributes.ClientInfo;
2021
import java.io.Serializable;
2122

2223
/**
@@ -33,6 +34,13 @@
3334
@AutoValue
3435
public abstract class RequestContext implements Serializable {
3536

37+
public static RequestContext create(ClientInfo clientInfo) {
38+
return create(
39+
clientInfo.getInstanceName().getProject(),
40+
clientInfo.getInstanceName().getInstance(),
41+
clientInfo.getAppProfileId());
42+
}
43+
3644
/** Creates a new instance of the {@link RequestContext}. */
3745
public static RequestContext create(String projectId, String instanceId, String appProfileId) {
3846
return new AutoValue_RequestContext(projectId, instanceId, appProfileId);

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableClientContext.java

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.google.auth.oauth2.ServiceAccountJwtAccessCredentials;
3030
import com.google.bigtable.v2.InstanceName;
3131
import com.google.cloud.bigtable.data.v2.internal.JwtCredentialsWithAudience;
32+
import com.google.cloud.bigtable.data.v2.internal.csm.attributes.ClientInfo;
3233
import com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants;
3334
import com.google.cloud.bigtable.data.v2.stub.metrics.ChannelPoolMetricsTracer;
3435
import com.google.cloud.bigtable.data.v2.stub.metrics.CompositeTracerFactory;
@@ -63,8 +64,7 @@ public class BigtableClientContext {
6364
private static final Logger logger = Logger.getLogger(BigtableClientContext.class.getName());
6465

6566
private final boolean isChild;
66-
private final InstanceName instanceName;
67-
private final String appProfileId;
67+
private final ClientInfo clientInfo;
6868
private final ApiTracerFactory userTracerFactory;
6969
@Nullable private final OpenTelemetrySdk builtinOpenTelemetry;
7070
@Nullable private final OpenTelemetry userOpenTelemetry;
@@ -83,8 +83,11 @@ public static BigtableClientContext create(EnhancedBigtableStubSettings settings
8383
public static BigtableClientContext create(
8484
EnhancedBigtableStubSettings settings, Tagger ocTagger, StatsRecorder ocRecorder)
8585
throws IOException {
86-
InstanceName instanceName = InstanceName.of(settings.getProjectId(), settings.getInstanceId());
87-
String appProfileId = settings.getAppProfileId();
86+
ClientInfo clientInfo =
87+
ClientInfo.builder()
88+
.setInstanceName(InstanceName.of(settings.getProjectId(), settings.getInstanceId()))
89+
.setAppProfileId(settings.getAppProfileId())
90+
.build();
8891

8992
EnhancedBigtableStubSettings.Builder builder = settings.toBuilder();
9093

@@ -184,8 +187,7 @@ public static BigtableClientContext create(
184187

185188
return new BigtableClientContext(
186189
false,
187-
instanceName,
188-
appProfileId,
190+
clientInfo,
189191
clientContext,
190192
userTracerFactory,
191193
builtinOtel,
@@ -224,8 +226,7 @@ private static void configureGrpcOtel(
224226

225227
private BigtableClientContext(
226228
boolean isChild,
227-
InstanceName instanceName,
228-
String appProfileId,
229+
ClientInfo clientInfo,
229230
ClientContext clientContext,
230231
ApiTracerFactory userTracerFactory,
231232
@Nullable OpenTelemetrySdk builtinOtel,
@@ -235,8 +236,7 @@ private BigtableClientContext(
235236
ExecutorProvider backgroundExecutorProvider)
236237
throws IOException {
237238
this.isChild = isChild;
238-
this.instanceName = instanceName;
239-
this.appProfileId = appProfileId;
239+
this.clientInfo = clientInfo;
240240

241241
this.userTracerFactory = userTracerFactory;
242242
this.builtinOpenTelemetry = builtinOtel;
@@ -247,15 +247,15 @@ private BigtableClientContext(
247247

248248
ImmutableList.Builder<ApiTracerFactory> tracerFactories = ImmutableList.builder();
249249
tracerFactories
250-
.add(Util.createOCTracingFactory(instanceName, appProfileId))
251-
.add(Util.createOCMetricsFactory(instanceName, appProfileId, ocTagger, ocRecorder))
250+
.add(Util.createOCTracingFactory(clientInfo))
251+
.add(Util.createOCMetricsFactory(clientInfo, ocTagger, ocRecorder))
252252
.add(userTracerFactory);
253253

254254
if (builtinOtel != null) {
255-
tracerFactories.add(Util.createOtelMetricsFactory(builtinOtel, instanceName, appProfileId));
255+
tracerFactories.add(Util.createOtelMetricsFactory(builtinOtel, clientInfo));
256256
}
257257
if (userOtel != null) {
258-
tracerFactories.add(Util.createOtelMetricsFactory(userOtel, instanceName, appProfileId));
258+
tracerFactories.add(Util.createOtelMetricsFactory(userOtel, clientInfo));
259259
}
260260

261261
this.clientContext =
@@ -264,12 +264,8 @@ private BigtableClientContext(
264264
.build();
265265
}
266266

267-
public InstanceName getInstanceName() {
268-
return instanceName;
269-
}
270-
271-
public String getAppProfileId() {
272-
return appProfileId;
267+
public ClientInfo getClientInfo() {
268+
return clientInfo;
273269
}
274270

275271
@Nullable
@@ -290,8 +286,7 @@ public BigtableClientContext createChild(InstanceName instanceName, String appPr
290286
throws IOException {
291287
return new BigtableClientContext(
292288
true,
293-
instanceName,
294-
appProfileId,
289+
clientInfo.toBuilder().setInstanceName(instanceName).setAppProfileId(appProfileId).build(),
295290
clientContext,
296291
userTracerFactory,
297292
builtinOpenTelemetry,

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,7 @@ public EnhancedBigtableStub(
182182
ClientOperationSettings perOpSettings, BigtableClientContext clientContext) {
183183
this.perOpSettings = perOpSettings;
184184
this.bigtableClientContext = clientContext;
185-
this.requestContext =
186-
RequestContext.create(
187-
clientContext.getInstanceName().getProject(),
188-
clientContext.getInstanceName().getInstance(),
189-
clientContext.getAppProfileId());
185+
this.requestContext = RequestContext.create(clientContext.getClientInfo());
190186
this.bulkMutationFlowController =
191187
new FlowController(perOpSettings.bulkMutateRowsSettings.getDynamicFlowControlSettings());
192188
this.bulkMutationDynamicFlowControlStats = new DynamicFlowControlStats();

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/Util.java

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import com.google.bigtable.v2.TableName;
4646
import com.google.cloud.bigtable.Version;
4747
import com.google.cloud.bigtable.data.v2.BigtableDataSettings;
48+
import com.google.cloud.bigtable.data.v2.internal.csm.attributes.ClientInfo;
4849
import com.google.cloud.bigtable.data.v2.stub.MetadataExtractorInterceptor;
4950
import com.google.common.base.Suppliers;
5051
import com.google.common.collect.ImmutableList;
@@ -241,14 +242,18 @@ public static String formatZoneIdMetricLabel(
241242
.orElse("global");
242243
}
243244

244-
public static ApiTracerFactory createOCTracingFactory(
245-
InstanceName instanceName, String appProfileId) {
245+
public static ApiTracerFactory createOCTracingFactory(ClientInfo clientInfo) {
246246
return new OpencensusTracerFactory(
247247
ImmutableMap.<String, String>builder()
248248
// Annotate traces with the same tags as metrics
249-
.put(RpcMeasureConstants.BIGTABLE_PROJECT_ID.getName(), instanceName.getProject())
250-
.put(RpcMeasureConstants.BIGTABLE_INSTANCE_ID.getName(), instanceName.getInstance())
251-
.put(RpcMeasureConstants.BIGTABLE_APP_PROFILE_ID.getName(), appProfileId)
249+
.put(
250+
RpcMeasureConstants.BIGTABLE_PROJECT_ID.getName(),
251+
clientInfo.getInstanceName().getProject())
252+
.put(
253+
RpcMeasureConstants.BIGTABLE_INSTANCE_ID.getName(),
254+
clientInfo.getInstanceName().getInstance())
255+
.put(
256+
RpcMeasureConstants.BIGTABLE_APP_PROFILE_ID.getName(), clientInfo.getAppProfileId())
252257
// Also annotate traces with library versions
253258
.put("gax", GaxGrpcProperties.getGaxGrpcVersion())
254259
.put("grpc", GaxGrpcProperties.getGrpcVersion())
@@ -257,30 +262,33 @@ public static ApiTracerFactory createOCTracingFactory(
257262
}
258263

259264
public static ApiTracerFactory createOCMetricsFactory(
260-
InstanceName instanceName, String appProfileId, Tagger tagger, StatsRecorder stats) {
265+
ClientInfo clientInfo, Tagger tagger, StatsRecorder stats) {
261266

262267
ImmutableMap<TagKey, TagValue> attributes =
263268
ImmutableMap.<TagKey, TagValue>builder()
264269
.put(
265-
RpcMeasureConstants.BIGTABLE_PROJECT_ID, TagValue.create(instanceName.getProject()))
270+
RpcMeasureConstants.BIGTABLE_PROJECT_ID,
271+
TagValue.create(clientInfo.getInstanceName().getProject()))
266272
.put(
267273
RpcMeasureConstants.BIGTABLE_INSTANCE_ID,
268-
TagValue.create(instanceName.getInstance()))
269-
.put(RpcMeasureConstants.BIGTABLE_APP_PROFILE_ID, TagValue.create(appProfileId))
274+
TagValue.create(clientInfo.getInstanceName().getInstance()))
275+
.put(
276+
RpcMeasureConstants.BIGTABLE_APP_PROFILE_ID,
277+
TagValue.create(clientInfo.getAppProfileId()))
270278
.build();
271279
return MetricsTracerFactory.create(tagger, stats, attributes);
272280
}
273281

274282
public static BuiltinMetricsTracerFactory createOtelMetricsFactory(
275-
OpenTelemetry otel, InstanceName instanceName, String appProfileId) throws IOException {
283+
OpenTelemetry otel, ClientInfo clientInfo) throws IOException {
276284
Attributes attributes =
277285
Attributes.of(
278286
BIGTABLE_PROJECT_ID_KEY,
279-
instanceName.getProject(),
287+
clientInfo.getInstanceName().getProject(),
280288
INSTANCE_ID_KEY,
281-
instanceName.getInstance(),
289+
clientInfo.getInstanceName().getInstance(),
282290
APP_PROFILE_KEY,
283-
appProfileId,
291+
clientInfo.getAppProfileId(),
284292
CLIENT_NAME_KEY,
285293
"bigtable-java/" + Version.VERSION);
286294
return BuiltinMetricsTracerFactory.create(otel, attributes);

0 commit comments

Comments
 (0)