Module Contents

ORIGIN_TRACE_HEADER_ATTR_KEY = _origin_trace_header
class SegmentContextManager(recorder, name=None, **segment_kwargs)

Wrapper for segment and recorder to provide segment context manager.

__exit__(self, exc_type, exc_val, exc_tb)
class Segment(name, entityid=None, traceid=None, parent_id=None, sampled=True)


The compute resources running your application logic send data about their work as segments. A segment provides the resource’s name, details about the request, and details about the work done.

add_subsegment(self, subsegment)

Add input subsegment as a child subsegment and increment reference counter and total subsegments counter.


Increment reference counter to track on open subsegments and total subsegments counter to track total size of subsegments it currently hold.


Decrement reference counter by 1 when a subsegment is closed.


Return True if the segment doesn’t have any open subsegments and itself is not in progress.


Return the number of total subsegments regardless of open or closed.


Decrement total subsegments by 1. This usually happens when a subsegment is streamed out.

remove_subsegment(self, subsegment)

Remove the reference of input subsegment.

set_user(self, user)

set user of a segment. One segment can only have one user. User is indexed and can be later queried.

set_service(self, service_info)

Add python runtime and version info. This method should be only used by the recorder.

set_rule_name(self, rule_name)

Add the matched centralized sampling rule name if a segment is sampled because of that rule. This method should be only used by the recorder.


Used by jsonpikle to remove unwanted fields.