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 @@ -70,6 +70,7 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanKind;
import java.io.IOException;
Expand Down Expand Up @@ -1196,10 +1197,10 @@ public boolean deleteRoutineSkipExceptionTranslation(
deleteRoutine =
this.options
.getOpenTelemetryTracer()
.spanBuilder("com.google.cloud.bigquery.BigQueryRpc.listRoutines")
.spanBuilder("com.google.cloud.bigquery.BigQueryRpc.deleteRoutine")
.setSpanKind(SpanKind.CLIENT)
.setAttribute("bq.rpc.service", "RoutineService")
.setAttribute("bq.rpc.method", "ListRoutines")
.setAttribute("bq.rpc.method", "DeleteRoutine")
.setAttribute("bq.rpc.system", "http")
.startSpan();
}
Expand Down Expand Up @@ -1987,10 +1988,10 @@ public TestIamPermissionsResponse testIamPermissionsSkipExceptionTranslation(
testIamPermissions =
this.options
.getOpenTelemetryTracer()
.spanBuilder("com.google.cloud.bigquery.BigQueryRpc.setIamPolicy")
.spanBuilder("com.google.cloud.bigquery.BigQueryRpc.testIamPermissions")
.setSpanKind(SpanKind.CLIENT)
.setAttribute("bq.rpc.service", "TableService")
.setAttribute("bq.rpc.method", "SetIamPolicy")
.setAttribute("bq.rpc.method", "TestIamPermissions")
.setAttribute("bq.rpc.system", "http")
.setAllAttributes(otelAttributesFromOptions(options))
.startSpan();
Expand All @@ -2004,10 +2005,10 @@ public TestIamPermissionsResponse testIamPermissionsSkipExceptionTranslation(
}

private static Attributes otelAttributesFromOptions(Map<Option, ?> options) {
Attributes attributes = Attributes.builder().build();
AttributesBuilder builder = Attributes.builder();
for (Map.Entry<Option, ?> entry : options.entrySet()) {
attributes.toBuilder().put(entry.getKey().toString(), entry.getValue().toString());
builder.put(entry.getKey().toString(), entry.getValue().toString());
}
return attributes;
return builder.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -542,9 +542,9 @@ public void testDeleteRoutineTelemetry() throws Exception {
"DELETE",
"/projects/" + PROJECT_ID + "/datasets/" + DATASET_ID + "/routines/" + ROUTINE_ID);
verifySpan(
"com.google.cloud.bigquery.BigQueryRpc.listRoutines",
"com.google.cloud.bigquery.BigQueryRpc.deleteRoutine",
"RoutineService",
"ListRoutines",
"DeleteRoutine",
null);
}

Expand Down Expand Up @@ -854,11 +854,40 @@ public void testTestIamPermissionsTelemetry() throws Exception {
+ TABLE_ID
+ ":testIamPermissions");
verifySpan(
"com.google.cloud.bigquery.BigQueryRpc.setIamPolicy",
"com.google.cloud.bigquery.BigQueryRpc.testIamPermissions",
"TableService",
"SetIamPolicy",
"TestIamPermissions",
null);
}

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

Map<BigQueryRpc.Option, Object> options = new HashMap<>();
options.put(BigQueryRpc.Option.FIELDS, "foo,bar");

rpc.getDatasetSkipExceptionTranslation(PROJECT_ID, DATASET_ID, options);

Map<String, String> expectedAttributes = new HashMap<>();
expectedAttributes.put("FIELDS", "foo,bar");
expectedAttributes.put("bq.rpc.response.dataset.id", PROJECT_ID + ":" + DATASET_ID);

verifySpan(
"com.google.cloud.bigquery.BigQueryRpc.getDataset",
"DatasetService",
"GetDataset",
expectedAttributes);
}
}

@Nested
Expand Down
Loading