Skip to content

Commit 0ebaa92

Browse files
committed
add attribute namespaces, change to snake_case
1 parent a963641 commit 0ebaa92

File tree

14 files changed

+49
-91
lines changed

14 files changed

+49
-91
lines changed

google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,6 @@ && getOptions().getOpenTelemetryTracer() != null) {
445445
.getOpenTelemetryTracer()
446446
.spanBuilder("com.google.cloud.bigquery.BigQuery.createJob")
447447
.setAllAttributes(jobInfo.getJobId().getOtelAttributes())
448-
.setAttribute("status", getFieldAsString(jobInfo.getStatus()))
449448
.setAllAttributes(otelAttributesFromOptions(options))
450449
.startSpan();
451450
}
@@ -616,7 +615,7 @@ && getOptions().getOpenTelemetryTracer() != null) {
616615
getOptions()
617616
.getOpenTelemetryTracer()
618617
.spanBuilder("com.google.cloud.bigquery.BigQuery.listDatasets")
619-
.setAttribute("projectId", projectId)
618+
.setAttribute("bq.dataset.project_id", projectId)
620619
.setAllAttributes(otelAttributesFromOptions(options))
621620
.startSpan();
622621
}
@@ -1638,7 +1637,6 @@ && getOptions().getOpenTelemetryTracer() != null) {
16381637
.getOpenTelemetryTracer()
16391638
.spanBuilder("com.google.cloud.bigquery.BigQuery.listTableData")
16401639
.setAllAttributes(tableId.getOtelAttributes())
1641-
.setAllAttributes(schema.getOtelAttributes())
16421640
.setAllAttributes(otelAttributesFromOptions(options))
16431641
.startSpan();
16441642
}
@@ -1735,7 +1733,7 @@ && getOptions().getOpenTelemetryTracer() != null) {
17351733
getOptions()
17361734
.getOpenTelemetryTracer()
17371735
.spanBuilder("com.google.cloud.bigquery.BigQuery.getJob")
1738-
.setAllAttributes(jobId.getOtelAttributes())
1736+
.setAllAttributes(completeJobId.getOtelAttributes())
17391737
.setAllAttributes(otelAttributesFromOptions(options))
17401738
.startSpan();
17411739
}
@@ -1848,7 +1846,7 @@ && getOptions().getOpenTelemetryTracer() != null) {
18481846
getOptions()
18491847
.getOpenTelemetryTracer()
18501848
.spanBuilder("com.google.cloud.bigquery.BigQuery.cancelJob")
1851-
.setAllAttributes(jobId.getOtelAttributes())
1849+
.setAllAttributes(completeJobId.getOtelAttributes())
18521850
.startSpan();
18531851
}
18541852
try (Scope jobCancelScope = jobCancel != null ? jobCancel.makeCurrent() : null) {
@@ -1895,7 +1893,6 @@ && getOptions().getOpenTelemetryTracer() != null) {
18951893
getOptions()
18961894
.getOpenTelemetryTracer()
18971895
.spanBuilder("com.google.cloud.bigquery.BigQuery.query")
1898-
.setAllAttributes(configuration.getOtelAttributes())
18991896
.setAllAttributes(otelAttributesFromOptions(options))
19001897
.startSpan();
19011898
}
@@ -1933,7 +1930,7 @@ && getOptions().getOpenTelemetryTracer() != null) {
19331930
getOptions()
19341931
.getOpenTelemetryTracer()
19351932
.spanBuilder("com.google.cloud.bigquery.BigQuery.queryRpc")
1936-
.setAttribute("projectId", projectId)
1933+
.setAttribute("bq.query.project_id", projectId)
19371934
.setAllAttributes(otelAttributesFromQueryRequest(content))
19381935
.setAllAttributes(otelAttributesFromOptions(options))
19391936
.startSpan();
@@ -2034,7 +2031,6 @@ && getOptions().getOpenTelemetryTracer() != null) {
20342031
getOptions()
20352032
.getOpenTelemetryTracer()
20362033
.spanBuilder("com.google.cloud.bigquery.BigQuery.query")
2037-
.setAllAttributes(configuration.getOtelAttributes())
20382034
.setAllAttributes(jobId.getOtelAttributes())
20392035
.setAllAttributes(otelAttributesFromOptions(options))
20402036
.startSpan();
@@ -2267,7 +2263,7 @@ && getOptions().getOpenTelemetryTracer() != null) {
22672263
.getOpenTelemetryTracer()
22682264
.spanBuilder("com.google.cloud.bigquery.BigQuery.testIamPermissions")
22692265
.setAllAttributes(tableId.getOtelAttributes())
2270-
.setAttribute("permissions", permissions.toString())
2266+
.setAttribute("bq.iam.permissions", permissions.toString())
22712267
.setAllAttributes(otelAttributesFromOptions(options))
22722268
.startSpan();
22732269
}
@@ -2318,27 +2314,27 @@ private static Attributes otelAttributesFromOptions(Option... options) {
23182314
for (Option option : options) {
23192315
attributes =
23202316
attributes.toBuilder()
2321-
.put(option.getRpcOption().toString(), option.getValue().toString())
2317+
.put("bq.option." + option.getRpcOption().toString(), option.getValue().toString())
23222318
.build();
23232319
}
23242320
return attributes;
23252321
}
23262322

