Module: Trailblazer::Pro::Debugger
- Defined in:
- lib/trailblazer/pro/debugger.rb
Defined Under Namespace
Classes: Push
Class Method Summary collapse
-
.call(debugger_trace:, activity:, render_wtf: false, renderer:, **options) ⇒ Object
Called in Trace::Present.call as :render_method.
-
.push(trace_data, activity:, now: DateTime.now, **options) ⇒ Object
Push.
- .render_trace_data(debugger_trace, activity:) ⇒ Object
Class Method Details
.call(debugger_trace:, activity:, render_wtf: false, renderer:, **options) ⇒ Object
Called in Trace::Present.call as :render_method.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/trailblazer/pro/debugger.rb', line 7 def call(debugger_trace:, activity:, render_wtf: false, renderer:, **) trace_data = render_trace_data(debugger_trace, activity: activity, **) trace_envelope = { fields: { activity_name: {stringValue: activity}, trace: {stringValue: trace_data}, created_at: {timestampValue: DateTime.now}, # we're using local client time currently. } } session, stored_trace_id, session_updated = push(trace_envelope, activity: activity, **) debugger_url = "https://ide.trailblazer.to/#{stored_trace_id}" # output = "[TRB PRO] view trace (#{activity}) at #{debugger_url}" # output = Developer::Wtf::Renderer::String.bold(output) output = Developer::Wtf::Renderer::String.bold("[TRB PRO] view trace (#{activity}) at ") output += debugger_url # DISCUSS: what do we want bold here? if render_wtf # TODO: take the color_map from outside caller. wtf_output = Developer::Trace::Present.render(debugger_trace: debugger_trace, renderer: renderer, color_map: Developer::Wtf::Renderer::DEFAULT_COLOR_MAP) # , activity: activity output = [wtf_output, output].join("\n") end returned_values = [session, stored_trace_id, debugger_url, trace_envelope, session_updated] return output, returned_values end |
.push(trace_data, activity:, now: DateTime.now, **options) ⇒ Object
Push
111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/trailblazer/pro/debugger.rb', line 111 def push(trace_data, activity:, now: DateTime.now, **) # signal, (ctx, _) = Trailblazer::Developer.wtf?(Push, [{now: now, data_to_store: trace_data, **options}, {}]) _signal, (ctx, _) = Trailblazer::Activity.(Push, {now: now, data_to_store: trace_data, **}) # signal, (ctx, _) = Push.invoke([{now: now, data_to_store: trace_data, **options}, {}]) session = ctx[:session] stored_trace_id = ctx[:id] session_updated = ctx[:session_updated] return session, stored_trace_id, session_updated end |
.render_trace_data(debugger_trace, activity:) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/trailblazer/pro/debugger.rb', line 38 def render_trace_data(debugger_trace, activity:, **) flat_tree_json = debugger_trace.to_a.collect do |debugger_node| # TODO: do we even need to grab tw by path here? introspect_nodes_node = OpenStruct.new(task: debugger_node.task) tw_render = Developer::Render::TaskWrap.render_for(debugger_node.activity, introspect_nodes_node) # This rendering code has deep knowledge of Trace/pro/v1 tracing interface. { id: debugger_node.id.to_s, runtime_id: debugger_node.runtime_id, level: debugger_node.level, label: debugger_node.label, ctx_snapshots: { before: debugger_node.snapshot_before.data[:ctx_variable_changeset].collect { |name, hash, has_changed| [name, {version: hash.to_s, has_changed: !!has_changed}] }, after: debugger_node.snapshot_after ? debugger_node.snapshot_after.data[:ctx_variable_changeset].collect { |name, hash, has_changed| [name, {version: hash.to_s, has_changed: !!has_changed}] } # FIXME: of course, this is horrible. : [], }, rendered_task_wrap: tw_render, } end JSON.dump( nodes: flat_tree_json, variable_versions: debugger_trace.to_h[:variable_versions].to_h, pro_version: Pro::VERSION.to_s, ) end |