feat(bigquery): Integrate Otel into retries, jobs, and more (#3842) · googleapis/java-bigquery@4b28c47 · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

Commit 4b28c47

Browse files
authored
feat(bigquery): Integrate Otel into retries, jobs, and more (#3842)
* feat(bigquery): Integrate Otel into retries, jobs, and tableDataWriteChannel * Add justification for changing func signature * fix ignored-differences syntax * fix ignored-differences syntax...again * update IT tests * Remove config and algorithm from retry span * remove otel support from connection interface
1 parent af90841 commit 4b28c47

File tree

7 files changed

+446
-133
lines changed

7 files changed

+446
-133
lines changed

google-cloud-bigquery/clirr-ignored-differences.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
<!-- see http://www.mojohaus.org/clirr-maven-plugin/examples/ignored-differences.html -->
33
<differences>
44
<!-- TODO: REMOVE AFTER RELEASE -->
5+
<difference>
6+
<differenceType>7004</differenceType>
7+
<className>com/google/cloud/bigquery/BigQueryRetryHelper</className>
8+
<method>java.lang.Object runWithRetries(java.util.concurrent.Callable, com.google.api.gax.retrying.RetrySettings, com.google.api.gax.retrying.ResultRetryAlgorithm, com.google.api.core.ApiClock, com.google.cloud.bigquery.BigQueryRetryConfig)</method>
9+
<justification>A Tracer object is needed to use Otel and runWithRetries is only called in a few files, so it should be fine to update the signature</justification>
10+
</difference>
511
<difference>
612
<differenceType>7004</differenceType>
713
<className>com/google/cloud/bigquery/spi/v2/BigQueryRpc</className>

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

Lines changed: 93 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,9 @@ public com.google.api.services.bigquery.model.Dataset call() throws IOException
295295
getOptions().getRetrySettings(),
296296
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
297297
getOptions().getClock(),
298-
EMPTY_RETRY_CONFIG));
298+
EMPTY_RETRY_CONFIG,
299+
getOptions().isOpenTelemetryTracingEnabled(),
300+
getOptions().getOpenTelemetryTracer()));
299301
} catch (BigQueryRetryHelperException e) {
300302
throw BigQueryException.translateAndThrow(e);
301303
} finally {
@@ -340,7 +342,9 @@ public com.google.api.services.bigquery.model.Table call() throws IOException {
340342
getOptions().getRetrySettings(),
341343
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
342344
getOptions().getClock(),
343-
EMPTY_RETRY_CONFIG));
345+
EMPTY_RETRY_CONFIG,
346+
getOptions().isOpenTelemetryTracingEnabled(),
347+
getOptions().getOpenTelemetryTracer()));
344348
} catch (BigQueryRetryHelperException e) {
345349
throw BigQueryException.translateAndThrow(e);
346350
} finally {
@@ -394,7 +398,9 @@ public com.google.api.services.bigquery.model.Routine call() throws IOException
394398
getOptions().getRetrySettings(),
395399
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
396400
getOptions().getClock(),
397-
EMPTY_RETRY_CONFIG));
401+
EMPTY_RETRY_CONFIG,
402+
getOptions().isOpenTelemetryTracingEnabled(),
403+
getOptions().getOpenTelemetryTracer()));
398404
} catch (BigQueryRetryHelperException e) {
399405
throw BigQueryException.translateAndThrow(e);
400406
} finally {
@@ -488,7 +494,9 @@ public com.google.api.services.bigquery.model.Job call() throws IOException {
488494
getOptions().getClock(),
489495
getBigQueryRetryConfig(optionsMap) != null
490496
? getBigQueryRetryConfig(optionsMap)
491-
: DEFAULT_RETRY_CONFIG));
497+
: DEFAULT_RETRY_CONFIG,
498+
getOptions().isOpenTelemetryTracingEnabled(),
499+
getOptions().getOpenTelemetryTracer()));
492500
} catch (BigQueryRetryHelperException e) {
493501
throw BigQueryException.translateAndThrow(e);
494502
}
@@ -580,7 +588,9 @@ public com.google.api.services.bigquery.model.Dataset call() throws IOException
580588
getOptions().getRetrySettings(),
581589
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
582590
getOptions().getClock(),
583-
EMPTY_RETRY_CONFIG);
591+
EMPTY_RETRY_CONFIG,
592+
getOptions().isOpenTelemetryTracingEnabled(),
593+
getOptions().getOpenTelemetryTracer());
584594
return Dataset.fromPb(this, answer);
585595
} catch (BigQueryRetryHelperException e) {
586596
if (isRetryErrorCodeHttpNotFound(e)) {
@@ -644,7 +654,9 @@ private static Page<Dataset> listDatasets(
644654
serviceOptions.getRetrySettings(),
645655
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
646656
serviceOptions.getClock(),
647-
EMPTY_RETRY_CONFIG);
657+
EMPTY_RETRY_CONFIG,
658+
serviceOptions.isOpenTelemetryTracingEnabled(),
659+
serviceOptions.getOpenTelemetryTracer());
648660
String cursor = result.x();
649661
return new PageImpl<>(
650662
new DatasetPageFetcher(projectId, serviceOptions, cursor, optionsMap),
@@ -694,7 +706,9 @@ public Boolean call() throws IOException {
694706
getOptions().getRetrySettings(),
695707
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
696708
getOptions().getClock(),
697-
EMPTY_RETRY_CONFIG);
709+
EMPTY_RETRY_CONFIG,
710+
getOptions().isOpenTelemetryTracingEnabled(),
711+
getOptions().getOpenTelemetryTracer());
698712
} catch (BigQueryRetryHelperException e) {
699713
if (isRetryErrorCodeHttpNotFound(e)) {
700714
return false;
@@ -743,7 +757,9 @@ public Boolean call() throws IOException {
743757
getOptions().getRetrySettings(),
744758
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
745759
getOptions().getClock(),
746-
EMPTY_RETRY_CONFIG);
760+
EMPTY_RETRY_CONFIG,
761+
getOptions().isOpenTelemetryTracingEnabled(),
762+
getOptions().getOpenTelemetryTracer());
747763
} catch (BigQueryRetryHelperException e) {
748764
if (isRetryErrorCodeHttpNotFound(e)) {
749765
return false;
@@ -787,7 +803,9 @@ public Boolean call() throws IOException {
787803
getOptions().getRetrySettings(),
788804
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
789805
getOptions().getClock(),
790-
EMPTY_RETRY_CONFIG);
806+
EMPTY_RETRY_CONFIG,
807+
getOptions().isOpenTelemetryTracingEnabled(),
808+
getOptions().getOpenTelemetryTracer());
791809
} catch (BigQueryRetryHelperException e) {
792810
if (isRetryErrorCodeHttpNotFound(e)) {
793811
return false;
@@ -831,7 +849,9 @@ public Boolean call() throws IOException {
831849
getOptions().getRetrySettings(),
832850
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
833851
getOptions().getClock(),
834-
EMPTY_RETRY_CONFIG);
852+
EMPTY_RETRY_CONFIG,
853+
getOptions().isOpenTelemetryTracingEnabled(),
854+
getOptions().getOpenTelemetryTracer());
835855
} catch (BigQueryRetryHelperException e) {
836856
if (isRetryErrorCodeHttpNotFound(e)) {
837857
return false;
@@ -873,7 +893,9 @@ public Boolean call() throws IOException {
873893
getOptions().getRetrySettings(),
874894
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
875895
getOptions().getClock(),
876-
EMPTY_RETRY_CONFIG);
896+
EMPTY_RETRY_CONFIG,
897+
getOptions().isOpenTelemetryTracingEnabled(),
898+
getOptions().getOpenTelemetryTracer());
877899
} catch (BigQueryRetryHelperException e) {
878900
throw BigQueryException.translateAndThrow(e);
879901
} finally {
@@ -912,7 +934,9 @@ public com.google.api.services.bigquery.model.Dataset call() throws IOException
912934
getOptions().getRetrySettings(),
913935
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
914936
getOptions().getClock(),
915-
EMPTY_RETRY_CONFIG));
937+
EMPTY_RETRY_CONFIG,
938+
getOptions().isOpenTelemetryTracingEnabled(),
939+
getOptions().getOpenTelemetryTracer()));
916940
} catch (BigQueryRetryHelperException e) {
917941
throw BigQueryException.translateAndThrow(e);
918942
} finally {
@@ -957,7 +981,9 @@ public com.google.api.services.bigquery.model.Table call() throws IOException {
957981
getOptions().getRetrySettings(),
958982
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
959983
getOptions().getClock(),
960-
EMPTY_RETRY_CONFIG));
984+
EMPTY_RETRY_CONFIG,
985+
getOptions().isOpenTelemetryTracingEnabled(),
986+
getOptions().getOpenTelemetryTracer()));
961987
} catch (BigQueryRetryHelperException e) {
962988
throw BigQueryException.translateAndThrow(e);
963989
} finally {
@@ -1001,7 +1027,9 @@ public com.google.api.services.bigquery.model.Model call() throws IOException {
10011027
getOptions().getRetrySettings(),
10021028
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
10031029
getOptions().getClock(),
1004-
EMPTY_RETRY_CONFIG));
1030+
EMPTY_RETRY_CONFIG,
1031+
getOptions().isOpenTelemetryTracingEnabled(),
1032+
getOptions().getOpenTelemetryTracer()));
10051033
} catch (BigQueryRetryHelperException e) {
10061034
throw BigQueryException.translateAndThrow(e);
10071035
} finally {
@@ -1045,7 +1073,9 @@ public com.google.api.services.bigquery.model.Routine call() throws IOException
10451073
getOptions().getRetrySettings(),
10461074
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
10471075
getOptions().getClock(),
1048-
EMPTY_RETRY_CONFIG));
1076+
EMPTY_RETRY_CONFIG,
1077+
getOptions().isOpenTelemetryTracingEnabled(),
1078+
getOptions().getOpenTelemetryTracer()));
10491079
} catch (BigQueryRetryHelperException e) {
10501080
throw BigQueryException.translateAndThrow(e);
10511081
} finally {
@@ -1097,7 +1127,9 @@ public com.google.api.services.bigquery.model.Table call() throws IOException {
10971127
getOptions().getRetrySettings(),
10981128
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
10991129
getOptions().getClock(),
1100-
EMPTY_RETRY_CONFIG);
1130+
EMPTY_RETRY_CONFIG,
1131+
getOptions().isOpenTelemetryTracingEnabled(),
1132+
getOptions().getOpenTelemetryTracer());
11011133
return Table.fromPb(this, answer);
11021134
} catch (BigQueryRetryHelperException e) {
11031135
if (isRetryErrorCodeHttpNotFound(e)) {
@@ -1154,7 +1186,9 @@ public com.google.api.services.bigquery.model.Model call() throws IOException {
11541186
getOptions().getRetrySettings(),
11551187
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
11561188
getOptions().getClock(),
1157-
EMPTY_RETRY_CONFIG);
1189+
EMPTY_RETRY_CONFIG,
1190+
getOptions().isOpenTelemetryTracingEnabled(),
1191+
getOptions().getOpenTelemetryTracer());
11581192
return Model.fromPb(this, answer);
11591193
} catch (BigQueryRetryHelperException e) {
11601194
if (isRetryErrorCodeHttpNotFound(e)) {
@@ -1211,7 +1245,9 @@ public com.google.api.services.bigquery.model.Routine call() throws IOException
12111245
getOptions().getRetrySettings(),
12121246
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
12131247
getOptions().getClock(),
1214-
EMPTY_RETRY_CONFIG);
1248+
EMPTY_RETRY_CONFIG,
1249+
getOptions().isOpenTelemetryTracingEnabled(),
1250+
getOptions().getOpenTelemetryTracer());
12151251
return Routine.fromPb(this, answer);
12161252
} catch (BigQueryRetryHelperException e) {
12171253
if (isRetryErrorCodeHttpNotFound(e)) {
@@ -1427,7 +1463,9 @@ public Tuple<String, Iterable<com.google.api.services.bigquery.model.Table>> cal
14271463
serviceOptions.getRetrySettings(),
14281464
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
14291465
serviceOptions.getClock(),
1430-
EMPTY_RETRY_CONFIG);
1466+
EMPTY_RETRY_CONFIG,
1467+
serviceOptions.isOpenTelemetryTracingEnabled(),
1468+
serviceOptions.getOpenTelemetryTracer());
14311469
String cursor = result.x();
14321470
Iterable<Table> tables =
14331471
Iterables.transform(
@@ -1466,7 +1504,9 @@ public Tuple<String, Iterable<com.google.api.services.bigquery.model.Model>> cal
14661504
serviceOptions.getRetrySettings(),
14671505
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
14681506
serviceOptions.getClock(),
1469-
EMPTY_RETRY_CONFIG);
1507+
EMPTY_RETRY_CONFIG,
1508+
serviceOptions.isOpenTelemetryTracingEnabled(),
1509+
serviceOptions.getOpenTelemetryTracer());
14701510
String cursor = result.x();
14711511
Iterable<Model> models =
14721512
Iterables.transform(
@@ -1505,7 +1545,9 @@ private static Page<Routine> listRoutines(
15051545
serviceOptions.getRetrySettings(),
15061546
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
15071547
serviceOptions.getClock(),
1508-
EMPTY_RETRY_CONFIG);
1548+
EMPTY_RETRY_CONFIG,
1549+
serviceOptions.isOpenTelemetryTracingEnabled(),
1550+
serviceOptions.getOpenTelemetryTracer());
15091551
String cursor = result.x();
15101552
Iterable<Routine> routines =
15111553
Iterables.transform(
@@ -1585,7 +1627,9 @@ public TableDataInsertAllResponse call() throws Exception {
15851627
getOptions().getRetrySettings(),
15861628
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
15871629
getOptions().getClock(),
1588-
EMPTY_RETRY_CONFIG);
1630+
EMPTY_RETRY_CONFIG,
1631+
getOptions().isOpenTelemetryTracingEnabled(),
1632+
getOptions().getOpenTelemetryTracer());
15891633
} catch (BigQueryRetryHelperException e) {
15901634
throw BigQueryException.translateAndThrow(e);
15911635
}
@@ -1677,7 +1721,9 @@ public TableDataList call() throws IOException {
16771721
serviceOptions.getRetrySettings(),
16781722
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
16791723
serviceOptions.getClock(),
1680-
EMPTY_RETRY_CONFIG);
1724+
EMPTY_RETRY_CONFIG,
1725+
serviceOptions.isOpenTelemetryTracingEnabled(),
1726+
serviceOptions.getOpenTelemetryTracer());
16811727
String cursor = result.getPageToken();
16821728
Map<BigQueryRpc.Option, ?> pageOptionMap =
16831729
Strings.isNullOrEmpty(cursor) ? optionsMap : optionMap(TableDataListOption.startIndex(0));
@@ -1749,7 +1795,9 @@ public com.google.api.services.bigquery.model.Job call() throws IOException {
17491795
getOptions().getRetrySettings(),
17501796
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
17511797
getOptions().getClock(),
1752-
EMPTY_RETRY_CONFIG);
1798+
EMPTY_RETRY_CONFIG,
1799+
getOptions().isOpenTelemetryTracingEnabled(),
1800+
getOptions().getOpenTelemetryTracer());
17531801
return Job.fromPb(this, answer);
17541802
} catch (BigQueryRetryHelperException e) {
17551803
if (isRetryErrorCodeHttpNotFound(e)) {
@@ -1804,7 +1852,9 @@ public Tuple<String, Iterable<com.google.api.services.bigquery.model.Job>> call(
18041852
serviceOptions.getRetrySettings(),
18051853
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
18061854
serviceOptions.getClock(),
1807-
EMPTY_RETRY_CONFIG);
1855+
EMPTY_RETRY_CONFIG,
1856+
serviceOptions.isOpenTelemetryTracingEnabled(),
1857+
serviceOptions.getOpenTelemetryTracer());
18081858
String cursor = result.x();
18091859
Iterable<Job> jobs =
18101860
Iterables.transform(
@@ -1857,7 +1907,9 @@ public Boolean call() throws IOException {
18571907
getOptions().getRetrySettings(),
18581908
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
18591909
getOptions().getClock(),
1860-
EMPTY_RETRY_CONFIG);
1910+
EMPTY_RETRY_CONFIG,
1911+
getOptions().isOpenTelemetryTracingEnabled(),
1912+
getOptions().getOpenTelemetryTracer());
18611913
} catch (BigQueryRetryHelperException e) {
18621914
if (isRetryErrorCodeHttpNotFound(e)) {
18631915
return false;
@@ -1942,7 +1994,9 @@ public com.google.api.services.bigquery.model.QueryResponse call()
19421994
getOptions().getRetrySettings(),
19431995
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
19441996
getOptions().getClock(),
1945-
DEFAULT_RETRY_CONFIG);
1997+
DEFAULT_RETRY_CONFIG,
1998+
getOptions().isOpenTelemetryTracingEnabled(),
1999+
getOptions().getOpenTelemetryTracer());
19462000
} catch (BigQueryRetryHelper.BigQueryRetryHelperException e) {
19472001
throw BigQueryException.translateAndThrow(e);
19482002
} finally {
@@ -2117,7 +2171,9 @@ public GetQueryResultsResponse call() throws IOException {
21172171
serviceOptions.getRetrySettings(),
21182172
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
21192173
serviceOptions.getClock(),
2120-
DEFAULT_RETRY_CONFIG);
2174+
DEFAULT_RETRY_CONFIG,
2175+
serviceOptions.isOpenTelemetryTracingEnabled(),
2176+
serviceOptions.getOpenTelemetryTracer());
21212177

