Skip to content

Commit cfcfda5

Browse files
authored
Restructure tracers (census-instrumentation#97)
1 parent 7738266 commit cfcfda5

File tree

25 files changed

+99
-335
lines changed

25 files changed

+99
-335
lines changed

README.rst

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,24 @@ Installation & basic usage
3030

3131
.. code:: python
3232
33-
from opencensus.trace import request_tracer
33+
from opencensus.trace import tracer as tracer_module
3434
35-
tracer = request_tracer.RequestTracer()
35+
tracer = tracer_module.Tracer()
3636
3737
.. _pip: https://pip.pypa.io
3838
.. _pipenv: https://docs.pipenv.org/
3939

4040
Usage
4141
-----
4242

43-
You can collect traces using the ``RequestTracer`` `context manager`_:
43+
You can collect traces using the ``Tracer`` `context manager`_:
4444

4545
.. code:: python
4646
47-
from opencensus.trace import request_tracer
47+
from opencensus.trace import tracer as tracer_module
4848
4949
# Initialize a tracer, by default using the `PrintExporter`
50-
tracer = request_tracer.RequestTracer()
50+
tracer = tracer_module.Tracer()
5151
5252
# Example for creating nested spans
5353
with tracer.span(name='span1') as span1:
@@ -65,10 +65,10 @@ Alternatively, you can explicitly start and end a span:
6565

6666
.. code:: python
6767
68-
from opencensus.trace import request_tracer
68+
from opencensus.trace import tracer as tracer_module
6969
7070
# Initialize a tracer, by default using the `PrintExporter`
71-
tracer = request_tracer.RequestTracer()
71+
tracer = tracer_module.Tracer()
7272
7373
tracer.start_span(name='span1')
7474
do_something_to_trace()
@@ -91,11 +91,11 @@ and ``ProbabilitySampler``
9191
.. code:: python
9292
9393
from opencensus.trace.samplers import probability
94-
from opencensus.trace import request_tracer
94+
from opencensus.trace import tracer as tracer_module
9595
9696
# Sampling the requests at the rate equals 0.5
9797
sampler = probability.ProbabilitySampler(rate=0.5)
98-
tracer = request_tracer.RequestTracer(sampler=sampler)
98+
tracer = tracer_module.Tracer(sampler=sampler)
9999
100100
Exporters
101101
~~~~~~~~~
@@ -111,7 +111,7 @@ file:
111111
.. code:: python
112112
113113
from opencensus.trace.exporters import file_exporter
114-
from opencensus.trace.tracer import context_tracer
114+
from opencensus.trace.tracers import context_tracer
115115
116116
exporter = file_exporter.FileExporter(file_name='traces')
117117
tracer = context_tracer.ContextTracer(exporter=exporter)
@@ -121,11 +121,11 @@ This example shows how to report the traces to Stackdriver Trace:
121121
.. code:: python
122122
123123
from opencensus.trace.exporters import stackdriver_exporter
124-
from opencensus.trace import request_tracer
124+
from opencensus.trace import tracer as tracer_module
125125
126126
exporter = stackdriver_exporter.StackdriverExporter(
127127
project_id='your_cloud_project')
128-
tracer = request_tracer.RequestTracer(exporter=exporter)
128+
tracer = tracer_module.Tracer(exporter=exporter)
129129
130130
Propagators
131131
~~~~~~~~~~~
@@ -253,19 +253,6 @@ setting in ``settings.py``:
253253
'ZIPKIN_EXPORTER_PORT': 9411,
254254
}
255255
256-
Webapp2
257-
~~~~~~~
258-
259-
.. code:: python
260-
261-
from opencensus.trace.tracer import webapp2_tracer
262-
263-
tracer = webapp2_tracer.WebApp2Tracer()
264-
265-
with tracer.span(name='span1'):
266-
do_something_to_trace()
267-
268-
269256
Service Integration
270257
-------------------
271258

@@ -276,7 +263,7 @@ services to census:
276263
.. code:: python
277264
278265
from opencensus.trace import config_integration
279-
from opencensus.trace import request_tracer
266+
from opencensus.trace import tracer as tracer_module
280267
281268
import mysql.connector
282269

