def emit(self, span_datas):
        """
        :type span_datas: list of :class:
            `~opencensus.trace.span_data.SpanData`
        :param list of opencensus.trace.span_data.SpanData span_datas:
            SpanData tuples to emit
        """
        project = 'projects/{}'.format(self.project_id)

        # Map each span data to it's corresponding trace id
        trace_span_map = defaultdict(list)
        for sd in span_datas:
            trace_span_map[sd.context.trace_id] += [sd]

        stackdriver_spans = []
        # Write spans to Stackdriver
        for _, sds in trace_span_map.items():
            # convert to the legacy trace json for easier refactoring
            # TODO: refactor this to use the span data directly
            trace = span_data.format_legacy_trace_json(sds)
            stackdriver_spans.extend(self.translate_to_stackdriver(trace))

        self.client.batch_write_spans(project, {'spans': stackdriver_spans})
def emit ( self , span_datas ) : project = 'projects/{}' . format ( self . project_id ) trace_span_map = defaultdict ( list ) for sd in span_datas : trace_span_map [ sd . context . trace_id ] += [ sd ] stackdriver_spans = [ ] for _ , sds in trace_span_map . items ( ) : trace = span_data . format_legacy_trace_json ( sds ) stackdriver_spans . extend ( self . translate_to_stackdriver ( trace ) ) self . client . batch_write_spans ( project , { 'spans' : stackdriver_spans } )
:type span_datas: list of :class:
            `~opencensus.trace.span_data.SpanData`
        :param list of opencensus.trace.span_data.SpanData span_datas:
            SpanData tuples to emit