Request Tracer

class opencensus.trace.tracer.Tracer(span_context=None, sampler=None, exporter=None, propagator=None)[source]

Bases: object

The Tracer is for tracing a request for web applications.

Parameters
  • span_context (SpanContext) -- SpanContext encapsulates the current context within the request's trace.

  • sampler (Sampler) -- Instances of Sampler objects. Defaults to ProbabilitySampler. Other options include AlwaysOnSampler and AlwaysOffSampler.

  • exporter (exporter) -- Instances of exporter objects. Default to Printexporter. The rest options are Fileexporter, Printexporter, Loggingexporter, Zipkinexporter, GoogleCloudexporter

add_attribute_to_current_span(attribute_key, attribute_value)[source]

Add attribute to current span.

Parameters

attribute_key (str) -- Attribute key.

:type attribute_value:str :param attribute_value: Attribute value.

current_span()[source]

Return the current span.

end_span()[source]

End a span. Update the span_id in SpanContext to the current span's parent span id; Update the current span; Send the span to exporter.

finish()[source]

End all spans.

get_tracer()[source]

Return a tracer according to the sampling decision.

should_sample()[source]

Determine whether to sample this request or not. If the context enables tracing, return True. Else follow the decision of the sampler.

Return type

bool

Returns

Whether to trace the request or not.

span(name='span')[source]

Create a new span with the trace using the context information.

Parameters

name (str) -- The name of the span.

Return type

Span

Returns

The Span object.

store_tracer()[source]

Add the current tracer to thread_local

trace_decorator()[source]

Decorator to trace a function.