aws_xray_sdk.core.lambda_launcher

Module Contents

log
LAMBDA_TRACE_HEADER_KEY = _X_AMZN_TRACE_ID
LAMBDA_TASK_ROOT_KEY = LAMBDA_TASK_ROOT
TOUCH_FILE_DIR = /tmp/.aws-xray/
TOUCH_FILE_PATH = /tmp/.aws-xray/initialized
check_in_lambda()

Return None if SDK is not loaded in AWS Lambda worker. Otherwise drop a touch file and return a lambda context.

class LambdaContext

Bases:aws_xray_sdk.core.context.Context

Lambda service will generate a segment for each function invocation which cannot be mutated. The context doesn’t keep any manually created segment but instead every time get_trace_entity() gets called it refresh the facade segment based on environment variables set by Lambda worker.

context_missing
put_segment(self, segment)

No-op.

end_segment(self, end_time=None)

No-op.

put_subsegment(self, subsegment)

Refresh the facade segment every time this function is invoked to prevent a new subsegment from being attached to a leaked segment/subsegment.

get_trace_entity(self)
_refresh_context(self)

Get current facade segment. To prevent resource leaking in Lambda worker, every time there is segment present, we compare its trace id to current environment variables. If it is different we create a new facade segment and clean up subsegments stored.

handle_context_missing(self)

No-op.

_initialize_context(self, trace_header)

Create a facade segment based on environment variables set by AWS Lambda and initialize storage for subsegments.