|
15 | 15 | import os |
16 | 16 |
|
17 | 17 | from opencensus.trace.exporters import base |
| 18 | +from opencensus.trace.exporters.transports import sync |
18 | 19 |
|
19 | 20 | from google.cloud.trace.client import Client |
20 | 21 |
|
@@ -73,23 +74,41 @@ def is_gae_environment(): |
73 | 74 | class StackdriverExporter(base.Exporter): |
74 | 75 | """A exporter that send traces and trace spans to Google Cloud Stackdriver |
75 | 76 | Trace. |
| 77 | +
|
| 78 | + :type client: :class: `~google.cloud.trace.client.Client` |
| 79 | + :param client: Stackdriver Trace client. |
| 80 | +
|
| 81 | + :type project_id: str |
| 82 | + :param project_id: project_id to create the Trace client. |
| 83 | +
|
| 84 | + :type transport: :class:`type` |
| 85 | + :param transport: Class for creating new transport objects. It should |
| 86 | + extend from the base :class:`.Transport` type and |
| 87 | + implement :meth`.Transport.export`. Defaults to |
| 88 | + :class:`.SyncTransport`. The other option is |
| 89 | + :class:`.BackgroundThreadTransport`. |
76 | 90 | """ |
77 | | - def __init__(self, client=None, project_id=None): |
| 91 | + def __init__(self, client=None, project_id=None, |
| 92 | + transport=sync.SyncTransport): |
78 | 93 | # The client will handler the case when project_id is None |
79 | 94 | if client is None: |
80 | 95 | client = Client(project=project_id) |
81 | 96 |
|
82 | 97 | self.client = client |
83 | 98 | self.project_id = client.project |
| 99 | + self.transport = transport(self) |
84 | 100 |
|
85 | | - def export(self, trace): |
| 101 | + def emit(self, trace): |
86 | 102 | """ |
87 | 103 | :type trace: dict |
88 | 104 | :param trace: Trace collected. |
89 | 105 | """ |
90 | 106 | stackdriver_traces = self.translate_to_stackdriver(trace) |
91 | 107 | self.client.patch_traces(stackdriver_traces) |
92 | 108 |
|
| 109 | + def export(self, trace): |
| 110 | + self.transport.export(trace) |
| 111 | + |
93 | 112 | def translate_to_stackdriver(self, trace): |
94 | 113 | """ |
95 | 114 | :type trace: dict |
|
0 commit comments