Skip to content

Commit b9ae73f

Browse files
lqiu96alicejlidiegomarquezp
authored
fix: Use ServiceName + MethodName as the regex for Otel (#2543)
Fixes: #2502 Use a consistent Regex matching pattern for both gRPC and HttpJson. Copy the pattern used for gRPC into HttpJson. Looking at the Method Descriptor for HttpJson (Compute as an example), the full method name does not match `service.resource.action`: https://github.com/googleapis/google-cloud-java/blob/1f9e63224424327a08e3663985773546b3f7808b/java-compute/google-cloud-compute/src/main/java/com/google/cloud/compute/v1/stub/HttpJsonBackendServicesStub.java#L85 It seems to match `ServiceName/MethodName`. --------- Co-authored-by: Alice <65933803+alicejli@users.noreply.github.com> Co-authored-by: Diego Marquez <diegomarquezp@google.com>
1 parent 774fe6e commit b9ae73f

File tree

6 files changed

+23
-25
lines changed

6 files changed

+23
-25
lines changed

gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallableFactory.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,8 @@
5252

5353
/** Class with utility methods to create http/json-based direct callables. */
5454
public class HttpJsonCallableFactory {
55-
// Used to extract service and method name from a grpc MethodDescriptor.
56-
// fullMethodName has the format: service.resource.action
57-
// For example: compute.instances.addAccessConfig
58-
private static final Pattern FULL_METHOD_NAME_REGEX = Pattern.compile("^(.+)\\.(.+)$");
55+
// Used to extract service and method name from a HttpJson MethodDescriptor.
56+
private static final Pattern FULL_METHOD_NAME_REGEX = Pattern.compile("^.*?([^./]+)/([^./]+)$");
5957

6058
private HttpJsonCallableFactory() {}
6159

gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonCallableFactoryTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ class HttpJsonCallableFactoryTest {
4747
void testGetSpanName() {
4848
Map<String, SpanName> validNames =
4949
ImmutableMap.of(
50-
"compute.projects.disableXpnHost", SpanName.of("compute.projects", "disableXpnHost"),
51-
"client.method", SpanName.of("client", "method"));
50+
"google.cloud.service.v1.CoolService/CoolRPC", SpanName.of("CoolService", "CoolRPC"),
51+
"CoolService/CoolRPC", SpanName.of("CoolService", "CoolRPC"));
5252

5353
for (Entry<String, SpanName> entry : validNames.entrySet()) {
5454
@SuppressWarnings("unchecked")

java-showcase-3.21.0/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITOtelMetrics.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ void testHttpJson_operationSucceeded_recordsMetrics() throws InterruptedExceptio
349349
Map<String, String> expectedAttributes =
350350
ImmutableMap.of(
351351
MetricsTracer.METHOD_ATTRIBUTE,
352-
"google.showcase.v1beta1.Echo/Echo",
352+
"Echo.Echo",
353353
MetricsTracer.LANGUAGE_ATTRIBUTE,
354354
MetricsTracer.DEFAULT_LANGUAGE);
355355
verifyDefaultMetricsAttributes(actualMetricDataList, expectedAttributes);
@@ -406,7 +406,7 @@ void testHttpJson_operationCancelled_recordsMetrics() throws Exception {
406406
Map<String, String> expectedAttributes =
407407
ImmutableMap.of(
408408
MetricsTracer.METHOD_ATTRIBUTE,
409-
"google.showcase.v1beta1.Echo/Block",
409+
"Echo.Block",
410410
MetricsTracer.LANGUAGE_ATTRIBUTE,
411411
MetricsTracer.DEFAULT_LANGUAGE);
412412
verifyDefaultMetricsAttributes(actualMetricDataList, expectedAttributes);
@@ -464,7 +464,7 @@ void testHttpJson_operationFailed_recordsMetrics() throws InterruptedException {
464464
Map<String, String> expectedAttributes =
465465
ImmutableMap.of(
466466
MetricsTracer.METHOD_ATTRIBUTE,
467-
"google.showcase.v1beta1.Echo/Block",
467+
"Echo.Block",
468468
MetricsTracer.LANGUAGE_ATTRIBUTE,
469469
MetricsTracer.DEFAULT_LANGUAGE);
470470
verifyDefaultMetricsAttributes(actualMetricDataList, expectedAttributes);
@@ -588,7 +588,7 @@ void testHttpJson_attemptFailedRetriesExhausted_recordsMetrics() throws Exceptio
588588
Map<String, String> expectedAttributes =
589589
ImmutableMap.of(
590590
MetricsTracer.METHOD_ATTRIBUTE,
591-
"google.showcase.v1beta1.Echo/Echo",
591+
"Echo.Echo",
592592
MetricsTracer.LANGUAGE_ATTRIBUTE,
593593
MetricsTracer.DEFAULT_LANGUAGE);
594594
verifyDefaultMetricsAttributes(actualMetricDataList, expectedAttributes);
@@ -645,7 +645,7 @@ void testHttpJson_attemptPermanentFailure_recordsMetrics() throws InterruptedExc
645645
Map<String, String> expectedAttributes =
646646
ImmutableMap.of(
647647
MetricsTracer.METHOD_ATTRIBUTE,
648-
"google.showcase.v1beta1.Echo/Block",
648+
"Echo.Block",
649649
MetricsTracer.LANGUAGE_ATTRIBUTE,
650650
MetricsTracer.DEFAULT_LANGUAGE);
651651
verifyDefaultMetricsAttributes(actualMetricDataList, expectedAttributes);
@@ -777,7 +777,7 @@ void testHttpJson_multipleFailedAttempts_successfulOperation() throws Exception
777777
Map<String, String> expectedAttributes =
778778
ImmutableMap.of(
779779
MetricsTracer.METHOD_ATTRIBUTE,
780-
"google.showcase.v1beta1.Echo/Block",
780+
"Echo.Block",
781781
MetricsTracer.LANGUAGE_ATTRIBUTE,
782782
MetricsTracer.DEFAULT_LANGUAGE);
783783
verifyDefaultMetricsAttributes(actualMetricDataList, expectedAttributes);

java-showcase-3.25.8/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITOtelMetrics.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ void testHttpJson_operationSucceeded_recordsMetrics() throws InterruptedExceptio
349349
Map<String, String> expectedAttributes =
350350
ImmutableMap.of(
351351
MetricsTracer.METHOD_ATTRIBUTE,
352-
"google.showcase.v1beta1.Echo/Echo",
352+
"Echo.Echo",
353353
MetricsTracer.LANGUAGE_ATTRIBUTE,
354354
MetricsTracer.DEFAULT_LANGUAGE);
355355
verifyDefaultMetricsAttributes(actualMetricDataList, expectedAttributes);
@@ -406,7 +406,7 @@ void testHttpJson_operationCancelled_recordsMetrics() throws Exception {
406406
Map<String, String> expectedAttributes =
407407
ImmutableMap.of(
408408
MetricsTracer.METHOD_ATTRIBUTE,
409-
"google.showcase.v1beta1.Echo/Block",
409+
"Echo.Block",
410410
MetricsTracer.LANGUAGE_ATTRIBUTE,
411411
MetricsTracer.DEFAULT_LANGUAGE);
412412
verifyDefaultMetricsAttributes(actualMetricDataList, expectedAttributes);
@@ -464,7 +464,7 @@ void testHttpJson_operationFailed_recordsMetrics() throws InterruptedException {
464464
Map<String, String> expectedAttributes =
465465
ImmutableMap.of(
466466
MetricsTracer.METHOD_ATTRIBUTE,
467-
"google.showcase.v1beta1.Echo/Block",
467+
"Echo.Block",
468468
MetricsTracer.LANGUAGE_ATTRIBUTE,
469469
MetricsTracer.DEFAULT_LANGUAGE);
470470
verifyDefaultMetricsAttributes(actualMetricDataList, expectedAttributes);
@@ -588,7 +588,7 @@ void testHttpJson_attemptFailedRetriesExhausted_recordsMetrics() throws Exceptio
588588
Map<String, String> expectedAttributes =
589589
ImmutableMap.of(
590590
MetricsTracer.METHOD_ATTRIBUTE,
591-
"google.showcase.v1beta1.Echo/Echo",
591+
"Echo.Echo",
592592
MetricsTracer.LANGUAGE_ATTRIBUTE,
593593
MetricsTracer.DEFAULT_LANGUAGE);
594594
verifyDefaultMetricsAttributes(actualMetricDataList, expectedAttributes);
@@ -645,7 +645,7 @@ void testHttpJson_attemptPermanentFailure_recordsMetrics() throws InterruptedExc
645645
Map<String, String> expectedAttributes =
646646
ImmutableMap.of(
647647
MetricsTracer.METHOD_ATTRIBUTE,
648-
"google.showcase.v1beta1.Echo/Block",
648+
"Echo.Block",
649649
MetricsTracer.LANGUAGE_ATTRIBUTE,
650650
MetricsTracer.DEFAULT_LANGUAGE);
651651
verifyDefaultMetricsAttributes(actualMetricDataList, expectedAttributes);
@@ -777,7 +777,7 @@ void testHttpJson_multipleFailedAttempts_successfulOperation() throws Exception
777777
Map<String, String> expectedAttributes =
778778
ImmutableMap.of(
779779
MetricsTracer.METHOD_ATTRIBUTE,
780-
"google.showcase.v1beta1.Echo/Block",
780+
"Echo.Block",
781781
MetricsTracer.LANGUAGE_ATTRIBUTE,
782782
MetricsTracer.DEFAULT_LANGUAGE);
783783
verifyDefaultMetricsAttributes(actualMetricDataList, expectedAttributes);

java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITOtelMetrics.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ void testHttpJson_operationSucceeded_recordsMetrics() throws InterruptedExceptio
349349
Map<String, String> expectedAttributes =
350350
ImmutableMap.of(
351351
MetricsTracer.METHOD_ATTRIBUTE,
352-
"google.showcase.v1beta1.Echo/Echo",
352+
"Echo.Echo",
353353
MetricsTracer.LANGUAGE_ATTRIBUTE,
354354
MetricsTracer.DEFAULT_LANGUAGE);
355355
verifyDefaultMetricsAttributes(actualMetricDataList, expectedAttributes);
@@ -406,7 +406,7 @@ void testHttpJson_operationCancelled_recordsMetrics() throws Exception {
406406
Map<String, String> expectedAttributes =
407407
ImmutableMap.of(
408408
MetricsTracer.METHOD_ATTRIBUTE,
409-
"google.showcase.v1beta1.Echo/Block",
409+
"Echo.Block",
410410
MetricsTracer.LANGUAGE_ATTRIBUTE,
411411
MetricsTracer.DEFAULT_LANGUAGE);
412412
verifyDefaultMetricsAttributes(actualMetricDataList, expectedAttributes);
@@ -464,7 +464,7 @@ void testHttpJson_operationFailed_recordsMetrics() throws InterruptedException {
464464
Map<String, String> expectedAttributes =
465465
ImmutableMap.of(
466466
MetricsTracer.METHOD_ATTRIBUTE,
467-
"google.showcase.v1beta1.Echo/Block",
467+
"Echo.Block",
468468
MetricsTracer.LANGUAGE_ATTRIBUTE,
469469
MetricsTracer.DEFAULT_LANGUAGE);
470470
verifyDefaultMetricsAttributes(actualMetricDataList, expectedAttributes);
@@ -588,7 +588,7 @@ void testHttpJson_attemptFailedRetriesExhausted_recordsMetrics() throws Exceptio
588588
Map<String, String> expectedAttributes =
589589
ImmutableMap.of(
590590
MetricsTracer.METHOD_ATTRIBUTE,
591-
"google.showcase.v1beta1.Echo/Echo",
591+
"Echo.Echo",
592592
MetricsTracer.LANGUAGE_ATTRIBUTE,
593593
MetricsTracer.DEFAULT_LANGUAGE);
594594
verifyDefaultMetricsAttributes(actualMetricDataList, expectedAttributes);
@@ -645,7 +645,7 @@ void testHttpJson_attemptPermanentFailure_recordsMetrics() throws InterruptedExc
645645
Map<String, String> expectedAttributes =
646646
ImmutableMap.of(
647647
MetricsTracer.METHOD_ATTRIBUTE,
648-
"google.showcase.v1beta1.Echo/Block",
648+
"Echo.Block",
649649
MetricsTracer.LANGUAGE_ATTRIBUTE,
650650
MetricsTracer.DEFAULT_LANGUAGE);
651651
verifyDefaultMetricsAttributes(actualMetricDataList, expectedAttributes);
@@ -777,7 +777,7 @@ void testHttpJson_multipleFailedAttempts_successfulOperation() throws Exception
777777
Map<String, String> expectedAttributes =
778778
ImmutableMap.of(
779779
MetricsTracer.METHOD_ATTRIBUTE,
780-
"google.showcase.v1beta1.Echo/Block",
780+
"Echo.Block",
781781
MetricsTracer.LANGUAGE_ATTRIBUTE,
782782
MetricsTracer.DEFAULT_LANGUAGE);
783783
verifyDefaultMetricsAttributes(actualMetricDataList, expectedAttributes);

java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITOtelTracing.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ void testTracing_successfulEcho_httpjson() throws Exception {
138138

139139
SpanData attemptSpan =
140140
spans.stream()
141-
.filter(span -> span.getName().equals("google.showcase.v1beta1/Echo/Echo/attempt"))
141+
.filter(span -> span.getName().equals("Echo/Echo/attempt"))
142142
.findFirst()
143143
.orElseThrow(() -> new AssertionError("Attempt span 'Echo/Echo/attempt' not found"));
144144
assertThat(attemptSpan.getKind()).isEqualTo(SpanKind.CLIENT);

0 commit comments

Comments
 (0)