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

Commit 5de9d30

Browse files
chore: plumb ClientInfo (#2803)
* chore: plumb ClientInfo Change-Id: I01806d0bbaa6ba95b3a8e66d9b3fa24806c928f0 * wip Change-Id: If6dd6db3cdc3624ff0a4397fad30fa6a47e935b0 * chore: generate libraries at Tue Feb 24 21:47:05 UTC 2026 * chore: generate libraries at Tue Feb 24 21:49:58 UTC 2026 --------- Co-authored-by: cloud-java-bot <cloud-java-bot@google.com>
1 parent d201b00 commit 5de9d30

7 files changed

Lines changed: 114 additions & 100 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/BuiltinMetricsTracerFactory.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@
1616
package com.google.cloud.bigtable.data.v2.stub.metrics;
1717

1818
import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.APPLICATION_BLOCKING_LATENCIES_NAME;
19+
import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.APP_PROFILE_KEY;
1920
import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.ATTEMPT_LATENCIES2_NAME;
2021
import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.ATTEMPT_LATENCIES_NAME;
2122
import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.BATCH_WRITE_FLOW_CONTROL_FACTOR_NAME;
2223
import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.BATCH_WRITE_FLOW_CONTROL_TARGET_QPS_NAME;
24+
import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.BIGTABLE_PROJECT_ID_KEY;
2325
import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.CLIENT_BLOCKING_LATENCIES_NAME;
26+
import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.CLIENT_NAME_KEY;
2427
import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.CONNECTIVITY_ERROR_COUNT_NAME;
2528
import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.FIRST_RESPONSE_LATENCIES_NAME;
29+
import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.INSTANCE_ID_KEY;
2630
import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.METER_NAME;
2731
import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.OPERATION_LATENCIES_NAME;
2832
import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.REMAINING_DEADLINE_NAME;
@@ -34,6 +38,8 @@
3438
import com.google.api.gax.tracing.ApiTracerFactory;
3539
import com.google.api.gax.tracing.BaseApiTracerFactory;
3640
import com.google.api.gax.tracing.SpanName;
41+
import com.google.cloud.bigtable.Version;
42+
import com.google.cloud.bigtable.data.v2.internal.csm.attributes.ClientInfo;
3743
import io.opentelemetry.api.OpenTelemetry;
3844
import io.opentelemetry.api.common.Attributes;
3945
import io.opentelemetry.api.metrics.DoubleGauge;
@@ -68,14 +74,24 @@ public class BuiltinMetricsTracerFactory extends BaseApiTracerFactory {
6874
private final DoubleHistogram batchWriteFlowControlFactorHistogram;
6975

7076
public static BuiltinMetricsTracerFactory create(
71-
OpenTelemetry openTelemetry, Attributes attributes) throws IOException {
72-
return new BuiltinMetricsTracerFactory(openTelemetry, attributes);
77+
OpenTelemetry openTelemetry, ClientInfo clientInfo) throws IOException {
78+
return new BuiltinMetricsTracerFactory(openTelemetry, clientInfo);
7379
}
7480

75-
BuiltinMetricsTracerFactory(OpenTelemetry openTelemetry, Attributes attributes) {
76-
this.attributes = attributes;
81+
BuiltinMetricsTracerFactory(OpenTelemetry openTelemetry, ClientInfo clientInfo) {
7782
Meter meter = openTelemetry.getMeter(METER_NAME);
7883

84+
this.attributes =
85+
Attributes.of(
86+
BIGTABLE_PROJECT_ID_KEY,
87+
clientInfo.getInstanceName().getProject(),
88+
INSTANCE_ID_KEY,
89+
clientInfo.getInstanceName().getInstance(),
90+
APP_PROFILE_KEY,
91+
clientInfo.getAppProfileId(),
92+
CLIENT_NAME_KEY,
93+
"bigtable-java/" + Version.VERSION);
94+
7995
operationLatenciesHistogram =
8096
meter
8197
.histogramBuilder(OPERATION_LATENCIES_NAME)

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

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@
1515
*/
1616
package com.google.cloud.bigtable.data.v2.stub.metrics;
1717

18-
import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.APP_PROFILE_KEY;
19-
import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.BIGTABLE_PROJECT_ID_KEY;
20-
import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.CLIENT_NAME_KEY;
21-
import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.INSTANCE_ID_KEY;
22-
2318
import com.google.api.core.InternalApi;
2419
import com.google.api.gax.grpc.GaxGrpcProperties;
2520
import com.google.api.gax.rpc.ApiCallContext;
@@ -45,6 +40,7 @@
4540
import com.google.bigtable.v2.TableName;
4641
import com.google.cloud.bigtable.Version;
4742
import com.google.cloud.bigtable.data.v2.BigtableDataSettings;
43+
import com.google.cloud.bigtable.data.v2.internal.csm.attributes.ClientInfo;
4844
import com.google.cloud.bigtable.data.v2.stub.MetadataExtractorInterceptor;
4945
import com.google.common.base.Suppliers;
5046
import com.google.common.collect.ImmutableList;
@@ -58,7 +54,6 @@
5854
import io.opencensus.tags.TagValue;
5955
import io.opencensus.tags.Tagger;
6056
import io.opentelemetry.api.OpenTelemetry;
61-
import io.opentelemetry.api.common.Attributes;
6257
import io.opentelemetry.sdk.OpenTelemetrySdk;
6358
import io.opentelemetry.sdk.metrics.InstrumentSelector;
6459
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
@@ -241,14 +236,18 @@ public static String formatZoneIdMetricLabel(
241236
.orElse("global");
242237
}
243238

244-
public static ApiTracerFactory createOCTracingFactory(
245-
InstanceName instanceName, String appProfileId) {
239+
public static ApiTracerFactory createOCTracingFactory(ClientInfo clientInfo) {
246240
return new OpencensusTracerFactory(
247241
ImmutableMap.<String, String>builder()
248242
// 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)
243+
.put(
244+
RpcMeasureConstants.BIGTABLE_PROJECT_ID.getName(),
245+
clientInfo.getInstanceName().getProject())
246+
.put(
247+
RpcMeasureConstants.BIGTABLE_INSTANCE_ID.getName(),
248+
clientInfo.getInstanceName().getInstance())
249+
.put(
250+
RpcMeasureConstants.BIGTABLE_APP_PROFILE_ID.getName(), clientInfo.getAppProfileId())
252251
// Also annotate traces with library versions
253252
.put("gax", GaxGrpcProperties.getGaxGrpcVersion())
254253
.put("grpc", GaxGrpcProperties.getGrpcVersion())
@@ -257,32 +256,25 @@ public static ApiTracerFactory createOCTracingFactory(
257256
}
258257

259258
public static ApiTracerFactory createOCMetricsFactory(
260-
InstanceName instanceName, String appProfileId, Tagger tagger, StatsRecorder stats) {
259+
ClientInfo clientInfo, Tagger tagger, StatsRecorder stats) {
261260

262261
ImmutableMap<TagKey, TagValue> attributes =
263262
ImmutableMap.<TagKey, TagValue>builder()
264263
.put(
265-
RpcMeasureConstants.BIGTABLE_PROJECT_ID, TagValue.create(instanceName.getProject()))
264+
RpcMeasureConstants.BIGTABLE_PROJECT_ID,
265+
TagValue.create(clientInfo.getInstanceName().getProject()))
266266
.put(
267267
RpcMeasureConstants.BIGTABLE_INSTANCE_ID,
268-
TagValue.create(instanceName.getInstance()))
269-
.put(RpcMeasureConstants.BIGTABLE_APP_PROFILE_ID, TagValue.create(appProfileId))
268+
TagValue.create(clientInfo.getInstanceName().getInstance()))
269+
.put(
270+
RpcMeasureConstants.BIGTABLE_APP_PROFILE_ID,
271+
TagValue.create(clientInfo.getAppProfileId()))
270272
.build();
271273
return MetricsTracerFactory.create(tagger, stats, attributes);
272274
}
273275

274276
public static BuiltinMetricsTracerFactory createOtelMetricsFactory(
275-
OpenTelemetry otel, InstanceName instanceName, String appProfileId) throws IOException {
276-
Attributes attributes =
277-
Attributes.of(
278-
BIGTABLE_PROJECT_ID_KEY,
279-
instanceName.getProject(),
280-
INSTANCE_ID_KEY,
281-
instanceName.getInstance(),
282-
APP_PROFILE_KEY,
283-
appProfileId,
284-
CLIENT_NAME_KEY,
285-
"bigtable-java/" + Version.VERSION);
286-
return BuiltinMetricsTracerFactory.create(otel, attributes);
277+
OpenTelemetry otel, ClientInfo clientInfo) {
278+
return new BuiltinMetricsTracerFactory(otel, clientInfo);
287279
}
288280
}

0 commit comments

Comments
 (0)