Module: Trailblazer::Developer::Trace
- Defined in:
- lib/trailblazer/developer/trace.rb,
lib/trailblazer/developer/trace/present.rb
Defined Under Namespace
Modules: Present Classes: Entity, Level, Stack
Constant Summary collapse
- Activity =
Trailblazer::Activity
Class Method Summary collapse
- .arguments_for_call(activity, options, flow_options, **circuit_options) ⇒ Object
-
.call(activity, ctx, flow_options, circuit_options = {}) ⇒ Object
(also: invoke)
Public entry point to activate tracing when running activity.
-
.capture_args(wrap_config, original_args) ⇒ Object
taskWrap step to capture incoming arguments of a step.
-
.capture_for(task, ctx, flow, activity:, **circuit_options) ⇒ Object
It’s important to understand that :stack is mutated by design.
-
.capture_return(wrap_config, original_args) ⇒ Object
taskWrap step to capture outgoing arguments from a step.
-
.merge_plan ⇒ Object
Insertions for the trace tasks that capture the arguments just before calling the task, and before the TaskWrap is finished.
Class Method Details
.arguments_for_call(activity, options, flow_options, **circuit_options) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/trailblazer/developer/trace.rb', line 20 def arguments_for_call(activity, (, ), **) = { stack: Trace::Stack.new, } = { wrap_runtime: ::Hash.new(Trace.merge_plan), # DISCUSS: this overrides existing {:wrap_runtime}. } return activity, [ , .merge() ], .merge() end |
.call(activity, ctx, flow_options, circuit_options = {}) ⇒ Object Also known as: invoke
Public entry point to activate tracing when running activity.
10 11 12 13 14 15 16 |
# File 'lib/trailblazer/developer/trace.rb', line 10 def call(activity, (ctx, ), ={}) activity, (ctx, ), = Trace.arguments_for_call( activity, [ctx, ], ) # only run once for the entire circuit! signal, (ctx, ) = Activity::TaskWrap.invoke(activity, [ctx, ], ) return [:stack], signal, [ctx, ] end |
.capture_args(wrap_config, original_args) ⇒ Object
taskWrap step to capture incoming arguments of a step.
46 47 48 49 50 |
# File 'lib/trailblazer/developer/trace.rb', line 46 def capture_args(wrap_config, original_args) original_args = capture_for(wrap_config[:task], *original_args) return wrap_config, original_args end |
.capture_for(task, ctx, flow, activity:, **circuit_options) ⇒ Object
It’s important to understand that :stack is mutated by design. This is needed so in case of exceptions we still have a “global” trace - unfortunately Ruby doesn’t allow us a better way.
69 70 71 72 73 74 75 76 77 |
# File 'lib/trailblazer/developer/trace.rb', line 69 def capture_for(task, (ctx, flow), activity:, **) flow[:stack].indent! flow[:stack] << Entity::Input.new( task, activity, [ctx, ctx.inspect] ).freeze return [ctx, flow], .merge(activity: activity) end |
.capture_return(wrap_config, original_args) ⇒ Object
taskWrap step to capture outgoing arguments from a step.
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/trailblazer/developer/trace.rb', line 53 def capture_return(wrap_config, original_args) (, , _) = original_args[0] [:stack] << Entity::Output.new( wrap_config[:task], {}, wrap_config[:return_signal] ).freeze [:stack].unindent! return wrap_config, original_args end |
.merge_plan ⇒ Object
Insertions for the trace tasks that capture the arguments just before calling the task, and before the TaskWrap is finished.
38 39 40 41 42 43 |
# File 'lib/trailblazer/developer/trace.rb', line 38 def merge_plan Activity::TaskWrap::Pipeline::Merge.new( [Activity::TaskWrap::Pipeline.method(:insert_before), "task_wrap.call_task", ["task_wrap.capture_args", Trace.method(:capture_args)]], [Activity::TaskWrap::Pipeline.method(:append), nil, ["task_wrap.capture_return", Trace.method(:capture_return)]], ) end |