Skip to content

Commit 207ca76

Browse files
committed
naming/comments/extra white space clean up
1 parent 695649d commit 207ca76

5 files changed

Lines changed: 15 additions & 35 deletions

File tree

java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/spi/v2/HttpBigQueryRpc.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1788,7 +1788,6 @@ private static Attributes otelAttributesFromOptions(Map<Option, ?> options) {
17881788
return builder.build();
17891789
}
17901790

1791-
@InternalApi("Visible for testing")
17921791
/* Temporary development gate for HttpTracingRequestInitializer rollout:
17931792
must be explicitly enabled with the system property
17941793
*/

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@
2121
import io.opentelemetry.api.common.AttributeKey;
2222
import io.opentelemetry.api.trace.Span;
2323

24-
/**
25-
* General BigQuery Telemetry class that stores generic telemetry attributes and any associated
26-
* logic to calculate.
27-
*/
24+
/** BigQuery Telemetry class that stores generic telemetry attributes and values */
2825
@BetaApi
2926
@InternalApi
3027
public final class BigQueryTelemetryTracer {

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,17 @@ public void initialize(HttpRequest request) throws IOException {
6363
if (delegate != null) {
6464
delegate.initialize(request);
6565
}
66-
6766
if (tracer == null) {
6867
return;
6968
}
70-
7169
// Get the current active span (created by HttpBigQueryRpc) and add HTTP attributes to it
7270
Span span = Span.current();
7371
if (!span.getSpanContext().isValid()) {
7472
// No active span to exists, skip instrumentation
7573
return;
7674
}
77-
7875
String host = request.getUrl().getHost();
7976
Integer port = request.getUrl().getPort();
80-
81-
// Add initial HTTP attributes to the existing span
8277
addInitialHttpAttributesToSpan(span, host, port);
8378
}
8479

java-bigquery/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/spi/v2/HttpBigQueryRpcTest.java

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -908,9 +908,7 @@ public void testOtelAttributesFromOptionsGetAddedtoSpan() throws Exception {
908908
}
909909

910910
@Test
911-
public void testHttpTracingEnabled() throws Exception {
912-
String originalProperty =
913-
System.getProperty("com.google.cloud.bigquery.http.tracing.dev.enabled");
911+
public void testHttpTracingEnabledAddsAdditionalAttributes() throws Exception {
914912
try {
915913
System.setProperty("com.google.cloud.bigquery.http.tracing.dev.enabled", "true");
916914
HttpBigQueryRpc customRpc = createRpc(true);
@@ -949,19 +947,12 @@ public void testHttpTracingEnabled() throws Exception {
949947
"http", rpcSpan.getAttributes().get(AttributeKey.stringKey("rpc.system.name")));
950948
assertNotNull(rpcSpan.getAttributes().get(AttributeKey.stringKey("server.address")));
951949
} finally {
952-
if (originalProperty != null) {
953-
System.setProperty(
954-
"com.google.cloud.bigquery.http.tracing.dev.enabled", originalProperty);
955-
} else {
956-
System.clearProperty("com.google.cloud.bigquery.http.tracing.dev.enabled");
957-
}
950+
System.clearProperty("com.google.cloud.bigquery.http.tracing.dev.enabled");
958951
}
959952
}
960953

961954
@Test
962-
public void testHttpTracingDisabled() throws Exception {
963-
String originalProperty =
964-
System.getProperty("com.google.cloud.bigquery.http.tracing.dev.enabled");
955+
public void testHttpTracingDisabledDoesNotAddAdditionalAttributes() throws Exception {
965956
try {
966957
System.setProperty("com.google.cloud.bigquery.http.tracing.dev.enabled", "false");
967958
HttpBigQueryRpc customRpc = createRpc(true);
@@ -999,12 +990,7 @@ public void testHttpTracingDisabled() throws Exception {
999990
assertThat(rpcSpan.getAttributes().get(AttributeKey.stringKey("rpc.system.name"))).isNull();
1000991
assertThat(rpcSpan.getAttributes().get(AttributeKey.stringKey("server.address"))).isNull();
1001992
} finally {
1002-
if (originalProperty != null) {
1003-
System.setProperty(
1004-
"com.google.cloud.bigquery.http.tracing.dev.enabled", originalProperty);
1005-
} else {
1006-
System.clearProperty("com.google.cloud.bigquery.http.tracing.dev.enabled");
1007-
}
993+
System.clearProperty("com.google.cloud.bigquery.http.tracing.dev.enabled");
1008994
}
1009995
}
1010996
}

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.google.cloud.bigquery.telemetry;
1818

1919
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.assertNull;
2021
import static org.mockito.ArgumentMatchers.any;
2122
import static org.mockito.Mockito.mock;
2223
import static org.mockito.Mockito.times;
@@ -47,7 +48,6 @@
4748
import org.junit.jupiter.api.BeforeEach;
4849
import org.junit.jupiter.api.Test;
4950

50-
/** Unit tests for TracingHttpRequestInitializer */
5151
public class HttpTracingRequestInitializerTest {
5252

5353
private static final String BASE_URL =
@@ -72,12 +72,12 @@ public void setUp() {
7272
OpenTelemetrySdk.builder().setTracerProvider(tracerProvider).build();
7373
tracer = openTelemetry.getTracer("test-tracer");
7474
initializer = new HttpTracingRequestInitializer(null, tracer);
75+
parentSpan = tracer.spanBuilder(SPAN_NAME).startSpan();
76+
spanScope = parentSpan.makeCurrent();
7577
}
7678

7779
@Test
7880
public void testRequestAttributesAreSetIfSpanExists() throws IOException {
79-
parentSpan = tracer.spanBuilder(SPAN_NAME).startSpan();
80-
spanScope = parentSpan.makeCurrent();
8181
HttpTransport transport = createTransport();
8282
HttpRequest request = buildGetRequest(transport, initializer, BASE_URL);
8383

@@ -97,9 +97,7 @@ public void testRequestAttributesAreSetIfSpanExists() throws IOException {
9797

9898
@Test
9999
public void testExistingParentAttributesAreNotAffectedByRequestAttributes() throws IOException {
100-
parentSpan =
101-
tracer.spanBuilder(SPAN_NAME).setAttribute("parent_attribute", "value").startSpan();
102-
spanScope = parentSpan.makeCurrent();
100+
parentSpan.setAttribute("parent_attribute", "value");
103101
HttpTransport transport = createTransport();
104102
HttpRequest request = buildGetRequest(transport, initializer, BASE_URL);
105103

@@ -124,13 +122,18 @@ public void testNoSpanIsCreatedIfNoActiveSpan() throws IOException {
124122
new HttpTracingRequestInitializer(delegateInitializer, tracer);
125123

126124
HttpTransport transport = createTransport();
125+
// close span before building the request so there is no current span during initialization
126+
spanScope.close();
127+
parentSpan.end();
128+
127129
HttpRequest request = buildGetRequest(transport, tracingInitializer, BASE_URL);
128130

129131
HttpResponse response = request.execute();
130132
response.disconnect();
131133

132134
List<SpanData> spans = spanExporter.getFinishedSpanItems();
133-
assertEquals(0, spans.size());
135+
assertEquals(1, spans.size());
136+
assertNull(spans.get(0).getAttributes().get(BigQueryTelemetryTracer.GCP_CLIENT_ARTIFACT));
134137
verify(delegateInitializer, times(1)).initialize(any(HttpRequest.class));
135138
}
136139

0 commit comments

Comments
 (0)