2626import com .google .common .base .Function ;
2727import com .google .common .util .concurrent .ListenableFuture ;
2828import com .google .spanner .v1 .BatchWriteResponse ;
29+ import io .opentelemetry .api .common .Attributes ;
2930import javax .annotation .Nullable ;
3031
3132class DatabaseClientImpl implements DatabaseClient {
3233 private static final String READ_WRITE_TRANSACTION = "CloudSpanner.ReadWriteTransaction" ;
3334 private static final String READ_ONLY_TRANSACTION = "CloudSpanner.ReadOnlyTransaction" ;
3435 private static final String PARTITION_DML_TRANSACTION = "CloudSpanner.PartitionDMLTransaction" ;
3536 private final TraceWrapper tracer ;
37+ private Attributes commonAttributes ;
3638 @ VisibleForTesting final String clientId ;
3739 @ VisibleForTesting final SessionPool pool ;
3840 @ VisibleForTesting final MultiplexedSessionDatabaseClient multiplexedSessionDatabaseClient ;
@@ -50,7 +52,8 @@ class DatabaseClientImpl implements DatabaseClient {
5052 /* multiplexedSessionDatabaseClient = */ null ,
5153 /* useMultiplexedSessionPartitionedOps= */ false ,
5254 tracer ,
53- /* useMultiplexedSessionForRW = */ false );
55+ /* useMultiplexedSessionForRW = */ false ,
56+ Attributes .empty ());
5457 }
5558
5659 @ VisibleForTesting
@@ -62,7 +65,8 @@ class DatabaseClientImpl implements DatabaseClient {
6265 /* multiplexedSessionDatabaseClient = */ null ,
6366 /* useMultiplexedSessionPartitionedOps= */ false ,
6467 tracer ,
65- /* useMultiplexedSessionForRW = */ false );
68+ /* useMultiplexedSessionForRW = */ false ,
69+ Attributes .empty ());
6670 }
6771
6872 DatabaseClientImpl (
@@ -72,14 +76,16 @@ class DatabaseClientImpl implements DatabaseClient {
7276 @ Nullable MultiplexedSessionDatabaseClient multiplexedSessionDatabaseClient ,
7377 boolean useMultiplexedSessionPartitionedOps ,
7478 TraceWrapper tracer ,
75- boolean useMultiplexedSessionForRW ) {
79+ boolean useMultiplexedSessionForRW ,
80+ Attributes commonAttributes ) {
7681 this .clientId = clientId ;
7782 this .pool = pool ;
7883 this .useMultiplexedSessionBlindWrite = useMultiplexedSessionBlindWrite ;
7984 this .multiplexedSessionDatabaseClient = multiplexedSessionDatabaseClient ;
8085 this .useMultiplexedSessionPartitionedOps = useMultiplexedSessionPartitionedOps ;
8186 this .tracer = tracer ;
8287 this .useMultiplexedSessionForRW = useMultiplexedSessionForRW ;
88+ this .commonAttributes = commonAttributes ;
8389 }
8490
8591 @ VisibleForTesting
@@ -138,7 +144,7 @@ public Timestamp write(final Iterable<Mutation> mutations) throws SpannerExcepti
138144 public CommitResponse writeWithOptions (
139145 final Iterable <Mutation > mutations , final TransactionOption ... options )
140146 throws SpannerException {
141- ISpan span = tracer .spanBuilder (READ_WRITE_TRANSACTION , options );
147+ ISpan span = tracer .spanBuilder (READ_WRITE_TRANSACTION , commonAttributes , options );
142148 try (IScope s = tracer .withSpan (span )) {
143149 if (canUseMultiplexedSessionsForRW () && getMultiplexedSessionDatabaseClient () != null ) {
144150 return getMultiplexedSessionDatabaseClient ().writeWithOptions (mutations , options );
@@ -161,7 +167,7 @@ public Timestamp writeAtLeastOnce(final Iterable<Mutation> mutations) throws Spa
161167 public CommitResponse writeAtLeastOnceWithOptions (
162168 final Iterable <Mutation > mutations , final TransactionOption ... options )
163169 throws SpannerException {
164- ISpan span = tracer .spanBuilder (READ_WRITE_TRANSACTION , options );
170+ ISpan span = tracer .spanBuilder (READ_WRITE_TRANSACTION , commonAttributes , options );
165171 try (IScope s = tracer .withSpan (span )) {
166172 if (useMultiplexedSessionBlindWrite && getMultiplexedSessionDatabaseClient () != null ) {
167173 return getMultiplexedSessionDatabaseClient ()
@@ -181,7 +187,7 @@ public CommitResponse writeAtLeastOnceWithOptions(
181187 public ServerStream <BatchWriteResponse > batchWriteAtLeastOnce (
182188 final Iterable <MutationGroup > mutationGroups , final TransactionOption ... options )
183189 throws SpannerException {
184- ISpan span = tracer .spanBuilder (READ_WRITE_TRANSACTION , options );
190+ ISpan span = tracer .spanBuilder (READ_WRITE_TRANSACTION , commonAttributes , options );
185191 try (IScope s = tracer .withSpan (span )) {
186192 return runWithSessionRetry (session -> session .batchWriteAtLeastOnce (mutationGroups , options ));
187193 } catch (RuntimeException e ) {
@@ -194,7 +200,7 @@ public ServerStream<BatchWriteResponse> batchWriteAtLeastOnce(
194200
195201 @ Override
196202 public ReadContext singleUse () {
197- ISpan span = tracer .spanBuilder (READ_ONLY_TRANSACTION );
203+ ISpan span = tracer .spanBuilder (READ_ONLY_TRANSACTION , commonAttributes );
198204 try (IScope s = tracer .withSpan (span )) {
199205 return getMultiplexedSession ().singleUse ();
200206 } catch (RuntimeException e ) {
@@ -206,7 +212,7 @@ public ReadContext singleUse() {
206212
207213 @ Override
208214 public ReadContext singleUse (TimestampBound bound ) {
209- ISpan span = tracer .spanBuilder (READ_ONLY_TRANSACTION );
215+ ISpan span = tracer .spanBuilder (READ_ONLY_TRANSACTION , commonAttributes );
210216 try (IScope s = tracer .withSpan (span )) {
211217 return getMultiplexedSession ().singleUse (bound );
212218 } catch (RuntimeException e ) {
@@ -218,7 +224,7 @@ public ReadContext singleUse(TimestampBound bound) {
218224
219225 @ Override
220226 public ReadOnlyTransaction singleUseReadOnlyTransaction () {
221- ISpan span = tracer .spanBuilder (READ_ONLY_TRANSACTION );
227+ ISpan span = tracer .spanBuilder (READ_ONLY_TRANSACTION , commonAttributes );
222228 try (IScope s = tracer .withSpan (span )) {
223229 return getMultiplexedSession ().singleUseReadOnlyTransaction ();
224230 } catch (RuntimeException e ) {
@@ -230,7 +236,7 @@ public ReadOnlyTransaction singleUseReadOnlyTransaction() {
230236
231237 @ Override
232238 public ReadOnlyTransaction singleUseReadOnlyTransaction (TimestampBound bound ) {
233- ISpan span = tracer .spanBuilder (READ_ONLY_TRANSACTION );
239+ ISpan span = tracer .spanBuilder (READ_ONLY_TRANSACTION , commonAttributes );
234240 try (IScope s = tracer .withSpan (span )) {
235241 return getMultiplexedSession ().singleUseReadOnlyTransaction (bound );
236242 } catch (RuntimeException e ) {
@@ -242,7 +248,7 @@ public ReadOnlyTransaction singleUseReadOnlyTransaction(TimestampBound bound) {
242248
243249 @ Override
244250 public ReadOnlyTransaction readOnlyTransaction () {
245- ISpan span = tracer .spanBuilder (READ_ONLY_TRANSACTION );
251+ ISpan span = tracer .spanBuilder (READ_ONLY_TRANSACTION , commonAttributes );
246252 try (IScope s = tracer .withSpan (span )) {
247253 return getMultiplexedSession ().readOnlyTransaction ();
248254 } catch (RuntimeException e ) {
@@ -254,7 +260,7 @@ public ReadOnlyTransaction readOnlyTransaction() {
254260
255261 @ Override
256262 public ReadOnlyTransaction readOnlyTransaction (TimestampBound bound ) {
257- ISpan span = tracer .spanBuilder (READ_ONLY_TRANSACTION );
263+ ISpan span = tracer .spanBuilder (READ_ONLY_TRANSACTION , commonAttributes );
258264 try (IScope s = tracer .withSpan (span )) {
259265 return getMultiplexedSession ().readOnlyTransaction (bound );
260266 } catch (RuntimeException e ) {
@@ -266,7 +272,7 @@ public ReadOnlyTransaction readOnlyTransaction(TimestampBound bound) {
266272
267273 @ Override
268274 public TransactionRunner readWriteTransaction (TransactionOption ... options ) {
269- ISpan span = tracer .spanBuilder (READ_WRITE_TRANSACTION , options );
275+ ISpan span = tracer .spanBuilder (READ_WRITE_TRANSACTION , commonAttributes , options );
270276 try (IScope s = tracer .withSpan (span )) {
271277 return getMultiplexedSessionForRW ().readWriteTransaction (options );
272278 } catch (RuntimeException e ) {
@@ -278,7 +284,7 @@ public TransactionRunner readWriteTransaction(TransactionOption... options) {
278284
279285 @ Override
280286 public TransactionManager transactionManager (TransactionOption ... options ) {
281- ISpan span = tracer .spanBuilder (READ_WRITE_TRANSACTION , options );
287+ ISpan span = tracer .spanBuilder (READ_WRITE_TRANSACTION , commonAttributes , options );
282288 try (IScope s = tracer .withSpan (span )) {
283289 return getMultiplexedSessionForRW ().transactionManager (options );
284290 } catch (RuntimeException e ) {
@@ -290,7 +296,7 @@ public TransactionManager transactionManager(TransactionOption... options) {
290296
291297 @ Override
292298 public AsyncRunner runAsync (TransactionOption ... options ) {
293- ISpan span = tracer .spanBuilder (READ_WRITE_TRANSACTION , options );
299+ ISpan span = tracer .spanBuilder (READ_WRITE_TRANSACTION , commonAttributes , options );
294300 try (IScope s = tracer .withSpan (span )) {
295301 return getMultiplexedSessionForRW ().runAsync (options );
296302 } catch (RuntimeException e ) {
@@ -302,7 +308,7 @@ public AsyncRunner runAsync(TransactionOption... options) {
302308
303309 @ Override
304310 public AsyncTransactionManager transactionManagerAsync (TransactionOption ... options ) {
305- ISpan span = tracer .spanBuilder (READ_WRITE_TRANSACTION , options );
311+ ISpan span = tracer .spanBuilder (READ_WRITE_TRANSACTION , commonAttributes , options );
306312 try (IScope s = tracer .withSpan (span )) {
307313 return getMultiplexedSessionForRW ().transactionManagerAsync (options );
308314 } catch (RuntimeException e ) {
@@ -322,7 +328,7 @@ public long executePartitionedUpdate(final Statement stmt, final UpdateOption...
322328
323329 private long executePartitionedUpdateWithPooledSession (
324330 final Statement stmt , final UpdateOption ... options ) {
325- ISpan span = tracer .spanBuilder (PARTITION_DML_TRANSACTION );
331+ ISpan span = tracer .spanBuilder (PARTITION_DML_TRANSACTION , commonAttributes );
326332 try (IScope s = tracer .withSpan (span )) {
327333 return runWithSessionRetry (session -> session .executePartitionedUpdate (stmt , options ));
328334 } catch (RuntimeException e ) {
0 commit comments