trace_viz 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +63 -41
  3. data/lib/trace_viz/builders/base_builder.rb +11 -0
  4. data/lib/trace_viz/builders/diagram/base_builder.rb +10 -0
  5. data/lib/trace_viz/builders/diagram/message_builder.rb +96 -0
  6. data/lib/trace_viz/builders/diagram/sequence_builder.rb +50 -0
  7. data/lib/trace_viz/collectors/filters/base_class_filter.rb +3 -1
  8. data/lib/trace_viz/config/validator.rb +1 -1
  9. data/lib/trace_viz/defaults/config.rb +4 -2
  10. data/lib/trace_viz/exporters/base_exporter.rb +26 -5
  11. data/lib/trace_viz/exporters/mermaid_exporter.rb +17 -0
  12. data/lib/trace_viz/exporters/registry.rb +2 -0
  13. data/lib/trace_viz/exporters/text_exporter.rb +2 -24
  14. data/lib/trace_viz/extractors/base_extractor.rb +17 -0
  15. data/lib/trace_viz/extractors/diagram/base_extractor.rb +18 -0
  16. data/lib/trace_viz/extractors/diagram/box_extractor.rb +50 -0
  17. data/lib/trace_viz/extractors/diagram/message_extractor.rb +23 -0
  18. data/lib/trace_viz/extractors/diagram/participant_extractor.rb +37 -0
  19. data/lib/trace_viz/extractors/diagram/processors/message_processor.rb +93 -0
  20. data/lib/trace_viz/formatters/base_formatter.rb +1 -0
  21. data/lib/trace_viz/formatters/base_formatter_factory.rb +23 -0
  22. data/lib/trace_viz/formatters/diagram/sequence/base_formatter.rb +14 -0
  23. data/lib/trace_viz/formatters/diagram/sequence/message_formatter.rb +37 -0
  24. data/lib/trace_viz/formatters/diagram_formatter.rb +10 -0
  25. data/lib/trace_viz/formatters/export/formatter_factory.rb +8 -13
  26. data/lib/trace_viz/formatters/export/summary_group_formatter.rb +1 -1
  27. data/lib/trace_viz/formatters/helpers/digram/action_helper.rb +17 -0
  28. data/lib/trace_viz/formatters/helpers/digram/result_helper.rb +39 -0
  29. data/lib/trace_viz/formatters/helpers/log/params_helper.rb +8 -4
  30. data/lib/trace_viz/formatters/helpers/log/result_helper.rb +3 -3
  31. data/lib/trace_viz/formatters/helpers/log/summary/params_helper.rb +8 -4
  32. data/lib/trace_viz/formatters/helpers/params_helper.rb +8 -4
  33. data/lib/trace_viz/formatters/helpers/result_helper.rb +4 -3
  34. data/lib/trace_viz/formatters/helpers/source_helper.rb +4 -3
  35. data/lib/trace_viz/formatters/helpers/summary/params_helper.rb +7 -3
  36. data/lib/trace_viz/formatters/helpers/summary/source_helper.rb +3 -3
  37. data/lib/trace_viz/formatters/log/formatter_factory.rb +8 -13
  38. data/lib/trace_viz/formatters/log/summary_group_formatter.rb +1 -1
  39. data/lib/trace_viz/helpers/config_helper.rb +4 -0
  40. data/lib/trace_viz/loggers/post_collection_logger.rb +9 -4
  41. data/lib/trace_viz/loggers/trace_logger.rb +3 -6
  42. data/lib/trace_viz/managers/diagram/participant_manager.rb +23 -0
  43. data/lib/trace_viz/models/box.rb +19 -0
  44. data/lib/trace_viz/models/diagram.rb +27 -0
  45. data/lib/trace_viz/models/message.rb +16 -0
  46. data/lib/trace_viz/models/participant.rb +18 -0
  47. data/lib/trace_viz/models.rb +8 -0
  48. data/lib/trace_viz/renderers/base_renderer.rb +6 -3
  49. data/lib/trace_viz/renderers/diagram/sequence_renderer.rb +59 -0
  50. data/lib/trace_viz/renderers/render_context.rb +2 -3
  51. data/lib/trace_viz/renderers/renderer_builder.rb +20 -0
  52. data/lib/trace_viz/renderers/renderer_factory.rb +10 -22
  53. data/lib/trace_viz/renderers/summary_renderer.rb +18 -6
  54. data/lib/trace_viz/renderers/verbose_renderer.rb +6 -6
  55. data/lib/trace_viz/shared/renderer_helper.rb +4 -25
  56. data/lib/trace_viz/syntax/mermaid/sequence_syntax.rb +99 -0
  57. data/lib/trace_viz/trace_data/base.rb +7 -0
  58. data/lib/trace_viz/trace_data/node.rb +9 -3
  59. data/lib/trace_viz/trace_data/root_node.rb +4 -0
  60. data/lib/trace_viz/trace_data/summary_node.rb +5 -9
  61. data/lib/trace_viz/trace_data/trace_point/base.rb +4 -0
  62. data/lib/trace_viz/trace_data/trace_point/method_call.rb +4 -0
  63. data/lib/trace_viz/transformers/base_transformer.rb +29 -0
  64. data/lib/trace_viz/transformers/summary_transformer.rb +70 -0
  65. data/lib/trace_viz/utils/alias_generator.rb +58 -0
  66. data/lib/trace_viz/utils/format/key_value_formatter.rb +42 -0
  67. data/lib/trace_viz/utils/format/value_truncator.rb +123 -0
  68. data/lib/trace_viz/utils.rb +8 -0
  69. data/lib/trace_viz/version.rb +1 -1
  70. metadata +38 -11
  71. data/lib/trace_viz/renderers/summary/node_processor.rb +0 -82
  72. data/lib/trace_viz/utils/format_utils/key_value_formatter.rb +0 -37
  73. data/lib/trace_viz/utils/format_utils/value_truncator.rb +0 -74
  74. data/lib/trace_viz/utils/format_utils.rb +0 -24
