Skip to content

Commit d599d04

Browse files
committed
add new attributes behind dev gate
1 parent 6126978 commit d599d04

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2144,10 +2144,13 @@ private Span createRpcTracingSpan(
21442144
.setSpanKind(SpanKind.CLIENT)
21452145
.setAttribute("bq.rpc.service", service)
21462146
.setAttribute("bq.rpc.method", method)
2147-
.setAttribute("bq.rpc.system", "http")
2148-
.setAttribute(
2149-
BigQueryTelemetryTracer.GCP_RESOURCE_DESTINATION_ID, gcpResourceDestinationId)
2150-
.setAttribute(BigQueryTelemetryTracer.URL_TEMPLATE, urlTemplate);
2147+
.setAttribute("bq.rpc.system", "http");
2148+
if (isHttpTracingEnabled()) {
2149+
builder
2150+
.setAttribute(
2151+
BigQueryTelemetryTracer.GCP_RESOURCE_DESTINATION_ID, gcpResourceDestinationId)
2152+
.setAttribute(BigQueryTelemetryTracer.URL_TEMPLATE, urlTemplate);
2153+
}
21512154

21522155
if (options != null) {
21532156
builder.setAllAttributes(otelAttributesFromOptions(options));

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

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,17 +150,24 @@ private void verifySpan(
150150
assertThat(spans).isNotEmpty();
151151
SpanData rpcSpan =
152152
spans.stream().filter(span -> span.getName().equals(spanName)).findFirst().orElse(null);
153-
assertNotNull(rpcSpan);
154-
assertEquals(service, rpcSpan.getAttributes().get(AttributeKey.stringKey("bq.rpc.service")));
155-
assertEquals(method, rpcSpan.getAttributes().get(AttributeKey.stringKey("bq.rpc.method")));
156-
assertEquals("http", rpcSpan.getAttributes().get(AttributeKey.stringKey("bq.rpc.system")));
153+
154+
verifySpanProductionAttributes(service, method, attributes, rpcSpan);
155+
157156
assertNotNull(
158-
rpcSpan.getAttributes().get(BigQueryTelemetryTracer.URL_TEMPLATE),
157+
rpcSpan.getAttributes().get(AttributeKey.stringKey("url.template")),
159158
"url.template attribute should be set");
160159

161160
assertEquals(
162161
gcpResourceDestinationId,
163162
rpcSpan.getAttributes().get(BigQueryTelemetryTracer.GCP_RESOURCE_DESTINATION_ID));
163+
}
164+
165+
private void verifySpanProductionAttributes(
166+
String service, String method, Map<String, String> attributes, SpanData rpcSpan) {
167+
assertNotNull(rpcSpan);
168+
assertEquals(service, rpcSpan.getAttributes().get(AttributeKey.stringKey("bq.rpc.service")));
169+
assertEquals(method, rpcSpan.getAttributes().get(AttributeKey.stringKey("bq.rpc.method")));
170+
assertEquals("http", rpcSpan.getAttributes().get(AttributeKey.stringKey("bq.rpc.system")));
164171

165172
if (attributes != null) {
166173
for (Map.Entry<String, String> entry : attributes.entrySet()) {
@@ -1162,12 +1169,6 @@ public void testHttpTracingDisabledDoesNotAddAdditionalAttributes() throws Excep
11621169
rpc.getDatasetSkipExceptionTranslation(PROJECT_ID, DATASET_ID, new HashMap<>());
11631170

11641171
verifyRequest("GET", "/projects/" + PROJECT_ID + "/datasets/" + DATASET_ID);
1165-
verifySpan(
1166-
"com.google.cloud.bigquery.BigQueryRpc.getDataset",
1167-
"DatasetService",
1168-
"GetDataset",
1169-
RESOURCE_PROJECT_PREFIX + PROJECT_ID + "/datasets/" + DATASET_ID,
1170-
Collections.singletonMap("bq.rpc.response.dataset.id", PROJECT_ID + ":" + DATASET_ID));
11711172

11721173
List<SpanData> spans = spanExporter.getFinishedSpanItems();
11731174
assertThat(spans).isNotEmpty();
@@ -1178,8 +1179,19 @@ public void testHttpTracingDisabledDoesNotAddAdditionalAttributes() throws Excep
11781179
.findFirst()
11791180
.orElse(null);
11801181
assertNotNull(rpcSpan);
1182+
verifySpanProductionAttributes(
1183+
"DatasetService",
1184+
"GetDataset",
1185+
Collections.singletonMap("bq.rpc.response.dataset.id", PROJECT_ID + ":" + DATASET_ID),
1186+
rpcSpan);
1187+
11811188
assertNull(rpcSpan.getAttributes().get(BigQueryTelemetryTracer.RPC_SYSTEM_NAME));
11821189
assertNull(rpcSpan.getAttributes().get(BigQueryTelemetryTracer.GCP_CLIENT_SERVICE));
1190+
assertNull(
1191+
rpcSpan.getAttributes().get(AttributeKey.stringKey("url.template")),
1192+
"url.template attribute should not be set");
1193+
1194+
assertNull(rpcSpan.getAttributes().get(BigQueryTelemetryTracer.GCP_RESOURCE_DESTINATION_ID));
11831195
}
11841196

11851197
@Test

0 commit comments

Comments
 (0)