diff --git a/README.rst b/README.rst index f5107e27f..b09bff6dc 100644 --- a/README.rst +++ b/README.rst @@ -22,7 +22,6 @@ Installation from opencensus.trace import request_tracer tracer = request_tracer.RequestTracer() - tracer.start_trace() Usage ----- @@ -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: @@ -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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -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() @@ -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: @@ -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) @@ -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) @@ -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', } @@ -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 ------------------- @@ -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 ~~~~~ @@ -295,7 +286,6 @@ integration with requests module. # Create a tracer tracer = RequestTracer() - tracer.start_trace() # Integrate with requests module trace_integrations(['requests']) diff --git a/docs/_sources/trace/usage.rst.txt b/docs/_sources/trace/usage.rst.txt index 770658f22..7cbbb8026 100644 --- a/docs/_sources/trace/usage.rst.txt +++ b/docs/_sources/trace/usage.rst.txt @@ -21,7 +21,6 @@ Installation from opencensus.trace import request_tracer tracer = request_tracer.RequestTracer() - tracer.start_trace() Usage ----- @@ -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: @@ -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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -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() @@ -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 ~~~~~~~~~~~ @@ -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) @@ -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', } @@ -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 ------------------- @@ -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 ~~~~~ @@ -294,7 +285,6 @@ integration with requests module. # Create a tracer tracer = RequestTracer() - tracer.start_trace() # Integrate with requests module trace_integrations(['requests']) diff --git a/docs/searchindex.js b/docs/searchindex.js index 763e6378c..a88f52951 100644 --- a/docs/searchindex.js +++ b/docs/searchindex.js @@ -1 +1 @@ -Search.setIndex({docnames:["index","trace/usage"],envversion:53,filenames:["index.rst","trace/usage.rst"],objects:{},objnames:{},objtypes:{},terms:{"default":1,"export":1,"import":1,For:1,One:1,The:[0,1],Then:1,There:1,Will:1,__name__:1,abl:0,activ:1,add:1,added:1,after:1,all:1,also:1,alwai:1,alwaysoffsampl:1,alwaysonsampl:1,ani:1,anoth:1,apach:1,app:1,applic:1,autom:1,automat:1,avail:1,avoid:1,backend:1,background:1,base:1,bdist_wheel:1,befor:1,begin:1,below:1,between:1,bigqueri:1,bin:1,block:1,both:1,call:1,can:1,child:1,choos:1,client:1,cloud:[0,1],code:1,com:1,command:1,commun:1,complet:1,config_integr:1,conn:1,connect:1,connector:1,context:1,context_trac:1,contexttrac:1,creat:1,current:1,cursor:1,data:1,databas:1,delet:1,deseri:1,develop:0,differ:1,dist:1,do_something_to_trac:1,don:1,download:1,enabl:1,encourag:1,end_span:1,end_trac:1,environ:0,equal:1,exampl:1,execut:1,exit:1,ext:1,extract:1,file:1,file_nam:1,file_report:1,filereport:1,finish:1,fixed_r:1,fixedratesampl:1,flask_middlewar:1,flaskmiddlewar:1,follow:1,fore:0,format:1,from:1,from_head:1,gener:1,get:1,github:1,googl:[0,1],google_cloud_format:1,google_cloud_report:1,googlecloudformatpropag:1,googlecloudreport:1,guid:0,have:1,head:1,header:1,highli:1,how:1,http:1,includ:1,inform:[0,1],initi:1,instal:0,installed_app:1,instrument:1,job:1,json:1,just:1,label:1,later:1,librari:[0,1],like:1,line:1,link:1,local:1,log:1,method:1,middlewar:1,middleware_class:1,modul:1,more:[0,1],most:1,name:1,need:1,nest:1,none:1,normal:1,note:1,nox:1,offici:1,opencensus_trac:1,opencensusmiddlewar:1,option:1,other:1,packag:1,password:1,pip:[0,1],platform:0,pleas:0,popular:1,post:1,print:1,print_report:1,printreport:1,product:1,progress:1,project_id:1,psf:1,psycopg2:1,put:1,py2:1,py34:1,py3:1,python:[0,1],python_vers:1,queri:1,query_job:1,rate:1,receiv:1,refer:0,request_trac:1,requesttrac:1,rest:1,result:1,run:1,run_async_queri:1,sampl:1,sample_t:1,script:1,section:1,see:1,select:1,send:1,sent:1,serial:1,set:[0,1],setup:[0,1],singl:1,snippet:1,sourc:1,span1:1,span1_child1:1,span1_child2:1,span2:1,span_context:1,spancontext:1,specifi:1,stackdriv:1,start_span:1,start_trac:1,stat:1,str:1,suit:1,support:1,system:0,textformatpropag:1,thi:1,to_head:1,tox:1,trace_integr:1,tracer:1,transport:1,turn:1,two:1,type:1,under:1,unit:1,unit_test:1,url:1,use:1,user:1,using:1,uuid4:1,uuid:1,variou:1,verbos:1,wai:1,wait:1,want:1,web:1,webapp2_trac:1,webapp2trac:1,welcom:1,what:1,when:1,which:1,whl:1,work:1,wrap:1,write:1,yet:1,you:1,your:[0,1],your_cloud_project:1},titles:["Welcome to OPENCENSUS's documentation!","OpenCensus Trace"],titleterms:{contribut:1,custom:1,develop:1,disclaim:1,django:1,document:0,end:1,explicitli:1,flask:1,framework:1,get:0,instal:1,integr:1,licens:1,mysql:1,opencensu:[0,1],postgresql:1,propag:1,recommend:1,report:1,request:1,sampler:1,servic:1,span:1,sqlalchemi:1,start:[0,1],statement:1,statu:1,test:1,trace:1,usag:1,webapp2:1,welcom:0}}) \ No newline at end of file +Search.setIndex({docnames:["index","trace/usage"],envversion:53,filenames:["index.rst","trace/usage.rst"],objects:{},objnames:{},objtypes:{},terms:{"default":1,"import":1,For:1,One:1,The:[0,1],Then:1,There:1,Will:1,__name__:1,abl:0,activ:1,add:1,added:1,after:1,all:1,also:1,alwai:1,alwaysoffsampl:1,alwaysonsampl:1,ani:1,anoth:1,apach:1,app:1,applic:1,autom:1,automat:1,avail:1,avoid:1,backend:1,background:1,base:1,bdist_wheel:1,befor:1,begin:1,below:1,between:1,bigqueri:1,bin:1,block:1,both:1,can:1,child:1,choos:1,client:1,cloud:[0,1],code:1,com:1,command:1,commun:1,complet:1,config_integr:1,conn:1,connect:1,connector:1,context:1,context_trac:1,contexttrac:1,creat:1,current:1,cursor:1,data:1,databas:1,delet:1,deseri:1,develop:0,differ:1,dist:1,do_something_to_trac:1,don:1,download:1,enabl:1,encourag:1,end_span:1,environ:0,equal:1,exampl:1,execut:1,exit:1,ext:1,extract:1,file:1,file_export:1,file_nam:1,fileexport:1,finish:1,flask_middlewar:1,flaskmiddlewar:1,follow:1,fore:0,format:1,from:1,from_head:1,gener:1,get:1,github:1,googl:[0,1],google_cloud_format:1,googlecloudformatpropag:1,guid:0,have:1,head:1,header:1,highli:1,how:1,http:1,includ:1,inform:[0,1],initi:1,instal:0,installed_app:1,instrument:1,job:1,json:1,just:1,label:1,later:1,librari:[0,1],like:1,line:1,link:1,local:1,log:1,method:1,middlewar:1,middleware_class:1,modul:1,more:[0,1],most:1,name:1,need:1,nest:1,none:1,normal:1,note:1,nox:1,offici:1,opencensus_trac:1,opencensusmiddlewar:1,option:1,other:1,packag:1,password:1,pip:[0,1],platform:0,pleas:0,popular:1,post:1,print:1,print_export:1,printexport:1,probabilitysampl:1,probabl:1,product:1,progress:1,project_id:1,psf:1,psycopg2:1,put:1,py2:1,py34:1,py3:1,python:[0,1],python_vers:1,queri:1,query_job:1,rate:1,receiv:1,refer:0,report:1,request_trac:1,requesttrac:1,rest:1,result:1,run:1,run_async_queri:1,sampl:1,sample_t:1,script:1,section:1,see:1,select:1,send:1,serial:1,set:[0,1],setup:[0,1],singl:1,snippet:1,sourc:1,span1:1,span1_child1:1,span1_child2:1,span2:1,span_context:1,spancontext:1,specifi:1,stackdriv:1,stackdriver_export:1,stackdriverexport:1,start_span:1,start_trac:1,stat:1,str:1,suit:1,support:1,system:0,textformatpropag:1,thi:1,to_head:1,tox:1,trace_integr:1,tracer:1,transport:1,turn:1,two:1,type:1,under:1,unit:1,unit_test:1,url:1,use:1,user:1,using:1,uuid4:1,uuid:1,variou:1,verbos:1,wai:1,wait:1,want:1,web:1,webapp2_trac:1,webapp2trac:1,welcom:1,what:1,when:1,which:1,whl:1,work:1,wrap:1,write:1,yet:1,you:1,your:[0,1],your_cloud_project:1},titles:["Welcome to OPENCENSUS's documentation!","OpenCensus Trace"],titleterms:{"export":1,contribut:1,custom:1,develop:1,disclaim:1,django:1,document:0,end:1,explicitli:1,flask:1,framework:1,get:0,instal:1,integr:1,licens:1,mysql:1,opencensu:[0,1],postgresql:1,propag:1,recommend:1,request:1,sampler:1,servic:1,span:1,sqlalchemi:1,start:[0,1],statement:1,statu:1,test:1,trace:1,usag:1,webapp2:1,welcom:0}}) \ No newline at end of file diff --git a/docs/trace/usage.html b/docs/trace/usage.html index 7cca208df..4608dacfd 100644 --- a/docs/trace/usage.html +++ b/docs/trace/usage.html @@ -57,7 +57,6 @@
from opencensus.trace import request_tracer
tracer = request_tracer.RequestTracer()
-tracer.start_trace()
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:
@@ -86,8 +84,7 @@ Usage 1: with
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.
with
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()
@@ -112,37 +109,37 @@ Customization¶
You can specify different samplers when initializing a tracer, default
is using AlwaysOnSampler, the other options are AlwaysOffSampler
-and FixedRateSampler
-from opencensus.trace.samplers import fixed_rate
+and ProbabilitySampler
+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¶
-You can choose different reporters to send the traces to. Default is
+
+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.
-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:
-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)
@@ -179,8 +176,8 @@ Flask
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)
@@ -197,10 +194,10 @@ Django'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',
}
@@ -213,12 +210,9 @@ Webapp2from 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()
@@ -238,14 +232,11 @@ Service Integrationconfig_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()