@@ -103,114 +103,71 @@ Alternatively, you can explicitly start and end a span:
103103Customization
104104-------------
105105
106- Samplers
107- ~~~~~~~~
106+ There are several things you can customize in OpenCensus:
108107
109- You can specify different samplers when initializing a tracer, default
110- is using `` AlwaysOnSampler `` , the other options are `` AlwaysOffSampler ``
111- and `` ProbabilitySampler ``
108+ * ** Blacklist **, which excludes certain hosts and paths from being tracked.
109+ By default , the health check path for the App Engine flexible environment is
110+ not tracked, you can turn it on by excluding it from the blacklist setting.
112111
113- .. code :: python
114-
115- from opencensus.trace.samplers import probability
116- from opencensus.trace import tracer as tracer_module
117-
118- # Sampling the requests at the rate equals 0.5
119- sampler = probability.ProbabilitySampler(rate = 0.5 )
120- tracer = tracer_module.Tracer(sampler = sampler)
121-
122- Exporters
123- ~~~~~~~~~
124-
125- By default, the traces are printed to stdout in JSON format. You can choose
126- different exporters to send the traces to. There are three built-in exporters,
127- which are ``opencensus.trace.print_exporter ``, ``opencensus.trace.file_exporter ``
128- and ``opencensus.trace.logging_exporter ``, other exporters are provided as
129- `extensions <#trace-exporter >`__.
130-
131- This example shows how to configure OpenCensus to save the traces to a
132- file:
133-
134- .. code :: python
135-
136- from opencensus.trace import file_exporter
137- from opencensus.trace.tracers import context_tracer
112+ * **Exporter **, which sends the traces.
113+ By default, the traces are printed to stdout in JSON format. You can choose
114+ different exporters to send the traces to. There are three built-in exporters,
115+ which are ``PrintExporter ``, ``FileExporter `` and ``LoggingExporter ``, the
116+ other exporters are provided as `extensions <#trace-exporter >`__.
138117
139- exporter = file_exporter.FileExporter(file_name = ' traces' )
140- tracer = context_tracer.ContextTracer(exporter = exporter)
118+ * **Sampler **, which determines how traces are sampled.
119+ The default sampler is ``AlwaysOnSampler ``, other samplers include the
120+ ``AlwaysOffSampler `` and ``ProbabilitySampler ``.
141121
142- Propagators
143- ~~~~~~~~~~~
122+ * **Propagator **, which serializes and deserializes the
123+ ``SpanContext `` and its headers. The default propagator is
124+ ``TraceContextPropagator ``, other propagators include
125+ ``BinaryFormatPropagator ``, ``GoogleCloudFormatPropagator `` and
126+ ``TextFormatPropagator ``.
144127
145- You can specify the propagator type for serializing and deserializing the
146- ``SpanContext `` and its headers. The default propagator is
147- ``TraceContextPropagator ``, the rest options are ``BinaryFormatPropagator ``,
148- ``GoogleCloudFormatPropagator `` and ``TextFormatPropagator ``.
149128
150- This example shows how to use the ``GoogleCloudFormatPropagator ``:
151-
152- .. code :: python
153-
154- from opencensus.trace.propagation import google_cloud_format
155-
156- propagator = google_cloud_format.GoogleCloudFormatPropagator()
157-
158- # Deserialize
159- span_context = propagator.from_header(header)
160-
161- # Serialize
162- header = propagator.to_header(span_context)
163-
164- This example shows how to use the ``TraceContextPropagator ``:
129+ You can customize while initializing a tracer.
165130
166131.. code :: python
167132
168133 import requests
169134
170135 from opencensus.trace import config_integration
171- from opencensus.trace.propagation.trace_context_http_header_format import TraceContextPropagator
172- from opencensus.trace.tracer import Tracer
136+ from opencensus.trace import file_exporter
137+ from opencensus.trace import tracer as tracer_module
138+ from opencensus.trace.propagation import google_cloud_format
139+ from opencensus.trace.samplers import probability
173140
174141 config_integration.trace_integrations([' httplib' ])
175- tracer = Tracer(propagator = TraceContextPropagator())
142+
143+ tracer = tracer_module.Tracer(
144+ exporter = file_exporter.FileExporter(file_name = ' traces' ),
145+ propagator = google_cloud_format.GoogleCloudFormatPropagator(),
146+ sampler = probability.ProbabilitySampler(rate = 0.5 ),
147+ )
176148
177149 with tracer.span(name = ' parent' ):
178150 with tracer.span(name = ' child' ):
179151 response = requests.get(' http://localhost:5000' )
180152
181- Blacklist Paths
182- ~~~~~~~~~~~~~~~
183-
184- You can specify which paths you do not want to trace by configuring the
185- blacklist paths.
186-
187- This example shows how to configure the blacklist to ignore the ``_ah/health `` endpoint
188- for a Flask application:
153+ You can use a configuration file for Flask/Django/Pyramid. For more
154+ information, please read the
155+ `individual integration documentation <#integration >`_.
189156
190157.. code :: python
191158
192- from opencensus.trace.ext.flask.flask_middleware import FlaskMiddleware
193-
194- app = flask.Flask(__name__ )
195-
196- blacklist_paths = [' _ah/health' ]
197- middleware = FlaskMiddleware(app, blacklist_paths = blacklist_paths)
198-
199- For Django, you can configure the blacklist in the ``OPENCENSUS `` in ``settings.py ``:
200-
201- .. code :: python
202-
203- OPENCENSUS : {
159+ ' OPENCENSUS' : {
204160 ' TRACE' : {
205- ...
206- ' BLACKLIST_PATHS' : [' _ah/health' ,],
161+ ' BLACKLIST_HOSTNAMES' : [' localhost' , ' 127.0.0.1' ],
162+ ' BLACKLIST_PATHS' : [' _ah/health' ],
163+ ' SAMPLER' : ' opencensus.trace.samplers.ProbabilitySampler(rate=1)' ,
164+ ' EXPORTER' : ''' opencensus.ext.ocagent.trace_exporter.TraceExporter(
165+ service_name='foobar',
166+ )''' ,
167+ ' PROPAGATOR' : ' opencensus.trace.propagation.google_cloud_format.GoogleCloudFormatPropagator()' ,
207168 }
208169 }
209170
210-
211- .. note :: By default, the health check path for the App Engine flexible environment is not traced,
212- but you can turn it on by excluding it from the blacklist setting.
213-
214171------------
215172 Extensions
216173------------
0 commit comments