21222178
TableSchema schemaPb = results.getSchema();
21232179

@@ -2186,7 +2242,9 @@ public com.google.api.services.bigquery.model.Policy call() throws IOException {
21862242
getOptions().getRetrySettings(),
21872243
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
21882244
getOptions().getClock(),
2189-
EMPTY_RETRY_CONFIG));
2245+
EMPTY_RETRY_CONFIG,
2246+
getOptions().isOpenTelemetryTracingEnabled(),
2247+
getOptions().getOpenTelemetryTracer()));
21902248
} catch (BigQueryRetryHelperException e) {
21912249
throw BigQueryException.translateAndThrow(e);
21922250
} finally {
@@ -2230,7 +2288,9 @@ public com.google.api.services.bigquery.model.Policy call() throws IOException {
22302288
getOptions().getRetrySettings(),
22312289
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
22322290
getOptions().getClock(),
2233-
EMPTY_RETRY_CONFIG));
2291+
EMPTY_RETRY_CONFIG,
2292+
getOptions().isOpenTelemetryTracingEnabled(),
2293+
getOptions().getOpenTelemetryTracer()));
22342294
} catch (BigQueryRetryHelperException e) {
22352295
throw BigQueryException.translateAndThrow(e);
22362296
} finally {
@@ -2276,7 +2336,9 @@ public com.google.api.services.bigquery.model.TestIamPermissionsResponse call()
22762336
getOptions().getRetrySettings(),
22772337
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
22782338
getOptions().getClock(),
2279-
EMPTY_RETRY_CONFIG);
2339+
EMPTY_RETRY_CONFIG,
2340+
getOptions().isOpenTelemetryTracingEnabled(),
2341+
getOptions().getOpenTelemetryTracer());
22802342
return response.getPermissions() == null
22812343
? ImmutableList.of()
22822344
: ImmutableList.copyOf(response.getPermissions());

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
import com.google.api.gax.retrying.RetryingFuture;
2626
import com.google.api.gax.retrying.TimedRetryAlgorithm;
2727
import com.google.cloud.RetryHelper;
28+
import io.opentelemetry.api.trace.Span;
29+
import io.opentelemetry.api.trace.Tracer;
30+
import io.opentelemetry.context.Scope;
2831
import java.io.IOException;
2932
import java.util.concurrent.Callable;
3033
import java.util.concurrent.ExecutionException;
@@ -40,9 +43,18 @@ public static <V> V runWithRetries(
4043
RetrySettings retrySettings,
4144
ResultRetryAlgorithm<?> resultRetryAlgorithm,
4245
ApiClock clock,
43-
BigQueryRetryConfig bigQueryRetryConfig)
46+
BigQueryRetryConfig bigQueryRetryConfig,
47+
boolean isOpenTelemetryEnabled,
48+
Tracer openTelemetryTracer)
4449
throws RetryHelperException {
45-
try {
50+
Span runWithRetries = null;
51+
if (isOpenTelemetryEnabled && openTelemetryTracer != null) {
52+
runWithRetries =
53+
openTelemetryTracer
54+
.spanBuilder("com.google.cloud.bigquery.BigQueryRetryHelper.runWithRetries")
55+
.startSpan();
56+
}
57+
try (Scope runWithRetriesScope = runWithRetries != null ? runWithRetries.makeCurrent() : null) {
4658
// Suppressing should be ok as a workaraund. Current and only ResultRetryAlgorithm
4759
// implementation does not use response at all, so ignoring its type is ok.
4860
@SuppressWarnings("unchecked")
@@ -59,6 +71,10 @@ public static <V> V runWithRetries(
5971
throw new BigQueryRetryHelperException(new BigQueryException((IOException) e.getCause()));
6072
}
6173
throw new BigQueryRetryHelperException(e.getCause());
74+
} finally {
75+
if (runWithRetries != null) {
76+
runWithRetries.end();
77+
}
6278
}
6379
}
6480

0 commit comments

Comments
 (0)

TMZ Celebrity News – Breaking Stories, Videos & Gossip

Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

🎥 Watch TMZ Live

TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.