Skip to content

Commit 14143f4

Browse files
committed
refactor: reuse gax ErrorTypeUtil and ObservabilityAttributes in bigquery
1 parent ce4969b commit 14143f4

4 files changed

Lines changed: 17 additions & 148 deletions

File tree

java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/telemetry/BigQueryTelemetryTracer.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import com.google.api.client.googleapis.json.GoogleJsonError;
2020
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
2121
import com.google.api.core.InternalApi;
22+
import com.google.api.gax.tracing.ErrorTypeUtil;
23+
import com.google.api.gax.tracing.ObservabilityAttributes;
2224
import io.opentelemetry.api.common.AttributeKey;
2325
import io.opentelemetry.api.trace.Span;
2426
import io.opentelemetry.api.trace.StatusCode;
@@ -37,27 +39,30 @@ private BigQueryTelemetryTracer() {}
3739
// https://github.com/googleapis/google-cloud-java/issues/12099
3840
// Common GCP Attributes
3941
public static final AttributeKey<String> GCP_CLIENT_SERVICE =
40-
AttributeKey.stringKey("gcp.client.service");
42+
AttributeKey.stringKey(ObservabilityAttributes.GCP_CLIENT_SERVICE_ATTRIBUTE);
4143
public static final AttributeKey<String> GCP_CLIENT_VERSION =
4244
AttributeKey.stringKey("gcp.client.version");
4345
public static final AttributeKey<String> GCP_CLIENT_REPO =
44-
AttributeKey.stringKey("gcp.client.repo");
46+
AttributeKey.stringKey(ObservabilityAttributes.REPO_ATTRIBUTE);
4547
public static final AttributeKey<String> GCP_CLIENT_ARTIFACT =
4648
AttributeKey.stringKey("gcp.client.artifact");
4749
public static final AttributeKey<String> GCP_RESOURCE_DESTINATION_ID =
48-
AttributeKey.stringKey("gcp.resource.destination.id");
50+
AttributeKey.stringKey(ObservabilityAttributes.DESTINATION_RESOURCE_ID_ATTRIBUTE);
4951
public static final AttributeKey<String> RPC_SYSTEM_NAME =
50-
AttributeKey.stringKey("rpc.system.name");
52+
AttributeKey.stringKey(ObservabilityAttributes.RPC_SYSTEM_NAME_ATTRIBUTE);
5153

5254
// Common Error Attributes
53-
public static final AttributeKey<String> ERROR_TYPE = AttributeKey.stringKey("error.type");
55+
public static final AttributeKey<String> ERROR_TYPE =
56+
AttributeKey.stringKey(ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE);
5457
public static final AttributeKey<String> EXCEPTION_TYPE =
55-
AttributeKey.stringKey("exception.type");
58+
AttributeKey.stringKey(ObservabilityAttributes.EXCEPTION_TYPE_ATTRIBUTE);
5659
public static final AttributeKey<String> STATUS_MESSAGE =
57-
AttributeKey.stringKey("status.message");
60+
AttributeKey.stringKey(ObservabilityAttributes.STATUS_MESSAGE_ATTRIBUTE);
5861

59-
public static final AttributeKey<String> URL_TEMPLATE = AttributeKey.stringKey("url.template");
60-
public static final AttributeKey<String> URL_DOMAIN = AttributeKey.stringKey("url.domain");
62+
public static final AttributeKey<String> URL_TEMPLATE =
63+
AttributeKey.stringKey(ObservabilityAttributes.URL_TEMPLATE_ATTRIBUTE);
64+
public static final AttributeKey<String> URL_DOMAIN =
65+
AttributeKey.stringKey(ObservabilityAttributes.URL_DOMAIN_ATTRIBUTE);
6166

6267
public static void addCommonAttributeToSpan(Span span) {
6368
span.setAttribute(GCP_CLIENT_SERVICE, BQ_GCP_CLIENT_SERVICE)
@@ -78,7 +83,7 @@ public static void addExceptionToSpan(Exception e, Span span) {
7883
String statusMessage = simpleName + (message != null ? ": " + message : "");
7984
span.setAttribute(BigQueryTelemetryTracer.EXCEPTION_TYPE, e.getClass().getName());
8085
span.setAttribute(
81-
BigQueryTelemetryTracer.ERROR_TYPE, ErrorTypeUtil.getClientErrorType(e).toString());
86+
BigQueryTelemetryTracer.ERROR_TYPE, ErrorTypeUtil.extractErrorType(e));
8287
span.setAttribute(BigQueryTelemetryTracer.STATUS_MESSAGE, statusMessage);
8388
span.setStatus(StatusCode.ERROR, statusMessage);
8489
}

java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/telemetry/ErrorTypeUtil.java

Lines changed: 0 additions & 70 deletions
This file was deleted.

java-bigquery/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/telemetry/BigQueryTelemetryTracerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public void testAddExceptionToSpan_WithMessage() {
143143
assertEquals(
144144
"java.lang.Exception",
145145
spanData.getAttributes().get(BigQueryTelemetryTracer.EXCEPTION_TYPE));
146-
assertErrorSpanAttributes("CLIENT_UNKNOWN_ERROR", "Exception: Test error message");
146+
assertErrorSpanAttributes("Exception", "Exception: Test error message");
147147
}
148148

149149
@Test
@@ -161,7 +161,7 @@ public void testAddExceptionToSpan_NoMessage() {
161161
spanData.getAttributes().get(BigQueryTelemetryTracer.EXCEPTION_TYPE));
162162
assertEquals("Exception", spanData.getAttributes().get(BigQueryTelemetryTracer.STATUS_MESSAGE));
163163
assertEquals(
164-
"CLIENT_UNKNOWN_ERROR", spanData.getAttributes().get(BigQueryTelemetryTracer.ERROR_TYPE));
164+
"Exception", spanData.getAttributes().get(BigQueryTelemetryTracer.ERROR_TYPE));
165165
}
166166

167167
@Test

java-bigquery/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/telemetry/ErrorTypeUtilTest.java

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)