Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import com.google.api.client.googleapis.json.GoogleJsonError;
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
import com.google.api.core.InternalApi;
import com.google.api.gax.tracing.ErrorTypeUtil;
import com.google.api.gax.tracing.ObservabilityAttributes;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.StatusCode;
Expand All @@ -37,27 +39,30 @@ private BigQueryTelemetryTracer() {}
// https://github.com/googleapis/google-cloud-java/issues/12099
// Common GCP Attributes
public static final AttributeKey<String> GCP_CLIENT_SERVICE =
AttributeKey.stringKey("gcp.client.service");
AttributeKey.stringKey(ObservabilityAttributes.GCP_CLIENT_SERVICE_ATTRIBUTE);
public static final AttributeKey<String> GCP_CLIENT_VERSION =
AttributeKey.stringKey("gcp.client.version");
Comment thread
blakeli0 marked this conversation as resolved.
public static final AttributeKey<String> GCP_CLIENT_REPO =
AttributeKey.stringKey("gcp.client.repo");
AttributeKey.stringKey(ObservabilityAttributes.REPO_ATTRIBUTE);
public static final AttributeKey<String> GCP_CLIENT_ARTIFACT =
AttributeKey.stringKey("gcp.client.artifact");
Comment thread
blakeli0 marked this conversation as resolved.
public static final AttributeKey<String> GCP_RESOURCE_DESTINATION_ID =
AttributeKey.stringKey("gcp.resource.destination.id");
AttributeKey.stringKey(ObservabilityAttributes.DESTINATION_RESOURCE_ID_ATTRIBUTE);
public static final AttributeKey<String> RPC_SYSTEM_NAME =
AttributeKey.stringKey("rpc.system.name");
AttributeKey.stringKey(ObservabilityAttributes.RPC_SYSTEM_NAME_ATTRIBUTE);

// Common Error Attributes
public static final AttributeKey<String> ERROR_TYPE = AttributeKey.stringKey("error.type");
public static final AttributeKey<String> ERROR_TYPE =
AttributeKey.stringKey(ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE);
public static final AttributeKey<String> EXCEPTION_TYPE =
AttributeKey.stringKey("exception.type");
AttributeKey.stringKey(ObservabilityAttributes.EXCEPTION_TYPE_ATTRIBUTE);
public static final AttributeKey<String> STATUS_MESSAGE =
AttributeKey.stringKey("status.message");
AttributeKey.stringKey(ObservabilityAttributes.STATUS_MESSAGE_ATTRIBUTE);

public static final AttributeKey<String> URL_TEMPLATE = AttributeKey.stringKey("url.template");
public static final AttributeKey<String> URL_DOMAIN = AttributeKey.stringKey("url.domain");
public static final AttributeKey<String> URL_TEMPLATE =
AttributeKey.stringKey(ObservabilityAttributes.URL_TEMPLATE_ATTRIBUTE);
public static final AttributeKey<String> URL_DOMAIN =
AttributeKey.stringKey(ObservabilityAttributes.URL_DOMAIN_ATTRIBUTE);