docs/trace/api/context_tracer.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Context Tracer
22
==============
33

4-
.. automodule:: opencensus.trace.tracer.context_tracer
4+
.. automodule:: opencensus.trace.tracers.context_tracer
55
:members:
66
:show-inheritance:

docs/trace/api/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ API Documentation
55

66
span
77
span_context
8-
request_tracer
8+
tracer
99
execution_context
1010
trace_options
1111
always_on_sampler

docs/trace/api/noop_tracer.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Noop Tracer
22
===========
33

4-
.. automodule:: opencensus.trace.tracer.noop_tracer
4+
.. automodule:: opencensus.trace.tracers.noop_tracer
55
:members:
66
:show-inheritance:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Request Tracer
22
==============
33

4-
.. automodule:: opencensus.trace.request_tracer
4+
.. automodule:: opencensus.trace.tracer
55
:members:
66
:show-inheritance:

docs/trace/usage.rst

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,24 @@ Installation & basic usage
3030

3131
.. code:: python
3232
33-
from opencensus.trace import request_tracer
33+
from opencensus.trace import tracer as tracer_module
3434
35-
tracer = request_tracer.RequestTracer()
35+
tracer = tracer_module.Tracer()
3636
3737
.. _pip: https://pip.pypa.io
3838
.. _pipenv: https://docs.pipenv.org/
3939

4040
Usage
4141
-----
4242

43-
You can collect traces using the ``RequestTracer`` `context manager`_:
43+
You can collect traces using the ``Tracer`` `context manager`_:
4444

4545
.. code:: python
4646
47-
from opencensus.trace import request_tracer
47+
from opencensus.trace import tracer as tracer_module
4848
4949
# Initialize a tracer, by default using the `PrintExporter`
50-
tracer = request_tracer.RequestTracer()
50+
tracer = tracer_module.Tracer()
5151
5252
# Example for creating nested spans
5353
with tracer.span(name='span1') as span1:
@@ -65,10 +65,10 @@ Alternatively, you can explicitly start and end a span:
6565

6666
.. code:: python
6767
68-
from opencensus.trace import request_tracer
68+
from opencensus.trace import tracer as tracer_module
6969
7070
# Initialize a tracer, by default using the `PrintExporter`
71-
tracer = request_tracer.RequestTracer()
71+
tracer = tracer_module.Tracer()
7272
7373
tracer.start_span(name='span1')
7474
do_something_to_trace()
@@ -91,11 +91,11 @@ and ``ProbabilitySampler``
9191
.. code:: python
9292
9393
from opencensus.trace.samplers import probability
94-
from opencensus.trace import request_tracer
94+
from opencensus.trace import tracer as tracer_module
9595
9696
# Sampling the requests at the rate equals 0.5
9797
sampler = probability.ProbabilitySampler(rate=0.5)
98-
tracer = request_tracer.RequestTracer(sampler=sampler)
98+
tracer = tracer_module.Tracer(sampler=sampler)
9999
100100
Exporters
101101
~~~~~~~~~
@@ -111,7 +111,7 @@ file:
111111
.. code:: python
112112
113113
from opencensus.trace.exporters import file_exporter
114-
from opencensus.trace.tracer import context_tracer
114+
from opencensus.trace.tracers import context_tracer
115115
116116
exporter = file_exporter.FileExporter(file_name='traces')
117117
tracer = context_tracer.ContextTracer(exporter=exporter)
@@ -121,11 +121,11 @@ This example shows how to report the traces to Stackdriver Trace:
121121
.. code:: python
122122
123123
from opencensus.trace.exporters import stackdriver_exporter
124-
from opencensus.trace import request_tracer
124+
from opencensus.trace import tracer as tracer_module
125125
126126
exporter = stackdriver_exporter.StackdriverExporter(
127127
project_id='your_cloud_project')
128-
tracer = request_tracer.RequestTracer(exporter=exporter)
128+
tracer = tracer_module.Tracer(exporter=exporter)
129129
130130
Propagators
131131
~~~~~~~~~~~
@@ -258,7 +258,7 @@ Webapp2
258258

