Class: Aws::Xray::Context
- Inherits:
-
Object
- Object
- Aws::Xray::Context
- Defined in:
- lib/aws/xray/context.rb
Defined Under Namespace
Classes: NotSetError
Constant Summary collapse
- VAR_NAME =
:_aws_xray_context_
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
- .current ⇒ Aws::Xray::Context
- .started? ⇒ Boolean
- .with_new_context(name, client, trace) {|Aws::Xray::Context| ... } ⇒ Object
Instance Method Summary collapse
-
#base_trace {|Aws::Xray::Segment| ... } ⇒ Object
Rescue standard errors and record the error to the segment.
-
#child_trace(remote:, name:) {|Aws::Xray::SubSegment| ... } ⇒ Object
Rescue standard errors and record the error to the sub segment.
-
#initialize(name, client, trace) ⇒ Context
constructor
A new instance of Context.
Constructor Details
#initialize(name, client, trace) ⇒ Context
Returns a new instance of Context.
55 56 57 58 59 60 |
# File 'lib/aws/xray/context.rb', line 55 def initialize(name, client, trace) @name = name @client = client @trace = trace @base_segment = Segment.build(@name, trace) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
53 54 55 |
# File 'lib/aws/xray/context.rb', line 53 def name @name end |
Class Method Details
.current ⇒ Aws::Xray::Context
17 18 19 |
# File 'lib/aws/xray/context.rb', line 17 def current Thread.current.thread_variable_get(VAR_NAME) || raise(NotSetError) end |
.started? ⇒ Boolean
22 23 24 |
# File 'lib/aws/xray/context.rb', line 22 def started? !!Thread.current.thread_variable_get(VAR_NAME) end |
.with_new_context(name, client, trace) {|Aws::Xray::Context| ... } ⇒ Object
35 36 37 38 39 40 |
# File 'lib/aws/xray/context.rb', line 35 def with_new_context(name, client, trace) build_current(name, client, trace) yield ensure remove_current end |
Instance Method Details
#base_trace {|Aws::Xray::Segment| ... } ⇒ Object
Rescue standard errors and record the error to the segment. Then re-raise the error.
67 68 69 70 71 72 73 74 75 |
# File 'lib/aws/xray/context.rb', line 67 def base_trace res = yield @base_segment @client.send_segment(@base_segment) res rescue => e @base_segment.set_error(fault: true, e: e) @client.send_segment(@base_segment) raise e end |
#child_trace(remote:, name:) {|Aws::Xray::SubSegment| ... } ⇒ Object
Rescue standard errors and record the error to the sub segment. Then re-raise the error.
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/aws/xray/context.rb', line 84 def child_trace(remote:, name:) sub = SubSegment.build(@trace, @base_segment, remote: remote, name: name) res = yield sub @client.send_segment(sub) res rescue => e sub.set_error(fault: true, e: e) @client.send_segment(sub) raise e end |