public static void addCommonAttributeToSpan(Span span) {
span.setAttribute(GCP_CLIENT_SERVICE, BQ_GCP_CLIENT_SERVICE)
Expand All @@ -77,8 +82,7 @@ public static void addExceptionToSpan(Exception e, Span span) {
String simpleName = e.getClass().getSimpleName();
String statusMessage = simpleName + (message != null ? ": " + message : "");
span.setAttribute(BigQueryTelemetryTracer.EXCEPTION_TYPE, e.getClass().getName());
span.setAttribute(
BigQueryTelemetryTracer.ERROR_TYPE, ErrorTypeUtil.getClientErrorType(e).toString());
span.setAttribute(BigQueryTelemetryTracer.ERROR_TYPE, ErrorTypeUtil.extractErrorType(e));
span.setAttribute(BigQueryTelemetryTracer.STATUS_MESSAGE, statusMessage);
span.setStatus(StatusCode.ERROR, statusMessage);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,14 @@ public void testListDatasetsTraced() {
assertEquals(200L, attrs.get(HttpTracingRequestInitializer.HTTP_RESPONSE_STATUS_CODE));
assertEquals("bigquery.googleapis.com", attrs.get(BigQueryTelemetryTracer.URL_DOMAIN));
assertEquals(
"https://bigquery.googleapis.com/bigquery/v2/projects/gcloud-devel/datasets?prettyPrint=false",
"https://bigquery.googleapis.com/bigquery/v2/projects/"
+ bigqueryHelper.getOptions().getProjectId()
+ "/datasets?prettyPrint=false",
attrs.get(HttpTracingRequestInitializer.URL_FULL));
assertEquals(
"//bigquery.googleapis.com/projects/gcloud-devel/datasets",
"//bigquery.googleapis.com/projects/"
+ bigqueryHelper.getOptions().getProjectId()
+ "/datasets",
attrs.get(BigQueryTelemetryTracer.GCP_RESOURCE_DESTINATION_ID));
assertEquals(
"projects/{+projectId}/datasets", attrs.get(BigQueryTelemetryTracer.URL_TEMPLATE));
Expand Down Expand Up @@ -146,19 +150,25 @@ public void testGetDatasetNotFoundTraced() {
"projects/{+projectId}/datasets/{+datasetId}",
attrs.get(BigQueryTelemetryTracer.URL_TEMPLATE));
assertEquals(
"https://bigquery.googleapis.com/bigquery/v2/projects/gcloud-devel/datasets/non_existent_dataset?prettyPrint=false",
"https://bigquery.googleapis.com/bigquery/v2/projects/"
+ bigqueryHelper.getOptions().getProjectId()
+ "/datasets/non_existent_dataset?prettyPrint=false",
attrs.get(HttpTracingRequestInitializer.URL_FULL));
assertEquals(
"bigquery.googleapis.com", attrs.get(HttpTracingRequestInitializer.SERVER_ADDRESS));
assertEquals("bigquery.googleapis.com", attrs.get(BigQueryTelemetryTracer.URL_DOMAIN));
assertEquals(
"//bigquery.googleapis.com/projects/gcloud-devel/datasets/non_existent_dataset",
"//bigquery.googleapis.com/projects/"
+ bigqueryHelper.getOptions().getProjectId()
+ "/datasets/non_existent_dataset",
attrs.get(BigQueryTelemetryTracer.GCP_RESOURCE_DESTINATION_ID));

// Error attributes
assertEquals("notFound", attrs.get(BigQueryTelemetryTracer.ERROR_TYPE));
assertEquals(
"Not found: Dataset gcloud-devel:non_existent_dataset",
"Not found: Dataset "
+ bigqueryHelper.getOptions().getProjectId()
+ ":non_existent_dataset",
attrs.get(BigQueryTelemetryTracer.STATUS_MESSAGE));
}
}
Expand Down Expand Up @@ -197,7 +207,9 @@ public void testClientErrorAndRetriesTraced() {
Map<AttributeKey<?>, Object> attrs = span.getAttributes().asMap();
checkGeneralAttributes(attrs);
assertEquals(
"https://invalid-host-name-12345.com:8080/bigquery/v2/projects/gcloud-devel/datasets?prettyPrint=false",
"https://invalid-host-name-12345.com:8080/bigquery/v2/projects/"
+ bigqueryHelper.getOptions().getProjectId()
+ "/datasets?prettyPrint=false",
(String) attrs.get(HttpTracingRequestInitializer.URL_FULL));
assertEquals(
"invalid-host-name-12345.com", attrs.get(HttpTracingRequestInitializer.SERVER_ADDRESS));
Expand All @@ -206,7 +218,9 @@ public void testClientErrorAndRetriesTraced() {
assertEquals(
"projects/{+projectId}/datasets", attrs.get(BigQueryTelemetryTracer.URL_TEMPLATE));
assertEquals(
"//bigquery.googleapis.com/projects/gcloud-devel/datasets",
"//bigquery.googleapis.com/projects/"
+ bigqueryHelper.getOptions().getProjectId()
+ "/datasets",
attrs.get(BigQueryTelemetryTracer.GCP_RESOURCE_DESTINATION_ID));
checkRetryAttribute(span, rpcSpanCount);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1079,8 +1079,7 @@ public void testHttpTracingEnabled_GenericException_SetsAttributes() throws Exce
assertEquals(
"java.io.IOException",
rpcSpan.getAttributes().get(BigQueryTelemetryTracer.EXCEPTION_TYPE));
assertEquals(
"CLIENT_UNKNOWN_ERROR", rpcSpan.getAttributes().get(BigQueryTelemetryTracer.ERROR_TYPE));
assertEquals("IOException", rpcSpan.getAttributes().get(BigQueryTelemetryTracer.ERROR_TYPE));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public void testAddExceptionToSpan_WithMessage() {
assertEquals(
"java.lang.Exception",
spanData.getAttributes().get(BigQueryTelemetryTracer.EXCEPTION_TYPE));
assertErrorSpanAttributes("CLIENT_UNKNOWN_ERROR", "Exception: Test error message");
assertErrorSpanAttributes("Exception", "Exception: Test error message");
}

@Test
Expand All @@ -160,8 +160,7 @@ public void testAddExceptionToSpan_NoMessage() {
"java.lang.Exception",
spanData.getAttributes().get(BigQueryTelemetryTracer.EXCEPTION_TYPE));
assertEquals("Exception", spanData.getAttributes().get(BigQueryTelemetryTracer.STATUS_MESSAGE));
assertEquals(
"CLIENT_UNKNOWN_ERROR", spanData.getAttributes().get(BigQueryTelemetryTracer.ERROR_TYPE));
assertEquals("Exception", spanData.getAttributes().get(BigQueryTelemetryTracer.ERROR_TYPE));
}

@Test
Expand Down

This file was deleted.

Loading