23272323
private static Attributes otelAttributesFromQueryRequest(QueryRequest request) {
23282324
return Attributes.builder()
2329-
.put("dryRun", getFieldAsString(request.getDryRun()))
2330-
.put("jobCreationMode", getFieldAsString(request.getJobCreationMode()))
2331-
.put("kind", getFieldAsString(request.getKind()))
2332-
.put("location", getFieldAsString(request.getLocation()))
2333-
.put("requestId", getFieldAsString(request.getRequestId()))
2334-
.put("useQueryCache", getFieldAsString(request.getUseQueryCache()))
2325+
.put("bq.query.dry_run", getFieldAsString(request.getDryRun()))
2326+
.put("bq.query.job_creation_mode", getFieldAsString(request.getJobCreationMode()))
2327+
.put("bq.query.kind", getFieldAsString(request.getKind()))
2328+
.put("bq.query.location", getFieldAsString(request.getLocation()))
2329+
.put("bq.query.request_id", getFieldAsString(request.getRequestId()))
2330+
.put("bq.query.use_query_cache", getFieldAsString(request.getUseQueryCache()))
23352331
.build();
23362332
}
23372333

23382334
private static Attributes otelAttributesFromPolicy(Policy policy) {
23392335
return Attributes.builder()
2340-
.put("version", getFieldAsString(policy.getVersion()))
2341-
.put("bindings", getFieldAsString(policy.getBindings()))
2336+
.put("bq.policy.version", getFieldAsString(policy.getVersion()))
2337+
.put("bq.policy.bindings", getFieldAsString(policy.getBindings()))
23422338
.build();
23432339
}
23442340

google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/DatasetId.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ static DatasetId fromPb(DatasetReference datasetRef) {
8888

8989
protected Attributes getOtelAttributes() {
9090
return Attributes.builder()
91-
.put("project", this.getProject())
92-
.put("dataset", this.getDataset())
91+
.put("bq.dataset.project", this.getProject())
92+
.put("bq.dataset.id", this.getDataset())
9393
.build();
9494
}
9595
}