259259
.. code:: python
260260
261-
from opencensus.trace.tracer import webapp2_tracer
261+
from opencensus.trace.tracers import webapp2_tracer
262262
263263
tracer = webapp2_tracer.WebApp2Tracer()
264264
@@ -276,7 +276,7 @@ services to census:
276276
.. code:: python
277277
278278
from opencensus.trace import config_integration
279-
from opencensus.trace import request_tracer
279+
from opencensus.trace import tracer as tracer_module
280280
281281
import mysql.connector
282282

examples/trace/helloworld/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
from opencensus.trace import execution_context
1818
from opencensus.trace.exporters import print_exporter
19-
from opencensus.trace.request_tracer import RequestTracer
19+
from opencensus.trace.tracers import Tracer
2020
from opencensus.trace.samplers import always_on
2121

2222

@@ -27,7 +27,7 @@ def function_to_trace():
2727
def main():
2828
sampler = always_on.AlwaysOnSampler()
2929
exporter = print_exporter.PrintExporter()
30-
tracer = RequestTracer(sampler=sampler, exporter=exporter)
30+
tracer = Tracer(sampler=sampler, exporter=exporter)
3131

3232
with tracer.span(name='root') as root_span:
3333
tracer.add_label_to_current_span(label_key='example key',

opencensus/trace/execution_context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import threading
1616

17-
from opencensus.trace.tracer import noop_tracer
17+
from opencensus.trace.tracers import noop_tracer
1818

1919
_thread_local = threading.local()
2020

opencensus/trace/ext/django/middleware.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from opencensus.trace.ext import utils
1919
from opencensus.trace.ext.django.config import (settings, convert_to_import)
2020
from opencensus.trace import attributes_helper
21-
from opencensus.trace import request_tracer
21+
from opencensus.trace import tracer as tracer_module
2222
from opencensus.trace import execution_context
2323
from opencensus.trace.samplers import probability
2424

@@ -56,7 +56,7 @@ def _get_django_request():
5656
return execution_context.get_opencensus_attr(REQUEST_THREAD_LOCAL_KEY)
5757

5858

59-
def _get_current_request_tracer():
59+
def _get_current_tracer():
6060
"""Get the current request tracer."""
6161
return execution_context.get_opencensus_tracer()
6262

@@ -159,7 +159,7 @@ def process_request(self, request):
159159
span_context = self.propagator.from_header(header)
160160

161161
# Reload the tracer with the new span context
162-
tracer = request_tracer.RequestTracer(
162+
tracer = tracer_module.Tracer(
163163
span_context=span_context,
164164
sampler=self.sampler,
165165
exporter=self.exporter,
@@ -187,7 +187,7 @@ def process_view(self, request, view_func, *args, **kwargs):
187187
try:
188188
# Get the current span and set the span name to the current
189189
# function name of the request.
190-
tracer = _get_current_request_tracer()
190+
tracer = _get_current_tracer()
191191
span = tracer.current_span()
192192
span.name = utils.get_func_name(view_func)
193193
except Exception: # pragma: NO COVER
@@ -199,7 +199,7 @@ def process_response(self, request, response):
199199
return response
200200

201201
try:
202-
tracer = _get_current_request_tracer()
202+
tracer = _get_current_tracer()
203203
tracer.add_attribute_to_current_span(
204204
attribute_key=HTTP_STATUS_CODE,
205205
attribute_value=str(response.status_code))

opencensus/trace/ext/flask/flask_middleware.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from opencensus.trace.exporters import print_exporter
2222
from opencensus.trace.ext import utils
2323
from opencensus.trace.samplers import always_on
24-
from opencensus.trace import request_tracer
24+
from opencensus.trace import tracer as tracer_module
2525

2626
_FLASK_TRACE_HEADER = 'X_CLOUD_TRACE_CONTEXT'
2727

@@ -95,7 +95,7 @@ def _before_request(self):
9595
header = get_flask_header()
9696
span_context = self.propagator.from_header(header)
9797

98-
tracer = request_tracer.RequestTracer(
98+
tracer = tracer_module.Tracer(
9999
span_context=span_context,
100100
sampler=self.sampler,
101101
exporter=self.exporter,

0 commit comments

Comments
 (0)