Module: Trailblazer::Developer::Trace
- Defined in:
- lib/trailblazer/developer/trace.rb,
lib/trailblazer/developer/trace/present.rb,
lib/trailblazer/developer/trace/focusable.rb,
lib/trailblazer/developer/trace/inspector.rb
Defined Under Namespace
Modules: Focusable, Inspector, Present Classes: Entity, Level, Stack
Constant Summary collapse
- Activity =
Trailblazer::Activity
Class Method Summary collapse
- .arguments_for_call(activity, options, original_flow_options, **original_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, ctx, flow), circuit_options) ⇒ Object
It’s important to understand that :stack is mutated by design.
-
.capture_return(wrap_config, ctx, flow), circuit_options) ⇒ Object
taskWrap step to capture outgoing arguments from a step.
- .default_input_data_collector(wrap_config, ctx, _, circuit_options) ⇒ Object
- .default_output_data_collector(wrap_config, ctx, _, _) ⇒ Object
-
.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, original_flow_options, **original_circuit_options) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/trailblazer/developer/trace.rb', line 20 def arguments_for_call(activity, (, ), **) = { stack: Trace::Stack.new, input_data_collector: Trace.method(:default_input_data_collector), output_data_collector: Trace.method(:default_output_data_collector), } = { **, **Hash( ) } = { wrap_runtime: ::Hash.new(Trace.merge_plan), # DISCUSS: this overrides existing {:wrap_runtime}. } = { **, ** } return activity, [ , ], 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, ctx, flow), 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. taskWrap step to capture incoming arguments of a step.
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/trailblazer/developer/trace.rb', line 56 def capture_args(wrap_config, ((ctx, flow), )) flow[:stack].indent! flow[:stack] << Entity::Input.new( wrap_config[:task], [:activity], flow[:input_data_collector].call(wrap_config, [ctx, flow], ) ).freeze return wrap_config, [[ctx, flow], ] end |
.capture_return(wrap_config, ctx, flow), circuit_options) ⇒ Object
taskWrap step to capture outgoing arguments from a step.
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/trailblazer/developer/trace.rb', line 69 def capture_return(wrap_config, ((ctx, flow), )) flow[:stack] << Entity::Output.new( wrap_config[:task], {}, flow[:output_data_collector].call(wrap_config, [ctx, flow], ) ).freeze flow[:stack].unindent! return wrap_config, [[ctx, flow], ] end |
.default_input_data_collector(wrap_config, ctx, _, circuit_options) ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/trailblazer/developer/trace.rb', line 81 def default_input_data_collector(wrap_config, (ctx, _), ) graph = Trailblazer::Activity::Introspect::Graph([:activity]) task = wrap_config[:task] name = (node = graph.find { |node| node[:task] == task }) ? node[:id] : task { ctx: ctx, task_name: name } end |
.default_output_data_collector(wrap_config, ctx, _, _) ⇒ Object
89 90 91 |
# File 'lib/trailblazer/developer/trace.rb', line 89 def default_output_data_collector(wrap_config, (ctx, _), _) { ctx: ctx, signal: wrap_config[:return_signal] } end |
.merge_plan ⇒ Object
Insertions for the trace tasks that capture the arguments just before calling the task, and before the TaskWrap is finished.
45 46 47 48 49 50 |
# File 'lib/trailblazer/developer/trace.rb', line 45 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 |