@@ -865,6 +865,17 @@ public boolean delete(JobId jobId) {
865865 Strings .isNullOrEmpty (jobId .getProject ())
866866 ? getOptions ().getProjectId ()
867867 : jobId .getProject ());
868+ Span jobDelete = null ;
869+ if (getOptions ().isOpenTelemetryTracingEnabled ()
870+ && getOptions ().getOpenTelemetryTracer () != null ) {
871+ jobDelete =
872+ getOptions ()
873+ .getOpenTelemetryTracer ()
874+ .spanBuilder ("com.google.cloud.bigquery.BigQuery.deleteJob" )
875+ .setAttribute ("language" , "Java" )
876+ .setAllAttributes (completeJobId .getOtelAttributes ())
877+ .startSpan ();
878+ }
868879 try {
869880 return BigQueryRetryHelper .runWithRetries (
870881 new Callable <Boolean >() {
@@ -880,6 +891,10 @@ public Boolean call() throws IOException {
880891 EMPTY_RETRY_CONFIG );
881892 } catch (BigQueryRetryHelperException e ) {
882893 throw BigQueryException .translateAndThrow (e );
894+ } finally {
895+ if (jobDelete != null ) {
896+ jobDelete .end ();
897+ }
883898 }
884899 }
885900
@@ -1381,26 +1396,43 @@ && getOptions().getOpenTelemetryTracer() != null) {
13811396
13821397 @ Override
13831398 public List <String > listPartitions (TableId tableId ) {
1384- List <String > partitions = new ArrayList <String >();
1385- String partitionsTable = tableId .getTable () + "$__PARTITIONS_SUMMARY__" ;
1386- TableId metaTableId =
1387- tableId .getProject () == null
1388- ? TableId .of (tableId .getDataset (), partitionsTable )
1389- : TableId .of (tableId .getProject (), tableId .getDataset (), partitionsTable );
1390- Table metaTable = getTable (metaTableId );
1391- Schema metaSchema = metaTable .getDefinition ().getSchema ();
1392- String partition_id = null ;
1393- for (Field field : metaSchema .getFields ()) {
1394- if (field .getName ().equals ("partition_id" )) {
1395- partition_id = field .getName ();
1396- break ;
1397- }
1399+ Span listPartitions = null ;
1400+ if (getOptions ().isOpenTelemetryTracingEnabled ()
1401+ && getOptions ().getOpenTelemetryTracer () != null ) {
1402+ listPartitions =
1403+ getOptions ()
1404+ .getOpenTelemetryTracer ()
1405+ .spanBuilder ("com.google.cloud.bigquery.BigQuery.listPartitions" )
1406+ .setAttribute ("language" , "Java" )
1407+ .setAllAttributes (tableId .getOtelAttributes ())
1408+ .startSpan ();
13981409 }
1399- TableResult result = metaTable .list (metaSchema );
1400- for (FieldValueList list : result .iterateAll ()) {
1401- partitions .add (list .get (partition_id ).getStringValue ());
1410+ try (Scope listPartitionsScope = listPartitions != null ? listPartitions .makeCurrent () : null ) {
1411+ List <String > partitions = new ArrayList <String >();
1412+ String partitionsTable = tableId .getTable () + "$__PARTITIONS_SUMMARY__" ;
1413+ TableId metaTableId =
1414+ tableId .getProject () == null
1415+ ? TableId .of (tableId .getDataset (), partitionsTable )
1416+ : TableId .of (tableId .getProject (), tableId .getDataset (), partitionsTable );
1417+ Table metaTable = getTable (metaTableId );
1418+ Schema metaSchema = metaTable .getDefinition ().getSchema ();
1419+ String partition_id = null ;
1420+ for (Field field : metaSchema .getFields ()) {
1421+ if (field .getName ().equals ("partition_id" )) {
1422+ partition_id = field .getName ();
1423+ break ;
1424+ }
1425+ }
1426+ TableResult result = metaTable .list (metaSchema );
1427+ for (FieldValueList list : result .iterateAll ()) {
1428+ partitions .add (list .get (partition_id ).getStringValue ());
1429+ }
1430+ return partitions ;
1431+ } finally {
1432+ if (listPartitions != null ) {
1433+ listPartitions .end ();
1434+ }
14021435 }
1403- return partitions ;
14041436 }
14051437
14061438 private static Page <Table > listTables (
@@ -1883,20 +1915,38 @@ public TableResult query(QueryJobConfiguration configuration, JobOption... optio
18831915 .setJobCreationMode (getOptions ().getDefaultJobCreationMode ())
18841916 .build ();
18851917
1886- // If all parameters passed in configuration are supported by the query() method on the backend,
1887- // put on fast path
1888- QueryRequestInfo requestInfo =
1889- new QueryRequestInfo (configuration , getOptions ().getUseInt64Timestamps ());
1890- if (requestInfo .isFastQuerySupported (null )) {
1891- String projectId = getOptions ().getProjectId ();
1892- QueryRequest content = requestInfo .toPb ();
1893- if (getOptions ().getLocation () != null ) {
1894- content .setLocation (getOptions ().getLocation ());
1918+ Span querySpan = null ;
1919+ if (getOptions ().isOpenTelemetryTracingEnabled ()
1920+ && getOptions ().getOpenTelemetryTracer () != null ) {
1921+ querySpan =
1922+ getOptions ()
1923+ .getOpenTelemetryTracer ()
1924+ .spanBuilder ("com.google.cloud.bigquery.BigQuery.query" )
1925+ .setAllAttributes (configuration .getOtelAttributes ())
1926+ .setAllAttributes (otelAttributesFromOptions (options ))
1927+ .startSpan ();
1928+ }
1929+ try (Scope queryScope = querySpan != null ? querySpan .makeCurrent () : null ) {
1930+ // If all parameters passed in configuration are supported by the query() method on the
1931+ // backend,
1932+ // put on fast path
1933+ QueryRequestInfo requestInfo =
1934+ new QueryRequestInfo (configuration , getOptions ().getUseInt64Timestamps ());
1935+ if (requestInfo .isFastQuerySupported (null )) {
1936+ String projectId = getOptions ().getProjectId ();
1937+ QueryRequest content = requestInfo .toPb ();
1938+ if (getOptions ().getLocation () != null ) {
1939+ content .setLocation (getOptions ().getLocation ());
1940+ }
1941+ return queryRpc (projectId , content , options );
1942+ }
1943+ // Otherwise, fall back to the existing create query job logic
1944+ return create (JobInfo .of (configuration ), options ).getQueryResults ();
1945+ } finally {
1946+ if (querySpan != null ) {
1947+ querySpan .end ();
18951948 }
1896- return queryRpc (projectId , content , options );
18971949 }
1898- // Otherwise, fall back to the existing create query job logic
1899- return create (JobInfo .of (configuration ), options ).getQueryResults ();
19001950 }
19011951
19021952 private TableResult queryRpc (
@@ -2005,31 +2055,51 @@ public TableResult query(QueryJobConfiguration configuration, JobId jobId, JobOp
20052055 throws InterruptedException , JobException {
20062056 Job .checkNotDryRun (configuration , "query" );
20072057
2008- // If all parameters passed in configuration are supported by the query() method on the backend,
2009- // put on fast path
2010- QueryRequestInfo requestInfo =
2011- new QueryRequestInfo (configuration , getOptions ().getUseInt64Timestamps ());
2012- if (requestInfo .isFastQuerySupported (jobId )) {
2013- // Be careful when setting the projectID in JobId, if a projectID is specified in the JobId,
2014- // the job created by the query method will use that project. This may cause the query to
2015- // fail with "Access denied" if the project do not have enough permissions to run the job.
2016-
2017- String projectId =
2018- jobId .getProject () != null ? jobId .getProject () : getOptions ().getProjectId ();
2019- QueryRequest content = requestInfo .toPb ();
2020- // Be careful when setting the location, if a location is specified in the BigQueryOption or
2021- // JobId the job created by the query method will be in that location, even if the table to be
2022- // queried is in a different location. This may cause the query to fail with
2023- // "BigQueryException: Not found"
2024- if (jobId .getLocation () != null ) {
2025- content .setLocation (jobId .getLocation ());
2026- } else if (getOptions ().getLocation () != null ) {
2027- content .setLocation (getOptions ().getLocation ());
2028- }
2058+ Span querySpan = null ;
2059+ if (getOptions ().isOpenTelemetryTracingEnabled ()
2060+ && getOptions ().getOpenTelemetryTracer () != null ) {
2061+ querySpan =
2062+ getOptions ()
2063+ .getOpenTelemetryTracer ()
2064+ .spanBuilder ("com.google.cloud.bigquery.BigQuery.query" )
2065+ .setAllAttributes (configuration .getOtelAttributes ())
2066+ .setAllAttributes (jobId .getOtelAttributes ())
2067+ .setAllAttributes (otelAttributesFromOptions (options ))
2068+ .startSpan ();
2069+ }
2070+ try (Scope queryScope = querySpan != null ? querySpan .makeCurrent () : null ) {
2071+ // If all parameters passed in configuration are supported by the query() method on the
2072+ // backend,
2073+ // put on fast path
2074+ QueryRequestInfo requestInfo =
2075+ new QueryRequestInfo (configuration , getOptions ().getUseInt64Timestamps ());
2076+ if (requestInfo .isFastQuerySupported (jobId )) {
2077+ // Be careful when setting the projectID in JobId, if a projectID is specified in the JobId,
2078+ // the job created by the query method will use that project. This may cause the query to
2079+ // fail with "Access denied" if the project do not have enough permissions to run the job.
2080+
2081+ String projectId =
2082+ jobId .getProject () != null ? jobId .getProject () : getOptions ().getProjectId ();
2083+ QueryRequest content = requestInfo .toPb ();
2084+ // Be careful when setting the location, if a location is specified in the BigQueryOption or
2085+ // JobId the job created by the query method will be in that location, even if the table to
2086+ // be
2087+ // queried is in a different location. This may cause the query to fail with
2088+ // "BigQueryException: Not found"
2089+ if (jobId .getLocation () != null ) {
2090+ content .setLocation (jobId .getLocation ());
2091+ } else if (getOptions ().getLocation () != null ) {
2092+ content .setLocation (getOptions ().getLocation ());
2093+ }
20292094
2030- return queryRpc (projectId , content , options );
2095+ return queryRpc (projectId , content , options );
2096+ }
2097+ return create (JobInfo .of (jobId , configuration ), options ).getQueryResults ();
2098+ } finally {
2099+ if (querySpan != null ) {
2100+ querySpan .end ();
2101+ }
20312102 }
2032- return create (JobInfo .of (jobId , configuration ), options ).getQueryResults ();
20332103 }
20342104
20352105 @ Override
@@ -2299,8 +2369,6 @@ private static Attributes otelAttributesFromQueryRequest(QueryRequest request) {
22992369 .put ("location" , getFieldAsString (request .getLocation ()))
23002370 .put ("maxResults" , getFieldAsString (request .getMaxResults ()))
23012371 .put ("maximumBytesBilled" , getFieldAsString (request .getMaximumBytesBilled ()))
2302- .put ("query" , getFieldAsString (request .getQuery ()))
2303- .put ("queryParameters" , getFieldAsString (request .getQueryParameters ()))
23042372 .put ("requestId" , getFieldAsString (request .getRequestId ()))
23052373 .put ("reservation" , getFieldAsString (request .getReservation ()))
23062374 .put ("timeoutMs" , getFieldAsString (request .getTimeoutMs ()))
0 commit comments