Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Commit 00763b3

Browse files
authored
Update README and docs (#69)
1 parent f157a9d commit 00763b3

10 files changed

Lines changed: 86 additions & 118 deletions

File tree

README.rst

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ Installation
2222
from opencensus.trace import request_tracer
2323
2424
tracer = request_tracer.RequestTracer()
25-
tracer.start_trace()
2625
2726
Usage
2827
-----
@@ -40,9 +39,8 @@ Usage 1: ``with`` statement (Recommended)
4039
4140
from opencensus.trace import request_tracer
4241
43-
# Initialize a tracer, by default using the `PrintReporter`
42+
# Initialize a tracer, by default using the `PrintExporter`
4443
tracer = request_tracer.RequestTracer()
45-
tracer.start_trace()
4644
4745
# Example for creating nested spans
4846
with tracer.span(name='span1') as span1:
@@ -54,8 +52,7 @@ Usage 1: ``with`` statement (Recommended)
5452
with tracer.span(name='span2') as span2:
5553
do_something_to_trace()
5654
57-
# The trace spans will be sent to the reporter when you call `end_trace()`
58-
tracer.end_trace()
55+
# The spans will be exported when exiting the with block.
5956
6057
Usage 2: Explicitly start and end spans
6158
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -64,7 +61,7 @@ Usage 2: Explicitly start and end spans
6461
6562
from opencensus.trace import request_tracer
6663
67-
# Initialize a tracer, by default using the `PrintReporter`
64+
# Initialize a tracer, by default using the `PrintExporter`
6865
tracer = request_tracer.RequestTracer()
6966
tracer.start_trace()
7067
@@ -96,17 +93,17 @@ Exporters
9693

9794
You can choose different exporters to send the traces to. Default is
9895
printing the traces in JSON format. The rest options are sending to
99-
logging, or write to a file. Will add reporters to report to different
96+
logging, or write to a file. Will add exporters to report to different
10097
trace backend later.
10198

10299
.. code:: python
103100
104-
from opencensus.trace.reporters import file_reporter
101+
from opencensus.trace.exporters import file_exporter
105102
from opencensus.trace.tracer import context_tracer
106103
107104
# Export the traces to a local file
108-
reporter = file_reporter.FileReporter(file_name='traces')
109-
tracer = context_tracer.ContextTracer(reporter=reporter)
105+
exporter = file_exporter.FileExporter(file_name='traces')
106+
tracer = context_tracer.ContextTracer(exporter=exporter)
110107
111108
Report to Stackdriver Trace:
112109

@@ -115,7 +112,7 @@ Report to Stackdriver Trace:
115112
from opencensus.trace.exporters import stackdriver_exporter
116113
from opencensus.trace import request_tracer
117114
118-
exporter = stackdriver_exporter.StackdriverReporter(
115+
exporter = stackdriver_exporter.StackdriverExporter(
119116
project_id='your_cloud_project')
120117
tracer = request_tracer.RequestTracer(exporter=exporter)
121118
@@ -159,8 +156,8 @@ requests will be automatically traced.
159156
160157
app = flask.Flask(__name__)
161158
162-
# You can also specify the sampler, reporter, propagator in the middleware,
163-
# default is using `AlwaysOnSampler` as sampler, `PrintReporter` as reporter,
159+
# You can also specify the sampler, exporter, propagator in the middleware,
160+
# default is using `AlwaysOnSampler` as sampler, `PrintExporter` as exporter,
164161
# `GoogleCloudFormatPropagator` as propagator.
165162
middleware = FlaskMiddleware(app)
166163
@@ -180,13 +177,13 @@ Add this line to the ``INSTALLED_APPS`` section:
180177

181178
'opencensus.trace.ext.django',
182179

183-
Customize the sampler, reporter, propagator in the ``settings.py`` file:
180+
Customize the sampler, exporter, propagator in the ``settings.py`` file:
184181

185182
::
186183

187184
OPENCENSUS_TRACE = {
188185
'SAMPLER': 'opencensus.trace.samplers.probability.ProbabilitySampler',
189-
'REPORTER': 'opencensus.trace.reporters.print_reporter.PrintReporter',
186+
'REPORTER': 'opencensus.trace.exporters.print_exporter.PrintExporter',
190187
'PROPAGATOR': 'opencensus.trace.propagation.google_cloud_format.'
191188
'GoogleCloudFormatPropagator',
192189
}
@@ -201,13 +198,10 @@ Webapp2
201198
from opencensus.trace.tracer import webapp2_tracer
202199
203200
tracer = webapp2_tracer.WebApp2Tracer()
204-
tracer.start_trace()
205201
206202
with tracer.span(name='span1'):
207203
do_something_to_trace()
208204
209-
tracer.end_trace()
210-
211205
Service Integration
212206
-------------------
213207

@@ -227,15 +221,12 @@ want to instrument. Usage for enabling MySQL instrumentation like below:
227221
config_integration.trace_integrations(INTEGRATIONS)
228222
229223
tracer = request_tracer.RequestTracer()
230-
tracer.start_trace()
231224
232225
conn = mysql.connector.connect(user='user', password='password')
233226
cursor = conn.cursor()
234227
query = 'SELECT 2*3'
235228
cursor.execute(query)
236229
237-
tracer.end_trace()
238-
239230
MySQL
240231
~~~~~
241232

@@ -295,7 +286,6 @@ integration with requests module.
295286
296287
# Create a tracer
297288
tracer = RequestTracer()
298-
tracer.start_trace()
299289
300290
# Integrate with requests module
301291
trace_integrations(['requests'])

docs/_sources/trace/usage.rst.txt

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ Installation
2121
from opencensus.trace import request_tracer
2222
2323
tracer = request_tracer.RequestTracer()
24-
tracer.start_trace()
2524
2625
Usage
2726
-----
@@ -39,9 +38,8 @@ Usage 1: ``with`` statement (Recommended)
3938
4039
from opencensus.trace import request_tracer
4140
42-
# Initialize a tracer, by default using the `PrintReporter`
41+
# Initialize a tracer, by default using the `PrintExporter`
4342
tracer = request_tracer.RequestTracer()
44-
tracer.start_trace()
4543
4644
# Example for creating nested spans
4745
with tracer.span(name='span1') as span1:
@@ -53,8 +51,7 @@ Usage 1: ``with`` statement (Recommended)
5351
with tracer.span(name='span2') as span2:
5452
do_something_to_trace()
5553
56-
# The trace spans will be sent to the reporter when you call `end_trace()`
57-
tracer.end_trace()
54+
# The spans will be exported when exiting the with block.
5855
5956
Usage 2: Explicitly start and end spans
6057
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -63,7 +60,7 @@ Usage 2: Explicitly start and end spans
6360
6461
from opencensus.trace import request_tracer
6562
66-
# Initialize a tracer, by default using the `PrintReporter`
63+
# Initialize a tracer, by default using the `PrintExporter`
6764
tracer = request_tracer.RequestTracer()
6865
tracer.start_trace()
6966
@@ -79,44 +76,44 @@ Samplers
7976

8077
You can specify different samplers when initializing a tracer, default
8178
is using ``AlwaysOnSampler``, the other options are ``AlwaysOffSampler``
82-
and ``FixedRateSampler``
79+
and ``ProbabilitySampler``
8380

8481
.. code:: python
8582
86-
from opencensus.trace.samplers import fixed_rate
83+
from opencensus.trace.samplers import probability
8784
from opencensus.trace import request_tracer
8885
8986
# Sampling the requests at the rate equals 0.5
90-
sampler = fixed_rate.FixedRateSampler(rate=0.5)
87+
sampler = probability.ProbabilitySampler(rate=0.5)
9188
tracer = request_tracer.RequestTracer(sampler=sampler)
9289
93-
Reporters
90+
Exporters
9491
~~~~~~~~~
9592

96-
You can choose different reporters to send the traces to. Default is
93+
You can choose different exporters to send the traces to. Default is
9794
printing the traces in JSON format. The rest options are sending to
98-
logging, or write to a file. Will add reporters to report to different
95+
logging, or write to a file. Will add exporters to report to different
9996
trace backend later.
10097

10198
.. code:: python
10299
103-
from opencensus.trace.reporters import file_reporter
100+
from opencensus.trace.exporters import file_exporter
104101
from opencensus.trace.tracer import context_tracer
105102
106103
# Export the traces to a local file
107-
reporter = file_reporter.FileReporter(file_name='traces')
108-
tracer = context_tracer.ContextTracer(reporter=reporter)
104+
exporter = file_exporter.FileExporter(file_name='traces')
105+
tracer = context_tracer.ContextTracer(exporter=exporter)
109106
110107
Report to Stackdriver Trace:
111108

112109
.. code:: python
113110
114-
from opencensus.trace.reporters import google_cloud_reporter
111+
from opencensus.trace.exporters import stackdriver_exporter
115112
from opencensus.trace import request_tracer
116113
117-
reporter = google_cloud_reporter.GoogleCloudReporter(
114+
exporter = stackdriver_exporter.StackdriverExporter(
118115
project_id='your_cloud_project')
119-
tracer = request_tracer.RequestTracer(reporter=reporter)
116+
tracer = request_tracer.RequestTracer(exporter=exporter)
120117
121118
Propagators
122119
~~~~~~~~~~~
@@ -158,8 +155,8 @@ requests will be automatically traced.
158155
159156
app = flask.Flask(__name__)
160157
161-
# You can also specify the sampler, reporter, propagator in the middleware,
162-
# default is using `AlwaysOnSampler` as sampler, `PrintReporter` as reporter,
158+
# You can also specify the sampler, exporter, propagator in the middleware,
159+
# default is using `AlwaysOnSampler` as sampler, `PrintExporter` as exporter,
163160
# `GoogleCloudFormatPropagator` as propagator.
164161
middleware = FlaskMiddleware(app)
165162
@@ -179,13 +176,13 @@ Add this line to the ``INSTALLED_APPS`` section:
179176

180177
'opencensus.trace.ext.django',
181178

182-
Customize the sampler, reporter, propagator in the ``settings.py`` file:
179+
Customize the sampler, exporter, propagator in the ``settings.py`` file:
183180

184181
::
185182

186183
OPENCENSUS_TRACE = {
187-
'SAMPLER': 'opencensus.trace.samplers.fixed_rate.FixedRateSampler',
188-
'REPORTER': 'opencensus.trace.reporters.print_reporter.PrintReporter',
184+
'SAMPLER': 'opencensus.trace.samplers.probability.ProbabilitySampler',
185+
'REPORTER': 'opencensus.trace.exporters.print_exporter.PrintExporter',
189186
'PROPAGATOR': 'opencensus.trace.propagation.google_cloud_format.'
190187
'GoogleCloudFormatPropagator',
191188
}
@@ -200,13 +197,10 @@ Webapp2
200197
from opencensus.trace.tracer import webapp2_tracer
201198
202199
tracer = webapp2_tracer.WebApp2Tracer()
203-
tracer.start_trace()
204200
205201
with tracer.span(name='span1'):
206202
do_something_to_trace()
207203
208-
tracer.end_trace()
209-
210204
Service Integration
211205
-------------------
212206

@@ -226,15 +220,12 @@ want to instrument. Usage for enabling MySQL instrumentation like below:
226220
config_integration.trace_integrations(INTEGRATIONS)
227221
228222
tracer = request_tracer.RequestTracer()
229-
tracer.start_trace()
230223
231224
conn = mysql.connector.connect(user='user', password='password')
232225
cursor = conn.cursor()
233226
query = 'SELECT 2*3'
234227
cursor.execute(query)
235228
236-
tracer.end_trace()
237-
238229
MySQL
239230
~~~~~
240231

@@ -294,7 +285,6 @@ integration with requests module.
294285
295286
# Create a tracer
296287
tracer = RequestTracer()
297-
tracer.start_trace()
298288
299289
# Integrate with requests module
300290
trace_integrations(['requests'])

docs/searchindex.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)