@@ -0,0 +1,93 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "trace_viz/formatters/diagram/sequence/message_formatter"
4
+ require "trace_viz/builders/diagram/message_builder"
5
+
6
+ module TraceViz
7
+ module Extractors
8
+ module Diagram
9
+ module Processors
10
+ class MessageProcessor
11
+ def initialize(participants)
12
+ @formatter = Formatters::Diagram::Sequence::MessageFormatter.new
13
+ @message_builder = Builders::Diagram::MessageBuilder.new(@formatter, participants)
14
+ end
15
+
16
+ def process_node(node, caller_node = nil)
17
+ trace = node.data
18
+ caller_trace = caller_node&.data
19
+
20
+ [].tap do |messages|
21
+ # Handle participant transitions
22
+ messages << @message_builder.build_call_message(
23
+ caller_trace,
24
+ trace,
25
+ ) if caller_trace
26
+
27
+ # Process the current node
28
+ messages << handle_loop_start(trace)
29
+ messages << handle_internal_message(trace)
30
+ messages << handle_note(trace)
31
+ messages << handle_activation(trace)
32
+ messages.concat(process_children(node))
33
+ messages << handle_deactivation(trace)
34
+ messages << handle_loop_end(trace)
35
+
36
+ # Update the current node after processing
37
+ messages << @message_builder.build_return_message(
38
+ trace,
39
+ caller_trace,
40
+ ) if caller_trace
41
+ end.compact
42
+ end
43
+
44
+ private
45
+
46
+ def handle_loop_start(trace)
47
+ return unless loop?(trace)
48
+
49
+ @message_builder.build_loop_start_message(trace)
50
+ end
51
+
52
+ def handle_internal_message(trace)
53
+ @message_builder.build_internal_message(trace)
54
+ end
55
+
56
+ def handle_note(trace)
57
+ @message_builder.build_note(trace)
58
+ end
59
+
60
+ def handle_activation(trace)
61
+ return unless node_has_children?(trace)
62
+
63
+ @message_builder.build_activate_message(trace)
64
+ end
65
+
66
+ def handle_deactivation(trace)
67
+ return unless node_has_children?(trace)
68
+
69
+ @message_builder.build_deactivate_message(trace)
70
+ end
71
+
72
+ def handle_loop_end(trace)
73
+ return unless loop?(trace)
74
+
75
+ @message_builder.build_loop_end_message
76
+ end
77
+
78
+ def process_children(node)
79
+ node.children.flat_map { |child| process_node(child, node) }
80
+ end
81
+
82
+ def loop?(trace)
83
+ trace.key == :summary_group
84
+ end
85
+
86
+ def node_has_children?(trace)
87
+ trace.children.any?
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
@@ -7,6 +7,7 @@ module TraceViz
7
7
  class BaseFormatter
