@@ -215,13 +215,15 @@ def emit(self, span_datas):
215215 for sd in span_datas :
216216 trace_span_map [sd .context .trace_id ] += [sd ]
217217
218+ stackdriver_spans = []
218219 # Write spans to Stackdriver
219220 for _ , sds in trace_span_map .items ():
220221 # convert to the legacy trace json for easier refactoring
221222 # TODO: refactor this to use the span data directly
222223 trace = span_data .format_legacy_trace_json (sds )
223- stackdriver_spans = self .translate_to_stackdriver (trace )
224- self .client .batch_write_spans (project , stackdriver_spans )
224+ stackdriver_spans .extend (self .translate_to_stackdriver (trace ))
225+
226+ self .client .batch_write_spans (project , {'spans' : stackdriver_spans })
225227
226228 def export (self , span_datas ):
227229 """
@@ -247,7 +249,6 @@ def translate_to_stackdriver(self, trace):
247249 set_attributes (trace )
248250 spans_json = trace .get ('spans' )
249251 trace_id = trace .get ('traceId' )
250- spans_list = []
251252
252253 for span in spans_json :
253254 span_name = 'projects/{}/traces/{}/spans/{}' .format (
@@ -272,10 +273,7 @@ def translate_to_stackdriver(self, trace):
272273 parent_span_id = str (span .get ('parentSpanId' ))
273274 span_json ['parentSpanId' ] = parent_span_id
274275
275- spans_list .append (span_json )
276-
277- spans = {'spans' : spans_list }
278- return spans
276+ yield span_json
279277
280278 def map_attributes (self , attribute_map ):
281279 if attribute_map is None :
0 commit comments