Skip to content

Commit 592e899

Browse files
feat: Set sampledToLocalTracing flag to true for all gRPC MethodDescriptors (#3874)
See b/416626151 for more information. Problem: When the sampledToLocalTracing is set to false or not set, the gRPC specific metrics have the `grpc.method` attribute defined as `other` instead of the methodDescriptor's full name. This may be confusing to customers who may expect to see the full gRPC method name. High Level: This flag enables captures for specific method names to help provide more detailed metrics. We do not expect any noticeable performance impact from this change. This does not impact the method name that is already properly captured for Gax Metrics (e.g. Attempt Count, Operation Latency, etc). Specifically, the use must be using grpc-java telemetry module and be using [GrpcOpenTelemetry](https://grpc.github.io/grpc-java/javadoc/io/grpc/opentelemetry/GrpcOpenTelemetry.html) instead of [OpenTelemetry](https://github.com/open-telemetry/opentelemetry-java/blob/main/api/all/src/main/java/io/opentelemetry/api/OpenTelemetry.java). --------- Co-authored-by: cloud-java-bot <[email protected]>
1 parent fc80c7b commit 592e899

File tree

37 files changed

+476
-12
lines changed

37 files changed

+476
-12
lines changed

gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/grpc/GrpcServiceStubClassComposer.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.google.api.generator.engine.ast.Expr;
2323
import com.google.api.generator.engine.ast.ExprStatement;
2424
import com.google.api.generator.engine.ast.MethodInvocationExpr;
25+
import com.google.api.generator.engine.ast.PrimitiveValue;
2526
import com.google.api.generator.engine.ast.ScopeNode;
2627
import com.google.api.generator.engine.ast.Statement;
2728
import com.google.api.generator.engine.ast.StringObjectValue;
@@ -140,6 +141,16 @@ protected Statement createMethodDescriptorVariableDecl(
140141
.apply("setResponseMarshaller", protoUtilsMarshallerFn.apply(methodInvocationArg))
141142
.apply(methodDescriptorMaker);
142143

144+
// The sampledToLocalTracing flag is set to true for all gRPC MethodDescriptors in GAPICs
145+
// This flag enables captures for specific method names to help provide more detailed metrics
146+
methodDescriptorMaker =
147+
methodMakerFn
148+
.apply(
149+
"setSampledToLocalTracing",
150+
ValueExpr.withValue(
151+
PrimitiveValue.builder().setType(TypeNode.BOOLEAN).setValue("true").build()))
152+
.apply(methodDescriptorMaker);
153+
143154
methodDescriptorMaker =
144155
MethodInvocationExpr.builder()
145156
.setMethodName("build")

gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/GrpcAutoPopulateFieldStub.golden

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public class GrpcAutoPopulateFieldTestingStub extends AutoPopulateFieldTestingSt
4242
ProtoUtils.marshaller(AutoPopulateFieldTestingEchoRequest.getDefaultInstance()))
4343
.setResponseMarshaller(
4444
ProtoUtils.marshaller(AutoPopulateFieldTestingEchoResponse.getDefaultInstance()))
45+
.setSampledToLocalTracing(true)
4546
.build();
4647

4748
private static final MethodDescriptor<
@@ -57,6 +58,7 @@ public class GrpcAutoPopulateFieldTestingStub extends AutoPopulateFieldTestingSt
5758
ProtoUtils.marshaller(AutoPopulateFieldTestingExpandRequest.getDefaultInstance()))
5859
.setResponseMarshaller(
5960
ProtoUtils.marshaller(AutoPopulateFieldTestingEchoResponse.getDefaultInstance()))
61+
.setSampledToLocalTracing(true)
6062
.build();
6163

6264
private static final MethodDescriptor<
@@ -72,6 +74,7 @@ public class GrpcAutoPopulateFieldTestingStub extends AutoPopulateFieldTestingSt
7274
ProtoUtils.marshaller(AutoPopulateFieldTestingEchoRequest.getDefaultInstance()))
7375
.setResponseMarshaller(
7476
ProtoUtils.marshaller(AutoPopulateFieldTestingEchoResponse.getDefaultInstance()))
77+
.setSampledToLocalTracing(true)
7578
.build();
7679

