1# Copyright 2017, OpenCensus Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15"""Export the trace spans by printing them out."""
16
17from opencensus.common.transports import sync
18from opencensus.trace import base_exporter
19
20
21class PrintExporter(base_exporter.Exporter):
22    """Export the spans by printing them.
23
24    :type transport: :class:`type`
25    :param transport: Class for creating new transport objects. It should
26                      extend from the base_exporter :class:`.Transport` type
27                      and implement :meth:`.Transport.export`. Defaults to
28                      :class:`.SyncTransport`. The other option is
29                      :class:`.AsyncTransport`.
30    """
31
32    def __init__(self, transport=sync.SyncTransport):
33        self.transport = transport(self)
34
35    def emit(self, span_datas):
36        """
37        :type span_datas: list of :class:
38            `~opencensus.trace.span_data.SpanData`
39        :param list of opencensus.trace.span_data.SpanData span_datas:
40            SpanData tuples to emit
41        """
42        print(span_datas)
43
44    def export(self, span_datas):
45        """
46        :type span_datas: list of :class:
47            `~opencensus.trace.span_data.SpanData`
48        :param list of opencensus.trace.span_data.SpanData span_datas:
49            SpanData tuples to export
50        """
51        self.transport.export(span_datas)
52