8
8
  include Helpers::ConfigHelper
9
9
 
10
+ # Format the data to a line
10
11
  def call
11
12
  raise NotImplementedError
12
13
  end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TraceViz
4
+ module Formatters
5
+ class BaseFormatterFactory
6
+ def initialize(formatters)
7
+ @formatters = formatters.freeze
8
+ end
9
+
10
+ def fetch_formatter(key)
11
+ @formatters.fetch(key) do
12
+ raise ArgumentError, "Unsupported formatter key: #{key}. Available keys: #{available_keys.join(", ")}"
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def available_keys
19
+ @formatters.keys
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../diagram_formatter"
4
+
5
+ module TraceViz
6
+ module Formatters
7
+ module Diagram
8
+ module Sequence
9
+ class BaseFormatter < Formatters::DiagramFormatter
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "base_formatter"
4
+ require "trace_viz/formatters/helpers"
5
+
6
+ module TraceViz
7
+ module Formatters
8
+ module Diagram
9
+ module Sequence
10
+ class MessageFormatter < BaseFormatter
11
+ include Helpers::ParamsHelper
12
+ include Helpers::Diagram::ActionHelper
13
+ include Helpers::Diagram::ResultHelper
14
+
15
+ def format_internal_message(trace)
16
+ [
17
+ action_representation(trace),
18
+ params_representation(trace),
19
+ ].join("")
20
+ end
21
+
22
+ def format_result(trace)
23
+ result_representation(trace)
24
+ end
25
+
26
+ def format_call
27
+ "Calling"
28
+ end
29
+
30
+ def format_return
31
+ "Returning"
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "base_formatter"
4
+
5
+ module TraceViz
6
+ module Formatters
7
+ class DiagramFormatter < BaseFormatter
8
+ end
9
+ end
10
+ end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "../base_formatter_factory"
3
4
  require_relative "method_call_formatter"
4
5
  require_relative "method_return_formatter"
5
6
  require_relative "summary_group_formatter"
@@ -7,19 +8,13 @@ require_relative "summary_group_formatter"
7
8
  module TraceViz
8
9
  module Formatters
9
10
  module Export
10
- class FormatterFactory
11
- FORMATTERS = {
12
- call: MethodCallFormatter.new,
13
- return: MethodReturnFormatter.new,
14
- summary_group: SummaryGroupFormatter.new,
15
- }.freeze
16
-
17
- class << self
18
- def fetch_formatter(key)
19
- FORMATTERS.fetch(key) do
20
- raise ArgumentError, "Unsupported factory key: #{key}"
21
- end
22
- end
11
+ class FormatterFactory < BaseFormatterFactory
12
+ def initialize
13
+ super(
14
+ call: Export::MethodCallFormatter.new,
15
+ return: Export::MethodReturnFormatter.new,
16
+ summary_group: Export::SummaryGroupFormatter.new
17
+ )
23
18
  end
24
19
  end
25
20
  end
@@ -26,7 +26,7 @@ module TraceViz
26
26
  def summary_info(trace_data)
27
27
  "[Summary: #{trace_data.count} calls | Avg Time: #{format(
28
28
  "in %.6fms",
29
- trace_data.average_duration,
29
+ trace_data.duration,
30
30
  )}]"
31
31
  end
32
32
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TraceViz
4
+ module Formatters
5
+ module Helpers
6
+ module Diagram
7
+ module ActionHelper
8
+ def action_representation(trace_data)
9
+ return unless config.general[:show_method_name]
10
+
11
+ trace_data.action
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "trace_viz/utils"
4
+
5
+ module TraceViz
6
+ module Formatters
7
+ module Helpers
8
+ module Diagram
9
+ module ResultHelper
10
+ def result_representation(trace_data)
11
+ return unless config.result[:show]
12
+
13
+ result = truncate_structure(trace_data.result)
14
+ result = sinitize_result(result)
15
+ result
16
+ end
17
+
18
+ private
19
+
20
+ def truncate_structure(input)
21
+ Utils::Format::ValueTruncator.truncate(
22
+ input,
23
+ length: config.result[:truncate_value],
24
+ hash_length: config.result[:truncate_length],
25
+ )
26
+ end
27
+
28
+ def sinitize_result(input)
29
+ input.to_s
30
+ # .gsub('"', "")
31
+ # .gsub("'", "")
32
+ .gsub("#", "")
33
+ .strip
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "trace_viz/utils/format_utils"
3
+ require "trace_viz/utils"
4
4
 
