Skip to content
Draft
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 @@ -16,7 +16,6 @@

package com.google.cloud.bigquery;

import com.google.api.core.BetaApi;
import com.google.api.core.ObsoleteApi;
import com.google.api.gax.retrying.ResultRetryAlgorithm;
import com.google.cloud.ServiceDefaults;
Expand Down Expand Up @@ -127,9 +126,10 @@ public Builder setDataFormatOptions(DataFormatOptions dataFormatOptions) {
/**
* Enables OpenTelemetry tracing functionality for this BigQuery instance
*
* <p>[TODO] add warning text here
*
* @param enableOpenTelemetryTracing enables OpenTelemetry tracing if true
*/
@BetaApi
public Builder setEnableOpenTelemetryTracing(boolean enableOpenTelemetryTracing) {
this.enableOpenTelemetryTracing = enableOpenTelemetryTracing;
return this;
Expand All @@ -140,7 +140,6 @@ public Builder setEnableOpenTelemetryTracing(boolean enableOpenTelemetryTracing)
*
* @param tracer OpenTelemetry tracer to be used
*/
@BetaApi
public Builder setOpenTelemetryTracer(Tracer tracer) {
this.openTelemetryTracer = tracer;
return this;
Expand Down Expand Up @@ -282,7 +281,6 @@ public JobCreationMode getDefaultJobCreationMode() {
*
* @return true if tracing is enabled, false if not
*/
@BetaApi("Span names and attributes are subject to change without notice")
public boolean isOpenTelemetryTracingEnabled() {
return enableOpenTelemetryTracing;
}
Expand All @@ -292,7 +290,6 @@ public boolean isOpenTelemetryTracingEnabled() {
*
* @return OpenTelemetry tracer object or {@code null} if not set
*/
@BetaApi("Span names and attributes are subject to change without notice")
public Tracer getOpenTelemetryTracer() {
return openTelemetryTracer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ public class HttpBigQueryRpc implements BigQueryRpc {

public static final String DEFAULT_PROJECTION = "full";
private static final String BASE_RESUMABLE_URI = "upload/bigquery/v2/projects/";
static final String HTTP_TRACING_DEV_GATE_PROPERTY =
"com.google.cloud.bigquery.http.tracing.dev.enabled";
static final String RESOURCE_PROJECT_PREFIX = "//bigquery.googleapis.com/projects/";
// see:
// https://cloud.google.com/bigquery/loading-data-post-request#resume-upload
Expand Down Expand Up @@ -120,9 +118,7 @@ public HttpBigQueryRpc(BigQueryOptions options) {
this.options = options;
this.urlDomain = new GenericUrl(options.getResolvedApiaryHost("bigquery")).getHost();

if (options.isOpenTelemetryTracingEnabled()
&& options.getOpenTelemetryTracer() != null
&& isHttpTracingEnabled()) {
if (options.isOpenTelemetryTracingEnabled() && options.getOpenTelemetryTracer() != null) {
initializer =
new HttpTracingRequestInitializer(initializer, options.getOpenTelemetryTracer());
}
Expand Down Expand Up @@ -2146,14 +2142,11 @@ private Span createRpcTracingSpan(
.setSpanKind(SpanKind.CLIENT)
.setAttribute("bq.rpc.service", service)
.setAttribute("bq.rpc.method", method)
.setAttribute("bq.rpc.system", "http");
if (isHttpTracingEnabled()) {
builder
.setAttribute(
BigQueryTelemetryTracer.GCP_RESOURCE_DESTINATION_ID, gcpResourceDestinationId)
.setAttribute(BigQueryTelemetryTracer.URL_TEMPLATE, urlTemplate)
.setAttribute(BigQueryTelemetryTracer.URL_DOMAIN, this.urlDomain);
}
.setAttribute("bq.rpc.system", "http")
.setAttribute(
BigQueryTelemetryTracer.GCP_RESOURCE_DESTINATION_ID, gcpResourceDestinationId)
.setAttribute(BigQueryTelemetryTracer.URL_TEMPLATE, urlTemplate)
.setAttribute(BigQueryTelemetryTracer.URL_DOMAIN, this.urlDomain);

if (options != null) {
builder.setAllAttributes(otelAttributesFromOptions(options));
Expand All @@ -2175,13 +2168,11 @@ private <T> T executeWithSpan(Span span, SpanOperation<T> operation) throws IOEx
try (Scope scope = span.makeCurrent()) {
return operation.execute(span);
} catch (Exception e) {
if (isHttpTracingEnabled()) {
if (e instanceof GoogleJsonResponseException) {
BigQueryTelemetryTracer.addServerErrorResponseToSpan(
((GoogleJsonResponseException) e), span);
} else {
BigQueryTelemetryTracer.addExceptionToSpan(e, span);
}
if (e instanceof GoogleJsonResponseException) {
BigQueryTelemetryTracer.addServerErrorResponseToSpan(
((GoogleJsonResponseException) e), span);
} else {
BigQueryTelemetryTracer.addExceptionToSpan(e, span);
}
throw e;
} finally {
Expand All @@ -2202,13 +2193,4 @@ private static Attributes otelAttributesFromOptions(Map<Option, ?> options) {
}
return builder.build();
}

/**
* Temporary development gate for HttpTracingRequestInitializer rollout: must be explicitly
* enabled with the system property. tracking ticket for removal:
* https://github.com/googleapis/google-cloud-java/issues/12100
*/
static boolean isHttpTracingEnabled() {
return Boolean.parseBoolean(System.getProperty(HTTP_TRACING_DEV_GATE_PROPERTY));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@

import com.google.api.client.googleapis.json.GoogleJsonError;
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
import com.google.api.core.BetaApi;
import com.google.api.core.InternalApi;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.StatusCode;

/** BigQuery Telemetry class that stores generic telemetry attributes and values */
@BetaApi
@InternalApi
public final class BigQueryTelemetryTracer {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@
*/
package com.google.cloud.bigquery.telemetry;

import com.google.api.core.BetaApi;
import com.google.common.annotations.VisibleForTesting;

/**
* Utility class for identifying exception types for telemetry tracking. TODO: this class should get
* replaced with gax version when ready work tracked in
* https://github.com/googleapis/google-cloud-java/issues/12105
*/
@BetaApi
@VisibleForTesting
public class ErrorTypeUtil {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.google.cloud.bigquery.telemetry;

import com.google.api.client.http.*;
import com.google.api.core.BetaApi;
import com.google.api.core.InternalApi;
import com.google.cloud.bigquery.BigQueryRetryHelper;
import com.google.common.annotations.VisibleForTesting;
Expand All @@ -33,7 +32,6 @@
* HttpRequestInitializer that wraps a delegate initializer, intercepts all HTTP requests, adds
* OpenTelemetry tracing and then invokes delegate interceptor.
*/
@BetaApi
@InternalApi
public class HttpTracingRequestInitializer implements HttpRequestInitializer {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public class ITOpenTelemetryTest {

@BeforeAll
public static void setUpClass() throws IOException {
System.setProperty("com.google.cloud.bigquery.http.tracing.dev.enabled", "true");
bigqueryHelper = RemoteBigQueryHelper.create();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;

// same thread execution temporarily required for using java system properties will get removed in
// issue https://github.com/googleapis/google-cloud-java/issues/12100
@Execution(ExecutionMode.SAME_THREAD)
public class HttpBigQueryRpcTest {

private static final String PROJECT_ID = "test-project";
Expand Down Expand Up @@ -225,7 +220,6 @@ class TelemetryEnabled {
@BeforeEach
public void setUp() {
setUpServer();
System.setProperty("com.google.cloud.bigquery.http.tracing.dev.enabled", "true");
rpc = createRpc(true);
}

Expand Down Expand Up @@ -1200,119 +1194,13 @@ public void testUrlDomain_OverriddenValue() throws Exception {
}
}

@Nested
class TelemetryEnabledDevDisabled {
private HttpBigQueryRpc rpc;

@BeforeEach
public void setUp() {
setUpServer();
System.clearProperty("com.google.cloud.bigquery.http.tracing.dev.enabled");
rpc = createRpc(true);
}

@Test
public void testHttpTracingDisabledDoesNotAddAdditionalAttributes() throws Exception {
setMockResponse(
"{\"kind\":\"bigquery#dataset\",\"id\":\""
+ PROJECT_ID
+ ":"
+ DATASET_ID
+ "\",\"datasetReference\":{\"projectId\":\""
+ PROJECT_ID
+ "\",\"datasetId\":\""
+ DATASET_ID
+ "\"}}");

rpc.getDatasetSkipExceptionTranslation(PROJECT_ID, DATASET_ID, new HashMap<>());

verifyRequest("GET", "/projects/" + PROJECT_ID + "/datasets/" + DATASET_ID);

List<SpanData> spans = spanExporter.getFinishedSpanItems();
assertThat(spans).isNotEmpty();
SpanData rpcSpan =
spans.stream()
.filter(
span -> span.getName().equals("com.google.cloud.bigquery.BigQueryRpc.getDataset"))
.findFirst()
.orElse(null);
assertNotNull(rpcSpan);
verifySpanProductionAttributes(
"DatasetService",
"GetDataset",
Collections.singletonMap("bq.rpc.response.dataset.id", PROJECT_ID + ":" + DATASET_ID),
rpcSpan);

assertNull(rpcSpan.getAttributes().get(BigQueryTelemetryTracer.RPC_SYSTEM_NAME));
assertNull(rpcSpan.getAttributes().get(BigQueryTelemetryTracer.GCP_CLIENT_SERVICE));
assertNull(
rpcSpan.getAttributes().get(AttributeKey.stringKey("url.template")),
"url.template attribute should not be set");
assertNull(rpcSpan.getAttributes().get(BigQueryTelemetryTracer.GCP_RESOURCE_DESTINATION_ID));
assertNull(rpcSpan.getAttributes().get(BigQueryTelemetryTracer.URL_DOMAIN));
assertNull(
rpcSpan.getAttributes().get(HttpTracingRequestInitializer.HTTP_REQUEST_RESEND_COUNT));
}

@Test
public void testHttpTracingDisabled_GenericException_DoesNotSetAttributes() throws Exception {
assertThrows(
IOException.class,
() -> {
rpc.getDatasetSkipExceptionTranslation(PROJECT_ID, DATASET_ID, new HashMap<>());
});

List<io.opentelemetry.sdk.trace.data.SpanData> spans = spanExporter.getFinishedSpanItems();
assertThat(spans).isNotEmpty();
io.opentelemetry.sdk.trace.data.SpanData rpcSpan =
spans.stream()
.filter(
span -> span.getName().equals("com.google.cloud.bigquery.BigQueryRpc.getDataset"))
.findFirst()
.orElse(null);
assertNotNull(rpcSpan);
assertNull(rpcSpan.getAttributes().get(BigQueryTelemetryTracer.EXCEPTION_TYPE));
assertNull(rpcSpan.getAttributes().get(BigQueryTelemetryTracer.ERROR_TYPE));
assertNull(rpcSpan.getAttributes().get(BigQueryTelemetryTracer.STATUS_MESSAGE));
}

@Test
public void testHttpTracingDisabled_GoogleJsonResponseException_DoesNotSetAttributes()
throws Exception {
mockResponse.setStatusCode(400);
mockResponse.setContentType(Json.MEDIA_TYPE);
mockResponse.setContent(
"{\"error\":{\"code\":400,\"message\":\"Invalid request\",\"errors\":[{\"message\":\"Invalid request\",\"domain\":\"global\",\"reason\":\"invalid\"}]}}");

assertThrows(
IOException.class,
() -> {
rpc.getDatasetSkipExceptionTranslation(PROJECT_ID, DATASET_ID, new HashMap<>());
});

List<io.opentelemetry.sdk.trace.data.SpanData> spans = spanExporter.getFinishedSpanItems();
assertThat(spans).isNotEmpty();
io.opentelemetry.sdk.trace.data.SpanData rpcSpan =
spans.stream()
.filter(
span -> span.getName().equals("com.google.cloud.bigquery.BigQueryRpc.getDataset"))
.findFirst()
.orElse(null);
assertNotNull(rpcSpan);
assertNull(rpcSpan.getAttributes().get(BigQueryTelemetryTracer.EXCEPTION_TYPE));
assertNull(rpcSpan.getAttributes().get(BigQueryTelemetryTracer.ERROR_TYPE));
assertNull(rpcSpan.getAttributes().get(BigQueryTelemetryTracer.STATUS_MESSAGE));
}
}

@Nested
class TelemetryDisabled {
private HttpBigQueryRpc rpc;

@BeforeEach
public void setUp() {
setUpServer();
System.clearProperty("com.google.cloud.bigquery.http.tracing.dev.enabled");
rpc = createRpc(false);
}

Expand Down
Loading