Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 12 additions & 22 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ Installation
from opencensus.trace import request_tracer

tracer = request_tracer.RequestTracer()
tracer.start_trace()

Usage
-----
Expand All @@ -40,9 +39,8 @@ Usage 1: ``with`` statement (Recommended)

from opencensus.trace import request_tracer

# Initialize a tracer, by default using the `PrintReporter`
# Initialize a tracer, by default using the `PrintExporter`
tracer = request_tracer.RequestTracer()
tracer.start_trace()

# Example for creating nested spans
with tracer.span(name='span1') as span1:
Expand All @@ -54,8 +52,7 @@ Usage 1: ``with`` statement (Recommended)
with tracer.span(name='span2') as span2:
do_something_to_trace()

# The trace spans will be sent to the reporter when you call `end_trace()`
tracer.end_trace()
# The spans will be exported when exiting the with block.

Usage 2: Explicitly start and end spans
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -64,7 +61,7 @@ Usage 2: Explicitly start and end spans

from opencensus.trace import request_tracer

# Initialize a tracer, by default using the `PrintReporter`
# Initialize a tracer, by default using the `PrintExporter`
tracer = request_tracer.RequestTracer()
tracer.start_trace()

Expand Down Expand Up @@ -96,17 +93,17 @@ Exporters

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

.. code:: python

from opencensus.trace.reporters import file_reporter
from opencensus.trace.exporters import file_exporter
from opencensus.trace.tracer import context_tracer

# Export the traces to a local file
reporter = file_reporter.FileReporter(file_name='traces')
tracer = context_tracer.ContextTracer(reporter=reporter)
exporter = file_exporter.FileExporter(file_name='traces')
tracer = context_tracer.ContextTracer(exporter=exporter)

Report to Stackdriver Trace:

Expand All @@ -115,7 +112,7 @@ Report to Stackdriver Trace:
from opencensus.trace.exporters import stackdriver_exporter
from opencensus.trace import request_tracer

