Skip to content
Draft
7 changes: 0 additions & 7 deletions gapic-libraries-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,6 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-bigtable-deps-bom</artifactId>
<version>2.78.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-bigtable-deps:current} -->
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-billing-bom</artifactId>
Expand Down
6 changes: 6 additions & 0 deletions java-bigquery/google-cloud-bigquery-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,12 @@
<artifactId>opentelemetry-sdk-testing</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-trace</artifactId>
<version>2.92.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ String getConnectionUrl() {
return connectionUrl;
}

String getConnectionId() {
public String getConnectionId() {
return this.connectionId;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ public class BigQueryJdbcOpenTelemetry {
private static final String OTLP_ENDPOINT_VALUE = "https://telemetry.googleapis.com:443";
private static final String EXPORTER_NONE = "none";
private static final String EXPORTER_OTLP = "otlp";
private static final String OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT =
"otel.span.attribute.value.length.limit";
private static final String OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT =
"otel.attribute.value.length.limit";
private static final String DEFAULT_ATTRIBUTE_LENGTH_LIMIT = "61440";
private static final BigQueryJdbcCustomLogger LOG =
new BigQueryJdbcCustomLogger("BigQueryJdbcOpenTelemetry");

Expand Down Expand Up @@ -290,6 +295,17 @@ public static OpenTelemetry getOpenTelemetry(
props.put(GOOGLE_CLOUD_PROJECT, gcpTelemetryProjectId);
}

// Set safe, generous default limits on attribute value lengths (60KB) to protect
// customers from GCP Cloud Trace 64KB span ingestion failures when logging massive
// exception stack traces or database schema metadata.
// Respect any existing user configuration overrides.
if (!props.containsKey(OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT)) {
props.put(OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT, DEFAULT_ATTRIBUTE_LENGTH_LIMIT);
}
if (!props.containsKey(OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT)) {
props.put(OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT, DEFAULT_ATTRIBUTE_LENGTH_LIMIT);
}

AutoConfiguredOpenTelemetrySdk autoConfigured =
AutoConfiguredOpenTelemetrySdk.builder().addPropertiesSupplier(() -> props).build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
public class OpenTelemetryJulHandler extends Handler {
private static final Pattern UNSAFE_LOG_CHARACTERS = Pattern.compile("[^a-zA-Z0-9./_-]");

public OpenTelemetryJulHandler() {}
public OpenTelemetryJulHandler() {
setLevel(Level.ALL);
}

@Override
public void publish(LogRecord record) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,26 @@
import com.google.cloud.bigquery.exception.BigQueryJdbcException;
import com.google.cloud.bigquery.storage.v1.BigQueryReadClient;
import com.google.cloud.bigquery.storage.v1.BigQueryWriteClient;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.sdk.testing.junit5.OpenTelemetryExtension;
import io.opentelemetry.sdk.trace.data.SpanData;
import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;
import java.util.List;
import java.util.Properties;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

public class BigQueryConnectionTest {

@RegisterExtension
static final OpenTelemetryExtension otelTesting = OpenTelemetryExtension.create();

private static final String DEFAULT_VERSION = "0.0.0";
private static final String DEFAULT_JDBC_TOKEN_VALUE = "Google-BigQuery-JDBC-Driver";
private static final String BASE_URL =
Expand Down Expand Up @@ -456,4 +465,25 @@ public void testIsReadOnlyTokenProvided(String readonlyProp, boolean expectedIsR
assertEquals(expectedIsReadOnly, connection.isReadOnlyTokenUsed());
}
}

@Test
public void testConnect_withCustomOpenTelemetry_usesCustomInstance() throws Exception {
DataSource ds = DataSource.fromUrl(BASE_URL);
ds.setCustomOpenTelemetry(otelTesting.getOpenTelemetry());

try (BigQueryConnection connection = new BigQueryConnection(BASE_URL, ds)) {
assertNotNull(connection);
assertFalse(connection.isClosed());

Tracer tracer = connection.getTracer();
assertNotNull(tracer);

Span span = tracer.spanBuilder("custom-otel-span").startSpan();
span.end();

List<SpanData> spans = otelTesting.getSpans();
assertEquals(1, spans.size());
assertEquals("custom-otel-span", spans.get(0).getName());
}
}
}
Loading
Loading