google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/DatasetInfo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -754,8 +754,8 @@ private static String getFieldAsString(Object field) {
754754
protected Attributes getOtelAttributes() {
755755
return Attributes.builder()
756756
.putAll(this.getDatasetId().getOtelAttributes())
757-
.put("lastModified", getFieldAsString(this.getLastModified()))
758-
.put("location", getFieldAsString(this.getLocation()))
757+
.put("bq.dataset.lastModified", getFieldAsString(this.getLastModified()))
758+
.put("bq.dataset.location", getFieldAsString(this.getLocation()))
759759
.build();
760760
}
761761

google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/JobId.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ private static String getFieldAsString(Object field) {
131131

132132
protected Attributes getOtelAttributes() {
133133
return Attributes.builder()
134-
.put("job", getFieldAsString(this.getJob()))
135-
.put("location", getFieldAsString(this.getLocation()))
136-
.put("project", getFieldAsString(this.getProject()))
134+
.put("bq.job.id", getFieldAsString(this.getJob()))
135+
.put("bq.job.location", getFieldAsString(this.getLocation()))
136+
.put("bq.job.project", getFieldAsString(this.getProject()))
137137
.build();
138138
}
139139
}

google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/JobInfo.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import com.google.api.services.bigquery.model.Job;
2020
import com.google.common.base.Function;
2121
import com.google.common.base.MoreObjects;
22-
import io.opentelemetry.api.common.Attributes;
2322
import java.io.Serializable;
2423
import java.util.Objects;
2524

@@ -376,18 +375,4 @@ public static JobInfo of(JobId jobId, JobConfiguration configuration) {
376375
static JobInfo fromPb(Job jobPb) {
377376
return new BuilderImpl(jobPb).build();
378377
}
379-
380-
private static String getFieldAsString(Object field) {
381-
return field == null ? "null" : field.toString();
382-
}
383-
384-
protected Attributes getOtelAttributes() {
385-
return Attributes.builder()
386-
.putAll(this.getJobId().getOtelAttributes())
387-
.put("creationTime", getFieldAsString(this.getStatistics().getCreationTime()))
388-
.put("startTime", getFieldAsString(this.getStatistics().getStartTime()))
389-
.put("endTime", getFieldAsString(this.getStatistics().getEndTime()))
390-
.put("jobType", getFieldAsString(this.getConfiguration().getType()))
391-
.build();
392-
}
393378
}

google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ModelId.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ static ModelId fromPb(ModelReference modelRef) {
109109

110110
protected Attributes getOtelAttributes() {
111111
return Attributes.builder()
112-
.put("project", this.getProject())
113-
.put("dataset", this.getDataset())
114-
.put("model", this.getModel())
112+
.put("bq.model.project", this.getProject())
113+
.put("bq.model.dataset", this.getDataset())
114+
.put("bq.model.id", this.getModel())
115115
.build();
116116
}
117117
}

google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ModelInfo.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -462,11 +462,11 @@ private static String getFieldAsString(Object field) {
462462
protected Attributes getOtelAttributes() {
463463
return Attributes.builder()
464464
.putAll(this.getModelId().getOtelAttributes())
465-
.put("modelType", getFieldAsString(this.getModelType()))
466-
.put("creationTime", getFieldAsString(this.getCreationTime()))
467-
.put("lastModifiedTime", getFieldAsString(this.getLastModifiedTime()))
468-
.put("expirationTime", getFieldAsString(this.getExpirationTime()))
469-
.put("location", getFieldAsString(this.getLocation()))
465+
.put("bq.model.type", getFieldAsString(this.getModelType()))
466+
.put("bq.model.creation_time", getFieldAsString(this.getCreationTime()))
467+
.put("bq.model.last_modified_time", getFieldAsString(this.getLastModifiedTime()))
468+
.put("bq.model.expiration_time", getFieldAsString(this.getExpirationTime()))
469+
.put("bq.model.location", getFieldAsString(this.getLocation()))
470470
.build();
471471
}
472472
}

google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryJobConfiguration.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import com.google.common.collect.Iterables;
3333
import com.google.common.collect.Lists;
3434
import com.google.common.collect.Maps;
35-
import io.opentelemetry.api.common.Attributes;
3635
import java.util.List;
3736
import java.util.Map;
3837
import java.util.Objects;
@@ -1214,16 +1213,4 @@ public QueryParameter apply(Map.Entry<String, QueryParameterValue> entry) {
12141213
return queryParameterPb;
12151214
}
12161215
};
1217-
1218-
private static String getFieldAsString(Object field) {
1219-
return field == null ? "null" : field.toString();
1220-
}
1221-
1222-
public Attributes getOtelAttributes() {
1223-
return Attributes.builder()
1224-
.put("destinationTable", getFieldAsString(this.getDestinationTable()))
1225-
.put("useQueryCache", getFieldAsString(this.useQueryCache()))
1226-
.put("dryRun", getFieldAsString(this.dryRun()))
1227-
.build();
1228-
}
12291216
}

google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/RoutineId.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ static RoutineId fromPb(RoutineReference routineRef) {
112112

113113
protected Attributes getOtelAttributes() {
114114
return Attributes.builder()
115-
.put("project", this.getProject())
116-
.put("dataset", this.getDataset())
117-
.put("routine", this.getRoutine())
115+
.put("bq.routine.project", this.getProject())
116+
.put("bq.routine.dataset", this.getDataset())
117+
.put("bq.routine.id", this.getRoutine())
118118
.build();
119119
}
120120
}

google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/RoutineInfo.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -553,9 +553,9 @@ private static String getFieldAsString(Object field) {
553553
protected Attributes getOtelAttributes() {
554554
return Attributes.builder()
555555
.putAll(this.getRoutineId().getOtelAttributes())
556-
.put("routineType", getFieldAsString(this.getRoutineType()))
557-
.put("creationTime", getFieldAsString(this.getCreationTime()))
558-
.put("lastModifiedTime", getFieldAsString(this.getLastModifiedTime()))
556+
.put("bq.routine.type", getFieldAsString(this.getRoutineType()))
557+
.put("bq.routine.creation_time", getFieldAsString(this.getCreationTime()))
558+
.put("bq.routine.last_modified_time", getFieldAsString(this.getLastModifiedTime()))
559559
.build();
560560
}
561561
}

0 commit comments

Comments
 (0)