aws_xray_sdk.core.models package¶
Submodules¶
aws_xray_sdk.core.models.default_dynamic_naming module¶
- class aws_xray_sdk.core.models.default_dynamic_naming.DefaultDynamicNaming(pattern, fallback)¶
Bases:
objectDecides what name to use on a segment generated from an incoming request. By default it takes the host name and compares it to a pre-defined pattern. If the host name matches that pattern, it returns the host name, otherwise it returns the fallback name. The host name usually comes from the incoming request’s headers.
- get_name(host_name)¶
Returns the segment name based on the input host name.
aws_xray_sdk.core.models.dummy_entities module¶
- class aws_xray_sdk.core.models.dummy_entities.DummySegment(name='dummy')¶
Bases:
SegmentA dummy segment is created when
xray_recorderdecide to not sample the segment based on sampling rules. Adding data to a dummy segment becomes a no-op except for subsegments. This is to reduce the memory footprint of the SDK. A dummy segment will not be sent to the X-Ray daemon. Manually create dummy segments is not recommended.- add_exception(exception, stack, remote=False)¶
No-op
- apply_status_code(status_code)¶
No-op
- put_annotation(key, value)¶
No-op
- put_http_meta(key, value)¶
No-op
- put_metadata(key, value, namespace='default')¶
No-op
- serialize()¶
No-op
- set_aws(aws_meta)¶
No-op
- set_service(service_info)¶
No-op
- set_user(user)¶
No-op
- class aws_xray_sdk.core.models.dummy_entities.DummySubsegment(segment, name='dummy')¶
Bases:
SubsegmentA dummy subsegment will be created when
xray_recordertries to create a subsegment under a not sampled segment. Adding data to a dummy subsegment becomes no-op. Dummy subsegment will not be sent to the X-Ray daemon.- add_exception(exception, stack, remote=False)¶
No-op
- apply_status_code(status_code)¶
No-op
- put_annotation(key, value)¶
No-op
- put_http_meta(key, value)¶
No-op
- put_metadata(key, value, namespace='default')¶
No-op
- serialize()¶
No-op
- set_aws(aws_meta)¶
No-op
- set_sql(sql)¶
No-op
aws_xray_sdk.core.models.entity module¶
- class aws_xray_sdk.core.models.entity.Entity(name)¶
Bases:
objectThe parent class for segment/subsegment. It holds common properties and methods on segment and subsegment.
- add_error_flag()¶
- add_exception(exception, stack, remote=False)¶
Add an exception to trace entities.
- add_fault_flag()¶
- add_subsegment(subsegment)¶
Add input subsegment as a child subsegment.
- add_throttle_flag()¶
- apply_status_code(status_code)¶
When a trace entity is generated under the http context, the status code will affect this entity’s fault/error/throttle flags. Flip these flags based on status code.
- close(end_time=None)¶
Close the trace entity by setting end_time and flip the in progress flag to False.
- Parameters:
end_time (int) – Epoch in seconds. If not specified current time will be used.
- get_origin_trace_header()¶
Retrieve saved trace header data.
- put_annotation(key, value)¶
Annotate segment or subsegment with a key-value pair. Annotations will be indexed for later search query.
- put_http_meta(key, value)¶
Add http related metadata.
- Parameters:
key (str) – Currently supported keys are: * url * method * user_agent * client_ip * status * content_length
value – status and content_length are int and for other supported keys string should be used.
- put_metadata(key, value, namespace='default')¶
Add metadata to segment or subsegment. Metadata is not indexed but can be later retrieved by BatchGetTraces API.
- remove_subsegment(subsegment)¶
Remove input subsegment from child subsegments.
- save_origin_trace_header(trace_header)¶
Temporarily store additional data fields in trace header to the entity for later propagation. The data will be cleaned up upon serialization.
- serialize()¶
Serialize to JSON document that can be accepted by the X-Ray backend service. It uses jsonpickle to perform serialization.
- set_aws(aws_meta)¶
set aws section of the entity. This method is called by global recorder and botocore patcher to provide additonal information about AWS runtime. It is not recommended to manually set aws section.
aws_xray_sdk.core.models.facade_segment module¶
- class aws_xray_sdk.core.models.facade_segment.FacadeSegment(name, entityid, traceid, sampled)¶
Bases:
SegmentThis type of segment should only be used in an AWS Lambda environment. It holds the same id, traceid and sampling decision as the segment generated by Lambda service but its properties cannot be mutated except for its subsegments. If this segment is created before Lambda worker finishes initializatioin, all the child subsegments will be discarded.
- add_error_flag()¶
Unsupported operation. Will raise an exception.
- add_exception(exception, stack, remote=False)¶
Unsupported operation. Will raise an exception.
- add_fault_flag()¶
Unsupported operation. Will raise an exception.
- add_throttle_flag()¶
Unsupported operation. Will raise an exception.
- apply_status_code(status_code)¶
Unsupported operation. Will raise an exception.
- close(end_time=None)¶
Unsupported operation. Will raise an exception.
- decrement_ref_counter()¶
No-op
- increment()¶
Increment total subsegments counter by 1.
- put_annotation(key, value)¶
Unsupported operation. Will raise an exception.
- put_http_meta(key, value)¶
Unsupported operation. Will raise an exception.
- put_metadata(key, value, namespace='default')¶
Unsupported operation. Will raise an exception.
- ready_to_send()¶
Facade segment should never be sent out. This always return False.
- serialize()¶
Unsupported operation. Will raise an exception.
- set_aws(aws_meta)¶
Unsupported operation. Will raise an exception.
- set_user(user)¶
Unsupported operation. Will raise an exception.
aws_xray_sdk.core.models.http module¶
aws_xray_sdk.core.models.noop_traceid module¶
aws_xray_sdk.core.models.segment module¶
- class aws_xray_sdk.core.models.segment.Segment(name, entityid=None, traceid=None, parent_id=None, sampled=True)¶
Bases:
EntityThe 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(subsegment)¶
Add input subsegment as a child subsegment and increment reference counter and total subsegments counter.
- decrement_ref_counter()¶
Decrement reference counter by 1 when a subsegment is closed.
- decrement_subsegments_size()¶
Decrement total subsegments by 1. This usually happens when a subsegment is streamed out.
- get_total_subsegments_size()¶
Return the number of total subsegments regardless of open or closed.
- increment()¶
Increment reference counter to track on open subsegments and total subsegments counter to track total size of subsegments it currently hold.
- ready_to_send()¶
Return True if the segment doesn’t have any open subsegments and itself is not in progress.
- remove_subsegment(subsegment)¶
Remove the reference of input subsegment.
- set_rule_name(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.
- set_service(service_info)¶
Add python runtime and version info. This method should be only used by the recorder.
- set_user(user)¶
set user of a segment. One segment can only have one user. User is indexed and can be later queried.
aws_xray_sdk.core.models.subsegment module¶
- class aws_xray_sdk.core.models.subsegment.Subsegment(name, namespace, segment)¶
Bases:
EntityThe work done in a single segment can be broke down into subsegments. Subsegments provide more granular timing information and details about downstream calls that your application made to fulfill the original request. A subsegment can contain additional details about a call to an AWS service, an external HTTP API, or an SQL database.
- add_subsegment(subsegment)¶
Add input subsegment as a child subsegment and increment reference counter and total subsegments counter of the parent segment.
- close(end_time=None)¶
Close the trace entity by setting end_time and flip the in progress flag to False. Also decrement parent segment’s ref counter by 1.
- Parameters:
end_time (int) – Epoch in seconds. If not specified current time will be used.
- remove_subsegment(subsegment)¶
Remove input subsegment from child subsegemnts and decrement parent segment total subsegments count.
- Parameters:
Subsegment – subsegment to remove.
- class aws_xray_sdk.core.models.subsegment.SubsegmentContextManager(recorder, name=None, **subsegment_kwargs)¶
Bases:
objectWrapper for segment and recorder to provide segment context manager.
- aws_xray_sdk.core.models.subsegment.is_already_recording(func)¶
- aws_xray_sdk.core.models.subsegment.set_as_recording(decorated_func, wrapped)¶
- aws_xray_sdk.core.models.subsegment.subsegment_decorator(wrapper=None, enabled=None, adapter=None, proxy=<class 'FunctionWrapper'>)¶
aws_xray_sdk.core.models.throwable module¶
aws_xray_sdk.core.models.trace_header module¶
- class aws_xray_sdk.core.models.trace_header.TraceHeader(root=None, parent=None, sampled=None, data=None)¶
Bases:
objectThe sampling decision and trace ID are added to HTTP requests in tracing headers named
X-Amzn-Trace-Id. The first X-Ray-integrated service that the request hits adds a tracing header, which is read by the X-Ray SDK and included in the response. Learn more about Tracing Header.- property data¶
Return the arbitrary fields in the trace header.
- classmethod from_header_str(header)¶
Create a TraceHeader object from a tracing header string extracted from a http request headers.
- property parent¶
Return the parent segment id in the header
- property root¶
Return trace id of the header
- property sampled¶
Return the sampling decision in the header. It’s 0 or 1 or ‘?’.
- to_header_str()¶
Convert to a tracing header string that can be injected to outgoing http request headers.
aws_xray_sdk.core.models.traceid module¶
- class aws_xray_sdk.core.models.traceid.TraceId¶
Bases:
objectA trace ID tracks the path of a request through your application. A trace collects all the segments generated by a single request. A trace ID is required for a segment.
- DELIMITER = '-'¶
- VERSION = '1'¶
- to_id()¶
Convert TraceId object to a string.