exporter = stackdriver_exporter.StackdriverReporter(
exporter = stackdriver_exporter.StackdriverExporter(
project_id='your_cloud_project')
tracer = request_tracer.RequestTracer(exporter=exporter)

Expand Down Expand Up @@ -159,8 +156,8 @@ requests will be automatically traced.

app = flask.Flask(__name__)

# You can also specify the sampler, reporter, propagator in the middleware,
# default is using `AlwaysOnSampler` as sampler, `PrintReporter` as reporter,
# You can also specify the sampler, exporter, propagator in the middleware,
# default is using `AlwaysOnSampler` as sampler, `PrintExporter` as exporter,
# `GoogleCloudFormatPropagator` as propagator.
middleware = FlaskMiddleware(app)

Expand All @@ -180,13 +177,13 @@ Add this line to the ``INSTALLED_APPS`` section:

'opencensus.trace.ext.django',

Customize the sampler, reporter, propagator in the ``settings.py`` file:
Customize the sampler, exporter, propagator in the ``settings.py`` file:

::

OPENCENSUS_TRACE = {
'SAMPLER': 'opencensus.trace.samplers.probability.ProbabilitySampler',
'REPORTER': 'opencensus.trace.reporters.print_reporter.PrintReporter',
'REPORTER': 'opencensus.trace.exporters.print_exporter.PrintExporter',
'PROPAGATOR': 'opencensus.trace.propagation.google_cloud_format.'
'GoogleCloudFormatPropagator',
}
Expand All @@ -201,13 +198,10 @@ Webapp2
from opencensus.trace.tracer import webapp2_tracer

tracer = webapp2_tracer.WebApp2Tracer()
tracer.start_trace()

with tracer.span(name='span1'):
do_something_to_trace()

tracer.end_trace()

Service Integration
-------------------

Expand All @@ -227,15 +221,12 @@ want to instrument. Usage for enabling MySQL instrumentation like below:
config_integration.trace_integrations(INTEGRATIONS)

tracer = request_tracer.RequestTracer()
tracer.start_trace()

conn = mysql.connector.connect(user='user', password='password')
cursor = conn.cursor()
query = 'SELECT 2*3'
cursor.execute(query)

tracer.end_trace()

MySQL
~~~~~

Expand Down Expand Up @@ -295,7 +286,6 @@ integration with requests module.

# Create a tracer
tracer = RequestTracer()
tracer.start_trace()

# Integrate with requests module
trace_integrations(['requests'])
Expand Down
50 changes: 20 additions & 30 deletions docs/_sources/trace/usage.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Installation
from opencensus.trace import request_tracer

tracer = request_tracer.RequestTracer()
tracer.start_trace()

Usage
-----
Expand All @@ -39,9 +38,8 @@ Usage 1: ``with`` statement (Recommended)

from opencensus.trace import request_tracer

# Initialize a tracer, by default using the `PrintReporter`
# Initialize a tracer, by default using the `PrintExporter`
tracer = request_tracer.RequestTracer()
tracer.start_trace()

# Example for creating nested spans
with tracer.span(name='span1') as span1:
Expand All @@ -53,8 +51,7 @@ Usage 1: ``with`` statement (Recommended)
with tracer.span(name='span2') as span2:
do_something_to_trace()

# The trace spans will be sent to the reporter when you call `end_trace()`
tracer.end_trace()
# The spans will be exported when exiting the with block.

Usage 2: Explicitly start and end spans
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -63,7 +60,7 @@ Usage 2: Explicitly start and end spans

from opencensus.trace import request_tracer

# Initialize a tracer, by default using the `PrintReporter`
# Initialize a tracer, by default using the `PrintExporter`
tracer = request_tracer.RequestTracer()
tracer.start_trace()

Expand All @@ -79,44 +76,44 @@ Samplers

You can specify different samplers when initializing a tracer, default
is using ``AlwaysOnSampler``, the other options are ``AlwaysOffSampler``
and ``FixedRateSampler``
and ``ProbabilitySampler``

.. code:: python

from opencensus.trace.samplers import fixed_rate
from opencensus.trace.samplers import probability
from opencensus.trace import request_tracer

# Sampling the requests at the rate equals 0.5
sampler = fixed_rate.FixedRateSampler(rate=0.5)
sampler = probability.ProbabilitySampler(rate=0.5)
tracer = request_tracer.RequestTracer(sampler=sampler)

Reporters
Exporters
~~~~~~~~~

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

.. code:: python

from opencensus.trace.reporters import file_reporter
from opencensus.trace.exporters import file_exporter
from opencensus.trace.tracer import context_tracer

# Export the traces to a local file
reporter = file_reporter.FileReporter(file_name='traces')
tracer = context_tracer.ContextTracer(reporter=reporter)
exporter = file_exporter.FileExporter(file_name='traces')
tracer = context_tracer.ContextTracer(exporter=exporter)

Report to Stackdriver Trace:

.. code:: python

from opencensus.trace.reporters import google_cloud_reporter
from opencensus.trace.exporters import stackdriver_exporter
from opencensus.trace import request_tracer

reporter = google_cloud_reporter.GoogleCloudReporter(
exporter = stackdriver_exporter.StackdriverExporter(
project_id='your_cloud_project')
tracer = request_tracer.RequestTracer(reporter=reporter)
tracer = request_tracer.RequestTracer(exporter=exporter)

Propagators
~~~~~~~~~~~
Expand Down Expand Up @@ -158,8 +155,8 @@ requests will be automatically traced.

app = flask.Flask(__name__)

# You can also specify the sampler, reporter, propagator in the middleware,
# default is using `AlwaysOnSampler` as sampler, `PrintReporter` as reporter,
# You can also specify the sampler, exporter, propagator in the middleware,
# default is using `AlwaysOnSampler` as sampler, `PrintExporter` as exporter,
# `GoogleCloudFormatPropagator` as propagator.
middleware = FlaskMiddleware(app)

Expand All @@ -179,13 +176,13 @@ Add this line to the ``INSTALLED_APPS`` section:

'opencensus.trace.ext.django',

Customize the sampler, reporter, propagator in the ``settings.py`` file:
Customize the sampler, exporter, propagator in the ``settings.py`` file:

::

OPENCENSUS_TRACE = {
'SAMPLER': 'opencensus.trace.samplers.fixed_rate.FixedRateSampler',
'REPORTER': 'opencensus.trace.reporters.print_reporter.PrintReporter',
'SAMPLER': 'opencensus.trace.samplers.probability.ProbabilitySampler',
'REPORTER': 'opencensus.trace.exporters.print_exporter.PrintExporter',
'PROPAGATOR': 'opencensus.trace.propagation.google_cloud_format.'
'GoogleCloudFormatPropagator',
}
Expand All @@ -200,13 +197,10 @@ Webapp2
from opencensus.trace.tracer import webapp2_tracer

tracer = webapp2_tracer.WebApp2Tracer()
tracer.start_trace()

with tracer.span(name='span1'):
do_something_to_trace()

tracer.end_trace()

Service Integration
-------------------

Expand All @@ -226,15 +220,12 @@ want to instrument. Usage for enabling MySQL instrumentation like below:
config_integration.trace_integrations(INTEGRATIONS)

tracer = request_tracer.RequestTracer()
tracer.start_trace()

conn = mysql.connector.connect(user='user', password='password')
cursor = conn.cursor()
query = 'SELECT 2*3'
cursor.execute(query)

tracer.end_trace()

MySQL
~~~~~

Expand Down Expand Up @@ -294,7 +285,6 @@ integration with requests module.

# Create a tracer
tracer = RequestTracer()
tracer.start_trace()

# Integrate with requests module
trace_integrations(['requests'])
Expand Down
2 changes: 1 addition & 1 deletion docs/searchindex.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading