Skip to content

Commit

Permalink
better structure by extracting.
Browse files Browse the repository at this point in the history
  • Loading branch information
apotonick committed May 30, 2024
1 parent f27e372 commit 1c216ee
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions lib/trailblazer/pro/debugger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,8 @@ module Debugger
def call(activity:, render_wtf: false, **options)
output = ""

trace_data = render_trace_data(activity: activity, **options)

trace_envelope = {
fields: {
activity_name: {stringValue: activity},
trace: {stringValue: trace_data},
created_at: {timestampValue: DateTime.now}, # we're using local client time currently.
}
}
trace_data = render_trace_data(activity: activity, **options)
trace_envelope = trace_envelope_for(activity: activity, trace_data: trace_data)

session, stored_trace_id, session_updated = push(trace_envelope, activity: activity, **options)

Expand All @@ -31,11 +24,9 @@ def call(activity:, render_wtf: false, **options)
return output, []
end

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?
debugger_link, debugger_url = render_debugger_link(stored_trace_id: stored_trace_id, activity: activity)

output += debugger_link

returned_values = [session, stored_trace_id, debugger_url, trace_envelope, session_updated]

Expand Down Expand Up @@ -74,13 +65,33 @@ def render_trace_data(debugger_trace:, activity:, **)
)
end

def trace_envelope_for(activity:, trace_data:)
{
fields: {
activity_name: {stringValue: activity},
trace: {stringValue: trace_data},
created_at: {timestampValue: DateTime.now}, # we're using local client time currently.
}
}
end

def render_original_wtf_trace(debugger_trace:, renderer:, color_map: Developer::Wtf::Renderer::DEFAULT_COLOR_MAP, **)
# 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

def render_debugger_link(stored_trace_id:, 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)
link = Developer::Wtf::Renderer::String.bold("[TRB PRO] view trace (#{activity}) at ")
link += debugger_url # DISCUSS: what do we want bold here?

return link, debugger_url
end

class Push < Trailblazer::Activity::Railway
step Subprocess(Client::Connect), # TODO: assert that success/failure go to right Track.
Output(:failure) => Track(:failure),
Expand Down

0 comments on commit 1c216ee

Please sign in to comment.