7780
private static final MethodDescriptor<
@@ -87,6 +90,7 @@ public class GrpcAutoPopulateFieldTestingStub extends AutoPopulateFieldTestingSt
8790
ProtoUtils.marshaller(AutoPopulateFieldTestingEchoRequest.getDefaultInstance()))
8891
.setResponseMarshaller(
8992
ProtoUtils.marshaller(AutoPopulateFieldTestingEchoResponse.getDefaultInstance()))
93+
.setSampledToLocalTracing(true)
9094
.build();
9195

9296
private final UnaryCallable<

gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/GrpcBigQueryJobServiceStub.golden

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class GrpcJobServiceStub extends JobServiceStub {
3535
.setRequestMarshaller(
3636
ProtoUtils.marshaller(JobProto.DeleteJobRequest.getDefaultInstance()))
3737
.setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance()))
38+
.setSampledToLocalTracing(true)
3839
.build();
3940

4041
private static final MethodDescriptor<JobProto.ListJobsRequest, JobProto.JobList>
@@ -45,6 +46,7 @@ public class GrpcJobServiceStub extends JobServiceStub {
4546
.setRequestMarshaller(
4647
ProtoUtils.marshaller(JobProto.ListJobsRequest.getDefaultInstance()))
4748
.setResponseMarshaller(ProtoUtils.marshaller(JobProto.JobList.getDefaultInstance()))
49+
.setSampledToLocalTracing(true)
4850
.build();
4951

5052
private final UnaryCallable<JobProto.DeleteJobRequest, Empty> deleteJobCallable;

gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/GrpcCallableNameTypeStub.golden

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class GrpcCallableNameTypeServiceStub extends CallableNameTypeServiceStub
3333
.setRequestMarshaller(
3434
ProtoUtils.marshaller(GetApiOperationRequest.getDefaultInstance()))
3535
.setResponseMarshaller(ProtoUtils.marshaller(ApiOperation.getDefaultInstance()))
36+
.setSampledToLocalTracing(true)
3637
.build();
3738

3839
private static final MethodDescriptor<GetApiOperationRequest, ApiOperation>
@@ -43,6 +44,7 @@ public class GrpcCallableNameTypeServiceStub extends CallableNameTypeServiceStub
4344
.setRequestMarshaller(
4445
ProtoUtils.marshaller(GetApiOperationRequest.getDefaultInstance()))
4546
.setResponseMarshaller(ProtoUtils.marshaller(ApiOperation.getDefaultInstance()))
47+
.setSampledToLocalTracing(true)
4648
.build();
4749

4850
private final UnaryCallable<GetApiOperationRequest, ApiOperation> getApiOperationCallable;

gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/GrpcDeprecatedServiceStub.golden

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class GrpcDeprecatedServiceStub extends DeprecatedServiceStub {
3232
.setFullMethodName("google.testdata.v1.DeprecatedService/FastFibonacci")
3333
.setRequestMarshaller(ProtoUtils.marshaller(FibonacciRequest.getDefaultInstance()))
3434
.setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance()))
35+
.setSampledToLocalTracing(true)
3536
.build();
3637

3738
private static final MethodDescriptor<FibonacciRequest, Empty> slowFibonacciMethodDescriptor =
@@ -40,6 +41,7 @@ public class GrpcDeprecatedServiceStub extends DeprecatedServiceStub {
4041
.setFullMethodName("google.testdata.v1.DeprecatedService/SlowFibonacci")
4142
.setRequestMarshaller(ProtoUtils.marshaller(FibonacciRequest.getDefaultInstance()))
4243
.setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance()))
44+
.setSampledToLocalTracing(true)
4345
.build();
4446

4547
private final UnaryCallable<FibonacciRequest, Empty> fastFibonacciCallable;

gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/GrpcEchoStub.golden

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public class GrpcEchoStub extends EchoStub {
4949
.setFullMethodName("google.showcase.v1beta1.Echo/Echo")
5050
.setRequestMarshaller(ProtoUtils.marshaller(EchoRequest.getDefaultInstance()))
5151
.setResponseMarshaller(ProtoUtils.marshaller(EchoResponse.getDefaultInstance()))
52+
.setSampledToLocalTracing(true)
5253
.build();
5354

5455
private static final MethodDescriptor<ExpandRequest, EchoResponse> expandMethodDescriptor =
@@ -57,6 +58,7 @@ public class GrpcEchoStub extends EchoStub {
5758
.setFullMethodName("google.showcase.v1beta1.Echo/Expand")
5859
.setRequestMarshaller(ProtoUtils.marshaller(ExpandRequest.getDefaultInstance()))
5960
.setResponseMarshaller(ProtoUtils.marshaller(EchoResponse.getDefaultInstance()))
61+
.setSampledToLocalTracing(true)
6062
.build();
6163

6264
private static final MethodDescriptor<EchoRequest, EchoResponse> collectMethodDescriptor =
@@ -65,6 +67,7 @@ public class GrpcEchoStub extends EchoStub {
6567
.setFullMethodName("google.showcase.v1beta1.Echo/Collect")
6668
.setRequestMarshaller(ProtoUtils.marshaller(EchoRequest.getDefaultInstance()))
6769
.setResponseMarshaller(ProtoUtils.marshaller(EchoResponse.getDefaultInstance()))
70+
.setSampledToLocalTracing(true)
6871
.build();
6972

7073
private static final MethodDescriptor<EchoRequest, EchoResponse> chatMethodDescriptor =
@@ -73,6 +76,7 @@ public class GrpcEchoStub extends EchoStub {
7376
.setFullMethodName("google.showcase.v1beta1.Echo/Chat")
7477
.setRequestMarshaller(ProtoUtils.marshaller(EchoRequest.getDefaultInstance()))
7578
.setResponseMarshaller(ProtoUtils.marshaller(EchoResponse.getDefaultInstance()))
79+
.setSampledToLocalTracing(true)
7680
.build();
7781

7882
private static final MethodDescriptor<EchoRequest, EchoResponse> chatAgainMethodDescriptor =
@@ -81,6 +85,7 @@ public class GrpcEchoStub extends EchoStub {
8185
.setFullMethodName("google.showcase.v1beta1.Echo/ChatAgain")
8286
.setRequestMarshaller(ProtoUtils.marshaller(EchoRequest.getDefaultInstance()))
8387
.setResponseMarshaller(ProtoUtils.marshaller(EchoResponse.getDefaultInstance()))
88+
.setSampledToLocalTracing(true)
8489
.build();
8590

8691
private static final MethodDescriptor<PagedExpandRequest, PagedExpandResponse>
@@ -91,6 +96,7 @@ public class GrpcEchoStub extends EchoStub {
9196
.setRequestMarshaller(ProtoUtils.marshaller(PagedExpandRequest.getDefaultInstance()))
9297
.setResponseMarshaller(
9398
ProtoUtils.marshaller(PagedExpandResponse.getDefaultInstance()))
99+
.setSampledToLocalTracing(true)
94100
.build();
95101

96102
private static final MethodDescriptor<PagedExpandRequest, PagedExpandResponse>
@@ -101,6 +107,7 @@ public class GrpcEchoStub extends EchoStub {
101107
.setRequestMarshaller(ProtoUtils.marshaller(PagedExpandRequest.getDefaultInstance()))
102108
.setResponseMarshaller(
103109
ProtoUtils.marshaller(PagedExpandResponse.getDefaultInstance()))
110+
.setSampledToLocalTracing(true)
104111
.build();
105112

106113
private static final MethodDescriptor<WaitRequest, Operation> waitMethodDescriptor =
@@ -109,6 +116,7 @@ public class GrpcEchoStub extends EchoStub {
109116
.setFullMethodName("google.showcase.v1beta1.Echo/Wait")
110117
.setRequestMarshaller(ProtoUtils.marshaller(WaitRequest.getDefaultInstance()))
111118
.setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance()))
119+
.setSampledToLocalTracing(true)
112120
.build();
113121

114122
private static final MethodDescriptor<BlockRequest, BlockResponse> blockMethodDescriptor =
@@ -117,6 +125,7 @@ public class GrpcEchoStub extends EchoStub {
117125
.setFullMethodName("google.showcase.v1beta1.Echo/Block")
118126
.setRequestMarshaller(ProtoUtils.marshaller(BlockRequest.getDefaultInstance()))
119127
.setResponseMarshaller(ProtoUtils.marshaller(BlockResponse.getDefaultInstance()))
128+
.setSampledToLocalTracing(true)
120129
.build();
121130

122131
private static final MethodDescriptor<EchoRequest, Object> collideNameMethodDescriptor =
@@ -125,6 +134,7 @@ public class GrpcEchoStub extends EchoStub {
125134
.setFullMethodName("google.showcase.v1beta1.Echo/CollideName")
126135
.setRequestMarshaller(ProtoUtils.marshaller(EchoRequest.getDefaultInstance()))
127136
.setResponseMarshaller(ProtoUtils.marshaller(Object.getDefaultInstance()))
137+
.setSampledToLocalTracing(true)
128138
.build();
129139

130140
private static final MethodDescriptor<PagedExpandLegacyRequest, PagedExpandResponse>
@@ -136,6 +146,7 @@ public class GrpcEchoStub extends EchoStub {
136146
ProtoUtils.marshaller(PagedExpandLegacyRequest.getDefaultInstance()))
137147
.setResponseMarshaller(
138148
ProtoUtils.marshaller(PagedExpandResponse.getDefaultInstance()))
149+
.setSampledToLocalTracing(true)
139150
.build();
140151

141152
private final UnaryCallable<EchoRequest, EchoResponse> echoCallable;

gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/GrpcLoggingStub.golden

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public class GrpcLoggingServiceV2Stub extends LoggingServiceV2Stub {
4646
.setFullMethodName("google.logging.v2.LoggingServiceV2/DeleteLog")
4747
.setRequestMarshaller(ProtoUtils.marshaller(DeleteLogRequest.getDefaultInstance()))
4848
.setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance()))
49+
.setSampledToLocalTracing(true)
4950
.build();
5051

5152
private static final MethodDescriptor<WriteLogEntriesRequest, WriteLogEntriesResponse>
@@ -57,6 +58,7 @@ public class GrpcLoggingServiceV2Stub extends LoggingServiceV2Stub {
5758
ProtoUtils.marshaller(WriteLogEntriesRequest.getDefaultInstance()))
5859
.setResponseMarshaller(
5960
ProtoUtils.marshaller(WriteLogEntriesResponse.getDefaultInstance()))
61+
.setSampledToLocalTracing(true)
6062
.build();
6163

6264
private static final MethodDescriptor<ListLogEntriesRequest, ListLogEntriesResponse>
@@ -68,6 +70,7 @@ public class GrpcLoggingServiceV2Stub extends LoggingServiceV2Stub {
6870
ProtoUtils.marshaller(ListLogEntriesRequest.getDefaultInstance()))
6971
.setResponseMarshaller(
7072
ProtoUtils.marshaller(ListLogEntriesResponse.getDefaultInstance()))
73+
.setSampledToLocalTracing(true)
7174
.build();
7275

7376
private static final MethodDescriptor<
@@ -85,6 +88,7 @@ public class GrpcLoggingServiceV2Stub extends LoggingServiceV2Stub {
8588
.setResponseMarshaller(
8689
ProtoUtils.marshaller(
8790
ListMonitoredResourceDescriptorsResponse.getDefaultInstance()))
91+
.setSampledToLocalTracing(true)
8892
.build();
8993

9094
private static final MethodDescriptor<ListLogsRequest, ListLogsResponse>
@@ -94,6 +98,7 @@ public class GrpcLoggingServiceV2Stub extends LoggingServiceV2Stub {
9498
.setFullMethodName("google.logging.v2.LoggingServiceV2/ListLogs")
9599
.setRequestMarshaller(ProtoUtils.marshaller(ListLogsRequest.getDefaultInstance()))
96100
.setResponseMarshaller(ProtoUtils.marshaller(ListLogsResponse.getDefaultInstance()))
101+
.setSampledToLocalTracing(true)
97102
.build();
98103

99104
private static final MethodDescriptor<TailLogEntriesRequest, TailLogEntriesResponse>
@@ -105,6 +110,7 @@ public class GrpcLoggingServiceV2Stub extends LoggingServiceV2Stub {
105110
ProtoUtils.marshaller(TailLogEntriesRequest.getDefaultInstance()))
106111
.setResponseMarshaller(
107112
ProtoUtils.marshaller(TailLogEntriesResponse.getDefaultInstance()))
113+
.setSampledToLocalTracing(true)
108114
.build();
109115

110116
private final UnaryCallable<DeleteLogRequest, Empty> deleteLogCallable;

gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/GrpcPublisherStub.golden

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public class GrpcPublisherStub extends PublisherStub {
4848
.setFullMethodName("google.pubsub.v1.Publisher/CreateTopic")
4949
.setRequestMarshaller(ProtoUtils.marshaller(Topic.getDefaultInstance()))
5050
.setResponseMarshaller(ProtoUtils.marshaller(Topic.getDefaultInstance()))
51+
.setSampledToLocalTracing(true)
5152
.build();
5253

5354
private static final MethodDescriptor<UpdateTopicRequest, Topic> updateTopicMethodDescriptor =
@@ -56,6 +57,7 @@ public class GrpcPublisherStub extends PublisherStub {
5657
.setFullMethodName("google.pubsub.v1.Publisher/UpdateTopic")
5758
.setRequestMarshaller(ProtoUtils.marshaller(UpdateTopicRequest.getDefaultInstance()))
5859
.setResponseMarshaller(ProtoUtils.marshaller(Topic.getDefaultInstance()))
60+
.setSampledToLocalTracing(true)
5961
.build();
6062

6163
private static final MethodDescriptor<PublishRequest, PublishResponse> publishMethodDescriptor =
@@ -64,6 +66,7 @@ public class GrpcPublisherStub extends PublisherStub {
6466
.setFullMethodName("google.pubsub.v1.Publisher/Publish")
6567
.setRequestMarshaller(ProtoUtils.marshaller(PublishRequest.getDefaultInstance()))
6668
.setResponseMarshaller(ProtoUtils.marshaller(PublishResponse.getDefaultInstance()))
69+
.setSampledToLocalTracing(true)
6770
.build();
6871

6972
private static final MethodDescriptor<GetTopicRequest, Topic> getTopicMethodDescriptor =
@@ -72,6 +75,7 @@ public class GrpcPublisherStub extends PublisherStub {
7275
.setFullMethodName("google.pubsub.v1.Publisher/GetTopic")
7376
.setRequestMarshaller(ProtoUtils.marshaller(GetTopicRequest.getDefaultInstance()))
7477
.setResponseMarshaller(ProtoUtils.marshaller(Topic.getDefaultInstance()))
78+
.setSampledToLocalTracing(true)
7579
.build();
7680

7781
private static final MethodDescriptor<ListTopicsRequest, ListTopicsResponse>
@@ -81,6 +85,7 @@ public class GrpcPublisherStub extends PublisherStub {
8185
.setFullMethodName("google.pubsub.v1.Publisher/ListTopics")
8286
.setRequestMarshaller(ProtoUtils.marshaller(ListTopicsRequest.getDefaultInstance()))
8387
.setResponseMarshaller(ProtoUtils.marshaller(ListTopicsResponse.getDefaultInstance()))
88+
.setSampledToLocalTracing(true)
8489
.build();
8590

8691
private static final MethodDescriptor<
@@ -94,6 +99,7 @@ public class GrpcPublisherStub extends PublisherStub {
9499
ProtoUtils.marshaller(ListTopicSubscriptionsRequest.getDefaultInstance()))
95100
.setResponseMarshaller(
96101
ProtoUtils.marshaller(ListTopicSubscriptionsResponse.getDefaultInstance()))
102+
.setSampledToLocalTracing(true)
97103
.build();
98104

99105
private static final MethodDescriptor<ListTopicSnapshotsRequest, ListTopicSnapshotsResponse>
@@ -105,6 +111,7 @@ public class GrpcPublisherStub extends PublisherStub {
105111
ProtoUtils.marshaller(ListTopicSnapshotsRequest.getDefaultInstance()))
106112
.setResponseMarshaller(
107113
ProtoUtils.marshaller(ListTopicSnapshotsResponse.getDefaultInstance()))
114+
.setSampledToLocalTracing(true)
108115
.build();
109116

110117
private static final MethodDescriptor<DeleteTopicRequest, Empty> deleteTopicMethodDescriptor =
@@ -113,6 +120,7 @@ public class GrpcPublisherStub extends PublisherStub {
113120
.setFullMethodName("google.pubsub.v1.Publisher/DeleteTopic")
114121
.setRequestMarshaller(ProtoUtils.marshaller(DeleteTopicRequest.getDefaultInstance()))
115122
.setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance()))
123+
.setSampledToLocalTracing(true)
116124
.build();
117125

118126
private static final MethodDescriptor<DetachSubscriptionRequest, DetachSubscriptionResponse>
@@ -124,6 +132,7 @@ public class GrpcPublisherStub extends PublisherStub {
124132
ProtoUtils.marshaller(DetachSubscriptionRequest.getDefaultInstance()))
125133
.setResponseMarshaller(
126134
ProtoUtils.marshaller(DetachSubscriptionResponse.getDefaultInstance()))
135+
.setSampledToLocalTracing(true)
127136
.build();
128137

129138
private final UnaryCallable<Topic, Topic> createTopicCallable;

0 commit comments

Comments
 (0)