2727 _metadata_with_leader_aware_routing ,
2828)
2929from google .cloud .spanner_v1 ._opentelemetry_tracing import (
30+ add_event_on_current_span ,
3031 trace_call ,
31- trace_end_explicitly ,
32+ trace_call_end_lazily ,
3233)
3334from google .cloud .spanner_v1 import RequestOptions
3435from google .cloud .spanner_v1 ._helpers import _retry
@@ -50,9 +51,9 @@ def __init__(self, session):
5051 super (_BatchBase , self ).__init__ (session )
5152 self ._mutations = []
5253 observability_options = getattr (
53- self ._session .database , "observability_options" , None
54+ self ._session ._database , "observability_options" , None
5455 )
55- self .__span = trace_end_explicitly (
56+ self .__span = trace_call_end_lazily (
5657 "CloudSpannerX." + type (self ).__name__ ,
5758 self ._session ,
5859 observability_options = observability_options ,
@@ -80,10 +81,9 @@ def insert(self, table, columns, values):
8081 :type values: list of lists
8182 :param values: Values to be modified.
8283 """
83- if self .__span :
84- self .__span .add_event (
85- "insert mutations inserted" , dict (table = table , columns = columns )
86- )
84+ add_event_on_span (
85+ self .__span , "insert mutations added" , dict (table = table , columns = columns )
86+ )
8787 self ._mutations .append (Mutation (insert = _make_write_pb (table , columns , values )))
8888
8989 def update (self , table , columns , values ):
@@ -98,11 +98,10 @@ def update(self, table, columns, values):
9898 :type values: list of lists
9999 :param values: Values to be modified.
100100 """
101- if self .__span :
102- self .__span .add_event (
103- "update mutations inserted" , dict (table = table , columns = columns )
104- )
105101 self ._mutations .append (Mutation (update = _make_write_pb (table , columns , values )))
102+ add_event_on_span (
103+ self .__span , "update mutations added" , dict (table = table , columns = columns )
104+ )
106105
107106 def insert_or_update (self , table , columns , values ):
108107 """Insert/update one or more table rows.
@@ -116,14 +115,14 @@ def insert_or_update(self, table, columns, values):
116115 :type values: list of lists
117116 :param values: Values to be modified.
118117 """
119- if self .__span :
120- self .__span .add_event (
121- "insert_or_update mutations inserted" ,
122- dict (table = table , columns = columns ),
123- )
124118 self ._mutations .append (
125119 Mutation (insert_or_update = _make_write_pb (table , columns , values ))
126120 )
121+ add_event_on_span (
122+ self .__span ,
123+ "insert_or_update mutations added" ,
124+ dict (table = table , columns = columns ),
125+ )
127126
128127 def replace (self , table , columns , values ):
129128 """Replace one or more table rows.
@@ -137,11 +136,10 @@ def replace(self, table, columns, values):
137136 :type values: list of lists
138137 :param values: Values to be modified.
139138 """
140- if self .__span :
141- self .__span .add_event (
142- "replace mutations inserted" , dict (table = table , columns = columns )
143- )
144139 self ._mutations .append (Mutation (replace = _make_write_pb (table , columns , values )))
140+ add_event_on_span (
141+ self .__span , "replace mutations added" , dict (table = table , columns = columns )
142+ )
145143
146144 def delete (self , table , keyset ):
147145 """Delete one or more table rows.
@@ -154,10 +152,7 @@ def delete(self, table, keyset):
154152 """
155153 delete = Mutation .Delete (table = table , key_set = keyset ._to_pb ())
156154 self ._mutations .append (Mutation (delete = delete ))
157- if self .__span :
158- self .__span .add_event (
159- "delete mutations inserted" , dict (table = table , columns = columns )
160- )
155+ add_event_on_span (self .__span , "delete mutations added" , dict (table = table ))
161156
162157
163158class Batch (_BatchBase ):
@@ -261,9 +256,9 @@ def __enter__(self):
261256 """Begin ``with`` block."""
262257 self ._check_state ()
263258 observability_options = getattr (
264- self ._session .database , "observability_options" , None
259+ self ._session ._database , "observability_options" , None
265260 )
266- self .__span = trace_end_explicitly (
261+ self .__span = trace_call_end_lazily (
267262 "CloudSpanner.Batch" ,
268263 self ._session ,
269264 observability_options = observability_options ,
0 commit comments