5
5
  module TraceViz
6
6
  module Formatters
@@ -26,7 +26,7 @@ module TraceViz
26
26
  def truncate_values(params, length)
27
27
  return params unless length
28
28
 
29
- params.transform_values { |value| Utils::FormatUtils.truncate_value(value, length) }
29
+ params.transform_values { |value| Utils::Format::ValueTruncator.truncate(value, length: length) }
30
30
  end
31
31
 
32
32
  def colorize_keys_and_values(params)
@@ -35,13 +35,17 @@ module TraceViz
35
35
  end
36
36
 
37
37
  def format_as_string(params, mode)
38
- Utils::FormatUtils.format_key_value_pairs(params, mode)
38
+ Utils::Format::KeyValueFormatter.format_pairs(params, mode: mode)
39
39
  end
40
40
 
41
41
  def wrap_params(params_string, config)
42
42
  return unless params_string
43
43
 
44
- truncated = Utils::FormatUtils.truncate_value(params_string, config.params[:truncate_length])
44
+ truncated = Utils::Format::ValueTruncator.truncate(
45
+ params_string,
46
+ length: config.params[:truncate_length],
47
+ )
48
+
45
49
  "(#{truncated})"
46
50
  end
47
51
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "trace_viz/utils/format_utils"
3
+ require "trace_viz/utils"
4
4
 
5
5
  module TraceViz
6
6
  module Formatters
@@ -10,9 +10,9 @@ module TraceViz
10
10
  def format_result(trace_data, config)
11
11
  return unless config.result[:show]
12
12
 
