code: def translate_to_stackdriver(self, trace):
          
          set_attributes(trace)
          spans_json = trace.get('spans')
          trace_id = trace.get('traceId')
  
          for span in spans_json:
              span_name = 'projects/{}/traces/{}/spans/{}'.format(
                  self.project_id, trace_id, span.get('spanId'))
  
              span_json = {
                  'name': span_name,
                  'displayName': span.get('displayName'),
                  'startTime': span.get('startTime'),
                  'endTime': span.get('endTime'),
                  'spanId': str(span.get('spanId')),
                  'attributes': self.map_attributes(span.get('attributes')),
                  'links': span.get('links'),
                  'status': span.get('status'),
                  'stackTrace': span.get('stackTrace'),
                  'timeEvents': span.get('timeEvents'),
                  'sameProcessAsParentSpan': span.get('sameProcessAsParentSpan'),
                  'childSpanCount': span.get('childSpanCount')
              }
  
              if span.get('parentSpanId') is not None:
                  parent_span_id = str(span.get('parentSpanId'))
                  span_json['parentSpanId'] = parent_span_id
  
              yield span_json
docs: Translate the spans json to Stackdriver format.
  
          See: https://cloud.google.com/trace/docs/reference/v2/rest/v2/
               projects.traces/batchWrite
  
          :type trace: dict
          :param trace: Trace dictionary
  
          :rtype: dict
          :returns: Spans in Google Cloud StackDriver Trace format.