27
27
_metadata_with_leader_aware_routing ,
28
28
)
29
29
from google .cloud .spanner_v1 ._opentelemetry_tracing import (
30
+ add_event_on_current_span ,
30
31
trace_call ,
31
- trace_end_explicitly ,
32
+ trace_call_end_lazily ,
32
33
)
33
34
from google .cloud .spanner_v1 import RequestOptions
34
35
from google .cloud .spanner_v1 ._helpers import _retry
@@ -50,9 +51,9 @@ def __init__(self, session):
50
51
super (_BatchBase , self ).__init__ (session )
51
52
self ._mutations = []
52
53
observability_options = getattr (
53
- self ._session .database , "observability_options" , None
54
+ self ._session ._database , "observability_options" , None
54
55
)
55
- self .__span = trace_end_explicitly (
56
+ self .__span = trace_call_end_lazily (
56
57
"CloudSpannerX." + type (self ).__name__ ,
57
58
self ._session ,
58
59
observability_options = observability_options ,
@@ -80,10 +81,9 @@ def insert(self, table, columns, values):
80
81
:type values: list of lists
81
82
:param values: Values to be modified.
82
83
"""
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
+ )
87
87
self ._mutations .append (Mutation (insert = _make_write_pb (table , columns , values )))
88
88
89
89
def update (self , table , columns , values ):
@@ -98,11 +98,10 @@ def update(self, table, columns, values):
98
98
:type values: list of lists
99
99
:param values: Values to be modified.
100
100
"""
101
- if self .__span :
102
- self .__span .add_event (
103
- "update mutations inserted" , dict (table = table , columns = columns )
104
- )
105
101
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
+ )
106
105
107
106
def insert_or_update (self , table , columns , values ):
108
107
"""Insert/update one or more table rows.
@@ -116,14 +115,14 @@ def insert_or_update(self, table, columns, values):
116
115
:type values: list of lists
117
116
:param values: Values to be modified.
118
117
"""
119
- if self .__span :
120
- self .__span .add_event (
121
- "insert_or_update mutations inserted" ,
122
- dict (table = table , columns = columns ),
123
- )
124
118
self ._mutations .append (
125
119
Mutation (insert_or_update = _make_write_pb (table , columns , values ))
126
120
)
121
+ add_event_on_span (
122
+ self .__span ,
123
+ "insert_or_update mutations added" ,
124
+ dict (table = table , columns = columns ),
125
+ )
127
126
128
127
def replace (self , table , columns , values ):
129
128
"""Replace one or more table rows.
@@ -137,11 +136,10 @@ def replace(self, table, columns, values):
137
136
:type values: list of lists
138
137
:param values: Values to be modified.
139
138
"""
140
- if self .__span :
141
- self .__span .add_event (
142
- "replace mutations inserted" , dict (table = table , columns = columns )
143
- )
144
139
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
+ )
145
143
146
144
def delete (self , table , keyset ):
147
145
"""Delete one or more table rows.
@@ -154,10 +152,7 @@ def delete(self, table, keyset):
154
152
"""
155
153
delete = Mutation .Delete (table = table , key_set = keyset ._to_pb ())
156
154
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 ))
161
156
162
157
163
158
class Batch (_BatchBase ):
@@ -261,9 +256,9 @@ def __enter__(self):
261
256
"""Begin ``with`` block."""
262
257
self ._check_state ()
263
258
observability_options = getattr (
264
- self ._session .database , "observability_options" , None
259
+ self ._session ._database , "observability_options" , None
265
260
)
266
- self .__span = trace_end_explicitly (
261
+ self .__span = trace_call_end_lazily (
267
262
"CloudSpanner.Batch" ,
268
263
self ._session ,
269
264
observability_options = observability_options ,
0 commit comments