13
- truncated_result = Utils::FormatUtils.truncate_value(
13
+ truncated_result = Utils::Format::ValueTruncator.truncate(
14
14
  trace_data.result.inspect,
15
- config.result[:truncate_length],
15
+ length: config.result[:truncate_value],
16
16
  )
17
17
 
18
18
  prefix = colorize_for("#=>", :trace_result_prefix)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "trace_viz/utils/format_utils"
3
+ require "trace_viz/utils"
4
4
 
5
5
  module TraceViz
6
6
  module Formatters
@@ -27,7 +27,7 @@ module TraceViz
27
27
  def truncate_values(params, length)
28
28
  return params unless length
29
29
 
30
- params.transform_values { |value| Utils::FormatUtils.truncate_value(value, length) }
30
+ params.transform_values { |value| Utils::Format::ValueTruncator.truncate(value, length: length) }
31
31
  end
32
32
 
33
33
  def colorize_keys_and_values(params)
@@ -36,13 +36,17 @@ module TraceViz
36
36
  end
37
37
 
38
38
  def format_as_string(params, mode)
39
- Utils::FormatUtils.format_key_value_pairs(params, mode)
39
+ Utils::Format::KeyValueFormatter.format_pairs(params, mode: mode)
40
40
  end
41
41
 
42
42
  def wrap_params(params_string, config)
43
43
  return unless params_string
44
44
 
45
- truncated = Utils::FormatUtils.truncate_value(params_string, config.params[:truncate_length])
45
+ truncated = Utils::Format::ValueTruncator.truncate(
46
+ params_string,
47
+ length: config.params[:truncate_length],
48
+ )
49
+
46
50
  "(#{truncated})"
47
51
  end
48
52
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "trace_viz/utils/format_utils"
3
+ require "trace_viz/utils"
4
4
 
5
5
  module TraceViz
6
6
  module Formatters
@@ -24,17 +24,21 @@ module TraceViz
24
24
  def truncate_param_values(params, max_length)
25
25
  return params unless max_length
26
26
 
27
- params.transform_values { |value| Utils::FormatUtils.truncate_value(value, max_length) }
27
+ params.transform_values { |value| Utils::Format::ValueTruncator.truncate(value, length: max_length) }
28
28
  end
29
29
 
30
30
  def stringify_params(params, mode)
31
- Utils::FormatUtils.format_key_value_pairs(params, mode)
31
+ Utils::Format::KeyValueFormatter.format_pairs(params, mode: mode)
32
32
  end
33
33
 
34
34
  def wrap_params_string(params_string, config)
35
35
  return unless params_string
36
36
 
37
- truncated_string = Utils::FormatUtils.truncate_value(params_string, config.params[:truncate_length])
37
+ truncated_string = Utils::Format::ValueTruncator.truncate(
38
+ params_string,
39
+ length: config.params[:truncate_length],
40
+ )
41
+
38
42
  "(#{truncated_string})"
39
43
  end
40
44
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "trace_viz/utils/format_utils"
3
+ require "trace_viz/utils"
4
4
 
5
5
  module TraceViz
6
6
  module Formatters
@@ -9,10 +9,11 @@ module TraceViz
9
9
  def result_representation(trace_data)
10
10
  return unless config.result[:show]
11
11
 
12
- truncated_result = Utils::FormatUtils.truncate_value(
12
+ truncated_result = Utils::Format::ValueTruncator.truncate(
13
13
  trace_data.result.inspect,
14
- config.result[:truncate_length],
14
+ length: config.result[:truncate_value],
15
15
  )
16
+
16
17
  "#=> #{truncated_result}"
17
18
  end
18
19
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "trace_viz/utils/format_utils"
3
+ require "trace_viz/utils"
4
4
 
5
5
  module TraceViz
6
6
  module Formatters
@@ -9,11 +9,12 @@ module TraceViz
9
9
  def source_location_representation(trace_data)
10
10
  return unless config.source_location[:show]
11
11
 
12
- truncated_path = Utils::FormatUtils.truncate_value(
12
+ truncated_path = Utils::Format::ValueTruncator.truncate(
13
13
  trace_data.path,
14
- config.source_location[:truncate_length],
14
+ length: config.source_location[:truncate_length],
15
15
  direction: :start,
16
16
  )
17
+
17
18
  "at #{truncated_path}:#{trace_data.line_number}"
18
19
  end
19
20
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "trace_viz/utils/format_utils"
3
+ require "trace_viz/utils"
4
4
 
5
5
  module TraceViz
6
6
  module Formatters
@@ -25,13 +25,17 @@ module TraceViz
25
25
  end
26
26
 
27
27
  def format_as_string(params, mode)
28
- Utils::FormatUtils.format_key_value_pairs(params, mode)
28
+ Utils::Format::KeyValueFormatter.format_pairs(params, mode: mode)
29
29
  end
30
30
 
31
31
  def wrap_params_template(params_string, config)
32
32
  return unless params_string
33
33
 
34
- truncated = Utils::FormatUtils.truncate_value(params_string, config.params[:truncate_length])
34
+ truncated = Utils::Format::ValueTruncator.truncate(
35
+ params_string,
36
+ length: config.params[:truncate_length],
37
+ )
38
+
35
39
  "(#{truncated})"
36
40
  end
37
41
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "trace_viz/utils/format_utils"
3
+ require "trace_viz/utils"
4
4
 
5
5
  module TraceViz
6
6
  module Formatters
@@ -10,9 +10,9 @@ module TraceViz
10
10
  def source_location_representation(trace_data)
11
11
  return unless config.source_location[:show]
12
12
 
13
- truncated_path = Utils::FormatUtils.truncate_value(
13
+ truncated_path = Utils::Format::ValueTruncator.truncate(
14
14
  trace_data.path,
15
- config.source_location[:truncate_length],
15
+ length: config.source_location[:truncate_length],
16
16
  direction: :start,
17
17
  )
18
18
  "at #{truncated_path}"
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "../base_formatter_factory"
3
4
  require_relative "method_call_formatter"
4
5
  require_relative "method_return_formatter"
5
6
  require_relative "summary_group_formatter"
@@ -7,19 +8,13 @@ require_relative "summary_group_formatter"
7
8
  module TraceViz
8
9
  module Formatters
9
10
  module Log
10
- class FormatterFactory
11
- FORMATTERS = {
12
- call: MethodCallFormatter.new,
13
- return: MethodReturnFormatter.new,
14
- summary_group: SummaryGroupFormatter.new,
15
- }.freeze
16
-
17
- class << self
18
- def fetch_formatter(key)
19
- FORMATTERS.fetch(key) do
20
- raise ArgumentError, "Unsupported factory key: #{key}"
21
- end
22
- end
11
+ class FormatterFactory < BaseFormatterFactory
12
+ def initialize
13
+ super(
14
+ call: Log::MethodCallFormatter.new,
15
+ return: Log::MethodReturnFormatter.new,
16
+ summary_group: Log::SummaryGroupFormatter.new
17
+ )
23
18
  end
24
19
  end
25
20
  end
@@ -27,7 +27,7 @@ module TraceViz
27
27
  colorize(
28
28
  "[Summary: #{trace_data.count} calls | Avg Time: #{format(
29
29
  "in %.6fms",
30
- trace_data.average_duration,
30
+ trace_data.duration,
31
31
  )}]",
32
32
  :bold,
33
33
  :italic,
@@ -8,6 +8,10 @@ module TraceViz
8
8
  def config
9
9
  Context.for(:config).configuration
10
10
  end
11
+
12
+ def fetch_general_config(key)
13
+ config.general[key]
14
+ end
11
15
  end
12
16
  end
13
17
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "trace_viz/formatters/log/formatter_factory"
4
+ require "trace_viz/renderers/renderer_builder"
4
5
  require "trace_viz/shared"
5
6
  require_relative "base_logger"
6
7
  require_relative "log_level_resolver"
@@ -8,13 +9,19 @@ require_relative "log_level_resolver"
8
9
  module TraceViz
9
10
  module Loggers
10
11
  class PostCollectionLogger < BaseLogger
12
+ include Helpers::ConfigHelper
11
13
  include Shared::RendererHelper
12
14
 
13
15
  def initialize(collector)
14
16
  super()
15
17
 
16
18
  @collector = collector
17
- @renderer = build_renderer(collector, Formatters::Log::FormatterFactory)
19
+
20
+ @renderer = Renderers::RendererBuilder.build(
21
+ collector,
22
+ key: fetch_general_config(:mode),
23
+ formatter_factory: Formatters::Log::FormatterFactory.new,
24
+ )
18
25
  end
19
26
 
20
27
  def log
@@ -26,9 +33,7 @@ module TraceViz
26
33
  attr_reader :collector, :renderer
27
34
 
28
35
  def log_line(line)
29
- log_message(resolve_log_level(line[:trace_data]), line[:line])
30
-
31
- process_lines(line[:nested_lines]) { |nested| log_line(nested) }
36
+ log_message(resolve_log_level(line[:data]), line[:line])
32
37
  end
33
38
 
34
39
  def resolve_log_level(trace_data)
@@ -11,6 +11,7 @@ module TraceViz
11
11
  super()
12
12
 
13
13
  @trace_data = trace_data
14
+ @formatter_factory = Formatters::Log::FormatterFactory.new
14
15
  end
15
16
 
16
17
  def log
@@ -19,18 +20,14 @@ module TraceViz
19
20
 
20
21
  private
21
22
 
22
- attr_reader :trace_data
23
+ attr_reader :trace_data, :formatter_factory
23
24
 
24
25
  def log_level
25
26
  LogLevelResolver.resolve(trace_data)
26
27
  end
27
28
 
28
29
  def formatted_message
29
- fetch_formatter(trace_data).call(trace_data)
30
- end
31
-
32
- def fetch_formatter(trace_data)
33
- Formatters::Log::FormatterFactory.fetch_formatter(trace_data.event)
30
+ formatter_factory.fetch_formatter(trace_data.key).call(trace_data)
34
31
  end
35
32
  end
36
33
  end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TraceViz
4
+ module Managers
5
+ module Diagram
6
+ class ParticipantsManager
7
+ def initialize(participants)
8
+ @participants_map = build_participants_map(participants)
9
+ end
10
+
11
+ def find(name)
12
+ @participants_map[name.to_s]
13
+ end
14
+
15
+ private
16
+
17
+ def build_participants_map(participants)
18
+ participants.each_with_object({}) { |participant, memo| memo[participant.name] = participant }
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end