Class: XRay::LambdaContext
- Inherits:
-
DefaultContext
- Object
- DefaultContext
- XRay::LambdaContext
- Defined in:
- lib/aws-xray-sdk/lambda/lambda_context.rb
Overview
LambdaContext extends the default context so that we can provide an appropriate FacadeSegment as the root context for each function invocation.
Constant Summary collapse
- TRACE_ID_ENV_VAR =
'_X_AMZN_TRACE_ID'.freeze
Constants inherited from DefaultContext
DefaultContext::CONTEXT_MISSING_KEY, DefaultContext::DEFAULT_STRATEGY, DefaultContext::LOCAL_KEY, DefaultContext::SUPPORTED_STRATEGY
Instance Attribute Summary
Attributes inherited from DefaultContext
Instance Method Summary collapse
-
#check_context ⇒ Object
If the environment trace id changes, create a new facade for that segment and make it the context's current entity.
- #current_entity ⇒ Object
- #lambda_trace_id ⇒ Object
Methods inherited from DefaultContext
#clear!, #handle_context_missing, #initialize, #inject_context, #store_entity
Methods included from Logging
Methods included from Context
#clear!, #handle_context_missing, #inject_context, #store_entity
Constructor Details
This class inherits a constructor from XRay::DefaultContext
Instance Method Details
#check_context ⇒ Object
If the environment trace id changes, create a new facade for that segment and make it the context's current entity
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/aws-xray-sdk/lambda/lambda_context.rb', line 17 def check_context #Create a new FacadeSegment if the _X_AMZN_TRACE_ID changes. return if lambda_trace_id == @current_trace_id @current_trace_id = lambda_trace_id trace_header = XRay::TraceHeader.from_header_string(header_str: @current_trace_id) segment = FacadeSegment.new(trace_id: trace_header.root, parent_id: trace_header.parent_id, id: trace_header.parent_id, name: 'lambda_context', sampled: trace_header.sampled == 1 ) store_entity(entity: segment) end |
#current_entity ⇒ Object
32 33 34 35 |
# File 'lib/aws-xray-sdk/lambda/lambda_context.rb', line 32 def current_entity check_context #ensure the FacadeSegment is current whenever the current_entity is retrieved super end |
#lambda_trace_id ⇒ Object
11 12 13 |
# File 'lib/aws-xray-sdk/lambda/lambda_context.rb', line 11 def lambda_trace_id ENV[TRACE_ID_ENV_VAR] end |