trace_viz 0.0.2 → 1.0.0
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.
- checksums.yaml +4 -4
- data/README.md +40 -37
- data/Steepfile +34 -0
- data/examples/eu_central_bank.rb +69 -0
- data/examples/example.cast +189 -285
- data/lib/trace_viz/adapters/base_adapter.rb +24 -1
- data/lib/trace_viz/adapters/trace_point_adapter.rb +3 -10
- data/lib/trace_viz/collectors/base_collector.rb +42 -35
- data/lib/trace_viz/collectors/filters/base_class_filter.rb +29 -0
- data/lib/trace_viz/collectors/filters/base_exclude_filter.rb +16 -0
- data/lib/trace_viz/collectors/filters/base_filter.rb +2 -8
- data/lib/trace_viz/collectors/filters/base_include_filter.rb +16 -0
- data/lib/trace_viz/collectors/filters/exclude_classes_filter.rb +4 -17
- data/lib/trace_viz/collectors/filters/exclude_default_classes_filter.rb +22 -26
- data/lib/trace_viz/collectors/filters/include_classes_filter.rb +4 -17
- data/lib/trace_viz/collectors/hierarchy_linker.rb +30 -0
- data/lib/trace_viz/collectors/matchers/base_matcher.rb +13 -0
- data/lib/trace_viz/collectors/matchers/trace_point_action_matcher.rb +12 -10
- data/lib/trace_viz/collectors/matchers/within_depth_matcher.rb +6 -5
- data/lib/trace_viz/collectors/steps/assign_depth_for_call_step.rb +30 -0
- data/lib/trace_viz/collectors/steps/assign_depth_for_return_step.rb +39 -0
- data/lib/trace_viz/collectors/steps/base_step.rb +27 -0
- data/lib/trace_viz/collectors/steps/build_hierarchy_step.rb +32 -0
- data/lib/trace_viz/collectors/{evaluators/hidden_evaluator.rb → steps/hidden_step.rb} +9 -5
- data/lib/trace_viz/collectors/steps/linking_step.rb +36 -0
- data/lib/trace_viz/collectors/{evaluators/filter_evaluator.rb → steps/validation_step.rb} +9 -6
- data/lib/trace_viz/collectors/steps.rb +10 -0
- data/lib/trace_viz/collectors/trace_pipeline.rb +26 -0
- data/lib/trace_viz/collectors/trace_pipeline_builder.rb +29 -0
- data/lib/trace_viz/collectors/trace_point_collector.rb +1 -11
- data/lib/trace_viz/config/validator.rb +6 -5
- data/lib/trace_viz/configuration.rb +3 -3
- data/lib/trace_viz/context/tracking_context.rb +4 -0
- data/lib/trace_viz/core/tracer.rb +2 -0
- data/lib/trace_viz/defaults/actions.rb +84 -0
- data/lib/trace_viz/defaults/colors.rb +61 -0
- data/lib/trace_viz/defaults/config.rb +89 -0
- data/lib/trace_viz/defaults/themes.rb +66 -0
- data/lib/trace_viz/defaults.rb +10 -129
- data/lib/trace_viz/exporters/base_exporter.rb +8 -11
- data/lib/trace_viz/exporters/export_manager.rb +33 -0
- data/lib/trace_viz/exporters/registry.rb +25 -0
- data/lib/trace_viz/exporters/text_exporter.rb +22 -0
- data/lib/trace_viz/formatters/base_formatter.rb +3 -30
- data/lib/trace_viz/formatters/export/base_formatter.rb +12 -0
- data/lib/trace_viz/formatters/export/formatter_factory.rb +27 -0
- data/lib/trace_viz/formatters/export/method_call_formatter.rb +21 -0
- data/lib/trace_viz/formatters/export/method_return_formatter.rb +22 -0
- data/lib/trace_viz/formatters/export/summary_group_formatter.rb +35 -0
- data/lib/trace_viz/formatters/helpers/depth_helper.rb +2 -8
- data/lib/trace_viz/formatters/helpers/indent_helper.rb +1 -1
- data/lib/trace_viz/formatters/helpers/log/color_helper.rb +23 -0
- data/lib/trace_viz/formatters/helpers/log/depth_helper.rb +22 -0
- data/lib/trace_viz/formatters/helpers/log/method_name_helper.rb +29 -0
- data/lib/trace_viz/formatters/helpers/log/params_helper.rb +51 -0
- data/lib/trace_viz/formatters/helpers/log/result_helper.rb +27 -0
- data/lib/trace_viz/formatters/helpers/log/summary/params_helper.rb +53 -0
- data/lib/trace_viz/formatters/helpers/method_details_helper.rb +1 -1
- data/lib/trace_viz/formatters/helpers/params_helper.rb +26 -9
- data/lib/trace_viz/formatters/helpers/result_helper.rb +1 -1
- data/lib/trace_viz/formatters/helpers/source_helper.rb +2 -1
- data/lib/trace_viz/formatters/helpers/summary/params_helper.rb +41 -0
- data/lib/trace_viz/formatters/helpers/summary/source_helper.rb +24 -0
- data/lib/trace_viz/formatters/helpers/time_helper.rb +2 -2
- data/lib/trace_viz/formatters/helpers.rb +10 -0
- data/lib/trace_viz/formatters/log/base_formatter.rb +13 -0
- data/lib/trace_viz/formatters/log/formatter_factory.rb +27 -0
- data/lib/trace_viz/formatters/log/method_call_formatter.rb +34 -0
- data/lib/trace_viz/formatters/log/method_return_formatter.rb +24 -0
- data/lib/trace_viz/formatters/log/summary_group_formatter.rb +40 -0
- data/lib/trace_viz/formatters/log/verbose_formatter.rb +14 -0
- data/lib/trace_viz/formatters/trace_data_formatter.rb +24 -0
- data/lib/trace_viz/helpers/config_helper.rb +13 -0
- data/lib/trace_viz/helpers/trace_point/param_helper.rb +98 -0
- data/lib/trace_viz/helpers/tracking_helper.rb +26 -0
- data/lib/trace_viz/helpers.rb +9 -0
- data/lib/trace_viz/logger.rb +9 -20
- data/lib/trace_viz/loggers/base_logger.rb +29 -0
- data/lib/trace_viz/loggers/log_level_resolver.rb +18 -0
- data/lib/trace_viz/loggers/logging_manager.rb +46 -0
- data/lib/trace_viz/loggers/post_collection_logger.rb +39 -0
- data/lib/trace_viz/loggers/trace_logger.rb +17 -18
- data/lib/trace_viz/loggers/trace_stats_logger.rb +28 -14
- data/lib/trace_viz/renderers/base_renderer.rb +24 -0
- data/lib/trace_viz/renderers/render_context.rb +18 -0
- data/lib/trace_viz/renderers/renderer_factory.rb +41 -0
- data/lib/trace_viz/renderers/summary/node_processor.rb +82 -0
- data/lib/trace_viz/renderers/summary_renderer.rb +22 -0
- data/lib/trace_viz/renderers/verbose_renderer.rb +29 -0
- data/lib/trace_viz/shared/renderer_helper.rb +46 -0
- data/lib/trace_viz/shared.rb +8 -0
- data/lib/trace_viz/trace_data/base.rb +16 -23
- data/lib/trace_viz/trace_data/node.rb +33 -0
- data/lib/trace_viz/trace_data/root_node.rb +20 -0
- data/lib/trace_viz/trace_data/summary_node.rb +49 -0
- data/lib/trace_viz/trace_data/trace_point/base.rb +22 -31
- data/lib/trace_viz/trace_data/trace_point/method_call.rb +22 -17
- data/lib/trace_viz/trace_data/trace_point/method_return.rb +21 -1
- data/lib/trace_viz/traits/depth_trackable.rb +13 -0
- data/lib/trace_viz/traits/identifiable.rb +25 -0
- data/lib/trace_viz/traits/time_trackable.rb +13 -0
- data/lib/trace_viz/traits.rb +10 -0
- data/lib/trace_viz/utils/colorize.rb +6 -6
- data/lib/trace_viz/utils/format_utils/key_value_formatter.rb +37 -0
- data/lib/trace_viz/utils/format_utils/value_truncator.rb +74 -0
- data/lib/trace_viz/utils/format_utils.rb +10 -53
- data/lib/trace_viz/utils/id_generator.rb +35 -0
- data/lib/trace_viz/version.rb +1 -1
- data/sig/adapters/base_adapter.rbs +11 -0
- data/sig/adapters/trace_point_adapter.rbs +13 -0
- data/sig/collectors/filters/registry.rbs +13 -0
- data/sig/collectors/trace_point_collector.rbs +17 -0
- data/sig/config/copier.rbs +15 -0
- data/sig/config/validator.rbs +18 -0
- data/sig/configuration.rbs +22 -0
- data/sig/context/base_context.rbs +9 -0
- data/sig/context/config_context.rbs +13 -0
- data/sig/context/manager.rbs +10 -0
- data/sig/context/map.rbs +13 -0
- data/sig/context.rbs +5 -0
- data/sig/core/tracer.rbs +7 -0
- data/sig/core.rbs +4 -0
- data/sig/defaults.rbs +17 -0
- data/sig/errors.rbs +13 -0
- data/sig/logger.rbs +33 -0
- data/sig/trace_viz.rbs +1 -2
- data/sig/utils/colorize.rbs +8 -0
- data/sig/utils/format_utils/key_value_formatter.rbs +16 -0
- data/sig/utils/format_utils/value_truncator.rbs +19 -0
- data/sig/utils/format_utils.rbs +8 -0
- data/sig/version.rbs +3 -0
- metadata +97 -18
- data/lib/trace_viz/collectors/depth_manager.rb +0 -37
- data/lib/trace_viz/collectors/evaluators/base_evaluator.rb +0 -23
- data/lib/trace_viz/exporters/formatters/base_formatter.rb +0 -12
- data/lib/trace_viz/exporters/formatters/method_call_formatter.rb +0 -21
- data/lib/trace_viz/exporters/formatters/method_return_formatter.rb +0 -22
- data/lib/trace_viz/exporters/transformers/base_transformer.rb +0 -25
- data/lib/trace_viz/exporters/transformers/text_transformer.rb +0 -28
- data/lib/trace_viz/loggers/trace_builder.rb +0 -30
- data/lib/trace_viz/loggers/trace_formatters/base_formatter.rb +0 -32
- data/lib/trace_viz/loggers/trace_formatters/method_call_formatter.rb +0 -21
- data/lib/trace_viz/loggers/trace_formatters/method_return_formatter.rb +0 -22
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "trace_viz/utils/format_utils"
|
4
|
+
|
5
|
+
module TraceViz
|
6
|
+
module Formatters
|
7
|
+
module Helpers
|
8
|
+
module Log
|
9
|
+
module Summary
|
10
|
+
module ParamsHelper
|
11
|
+
def format_params_template(trace_data, config)
|
12
|
+
return unless config.params[:show]
|
13
|
+
|
14
|
+
params = prepare_params(trace_data.params, config)
|
15
|
+
wrap_params(params, config)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def prepare_params(params, config)
|
21
|
+
params
|
22
|
+
.then { |p| truncate_values(p, config.params[:truncate_values]) }
|
23
|
+
.then { |p| colorize_keys_and_values(p) }
|
24
|
+
.then { |p| format_as_string(p, config.params[:mode]) }
|
25
|
+
end
|
26
|
+
|
27
|
+
def truncate_values(params, length)
|
28
|
+
return params unless length
|
29
|
+
|
30
|
+
params.transform_values { |value| Utils::FormatUtils.truncate_value(value, length) }
|
31
|
+
end
|
32
|
+
|
33
|
+
def colorize_keys_and_values(params)
|
34
|
+
params.transform_keys { |key| colorize_for(key.to_s, :trace_params_key) }
|
35
|
+
.transform_values { |value| colorize("<#{value.class}>", :yellow) }
|
36
|
+
end
|
37
|
+
|
38
|
+
def format_as_string(params, mode)
|
39
|
+
Utils::FormatUtils.format_key_value_pairs(params, mode)
|
40
|
+
end
|
41
|
+
|
42
|
+
def wrap_params(params_string, config)
|
43
|
+
return unless params_string
|
44
|
+
|
45
|
+
truncated = Utils::FormatUtils.truncate_value(params_string, config.params[:truncate_length])
|
46
|
+
"(#{truncated})"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -6,19 +6,36 @@ module TraceViz
|
|
6
6
|
module Formatters
|
7
7
|
module Helpers
|
8
8
|
module ParamsHelper
|
9
|
-
def params_representation
|
9
|
+
def params_representation(trace_data)
|
10
10
|
return unless config.params[:show]
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
params = process_params(trace_data.params, config)
|
13
|
+
wrap_params_string(params, config)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def process_params(params, config)
|
19
|
+
params
|
20
|
+
.then { |p| truncate_param_values(p, config.params[:truncate_values]) }
|
21
|
+
.then { |p| stringify_params(p, config.params[:mode]) }
|
22
|
+
end
|
23
|
+
|
24
|
+
def truncate_param_values(params, max_length)
|
25
|
+
return params unless max_length
|
26
|
+
|
27
|
+
params.transform_values { |value| Utils::FormatUtils.truncate_value(value, max_length) }
|
28
|
+
end
|
29
|
+
|
30
|
+
def stringify_params(params, mode)
|
31
|
+
Utils::FormatUtils.format_key_value_pairs(params, mode)
|
32
|
+
end
|
15
33
|
|
16
|
-
|
17
|
-
|
18
|
-
config.params[:mode],
|
19
|
-
)
|
34
|
+
def wrap_params_string(params_string, config)
|
35
|
+
return unless params_string
|
20
36
|
|
21
|
-
|
37
|
+
truncated_string = Utils::FormatUtils.truncate_value(params_string, config.params[:truncate_length])
|
38
|
+
"(#{truncated_string})"
|
22
39
|
end
|
23
40
|
end
|
24
41
|
end
|
@@ -6,12 +6,13 @@ module TraceViz
|
|
6
6
|
module Formatters
|
7
7
|
module Helpers
|
8
8
|
module SourceHelper
|
9
|
-
def source_location_representation
|
9
|
+
def source_location_representation(trace_data)
|
10
10
|
return unless config.source_location[:show]
|
11
11
|
|
12
12
|
truncated_path = Utils::FormatUtils.truncate_value(
|
13
13
|
trace_data.path,
|
14
14
|
config.source_location[:truncate_length],
|
15
|
+
direction: :start,
|
15
16
|
)
|
16
17
|
"at #{truncated_path}:#{trace_data.line_number}"
|
17
18
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "trace_viz/utils/format_utils"
|
4
|
+
|
5
|
+
module TraceViz
|
6
|
+
module Formatters
|
7
|
+
module Helpers
|
8
|
+
module Summary
|
9
|
+
module ParamsHelper
|
10
|
+
def format_params_template(trace_data, config)
|
11
|
+
return unless config.params[:show]
|
12
|
+
|
13
|
+
params_template = build_params_template(trace_data.params, config)
|
14
|
+
wrap_params_template(params_template, config)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def build_params_template(params, config)
|
20
|
+
params.transform_values do |value|
|
21
|
+
"<#{value.class}>"
|
22
|
+
end.then do |formatted_params|
|
23
|
+
format_as_string(formatted_params, config.params[:mode])
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def format_as_string(params, mode)
|
28
|
+
Utils::FormatUtils.format_key_value_pairs(params, mode)
|
29
|
+
end
|
30
|
+
|
31
|
+
def wrap_params_template(params_string, config)
|
32
|
+
return unless params_string
|
33
|
+
|
34
|
+
truncated = Utils::FormatUtils.truncate_value(params_string, config.params[:truncate_length])
|
35
|
+
"(#{truncated})"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "trace_viz/utils/format_utils"
|
4
|
+
|
5
|
+
module TraceViz
|
6
|
+
module Formatters
|
7
|
+
module Helpers
|
8
|
+
module Summary
|
9
|
+
module SourceHelper
|
10
|
+
def source_location_representation(trace_data)
|
11
|
+
return unless config.source_location[:show]
|
12
|
+
|
13
|
+
truncated_path = Utils::FormatUtils.truncate_value(
|
14
|
+
trace_data.path,
|
15
|
+
config.source_location[:truncate_length],
|
16
|
+
direction: :start,
|
17
|
+
)
|
18
|
+
"at #{truncated_path}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -4,10 +4,10 @@ module TraceViz
|
|
4
4
|
module Formatters
|
5
5
|
module Helpers
|
6
6
|
module TimeHelper
|
7
|
-
def execution_time_representation
|
7
|
+
def execution_time_representation(trace_data)
|
8
8
|
return unless config.execution[:show_time] && trace_data.duration
|
9
9
|
|
10
|
-
"in
|
10
|
+
format("in %.6fms", trace_data.duration)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "method_call_formatter"
|
4
|
+
require_relative "method_return_formatter"
|
5
|
+
require_relative "summary_group_formatter"
|
6
|
+
|
7
|
+
module TraceViz
|
8
|
+
module Formatters
|
9
|
+
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
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "verbose_formatter"
|
4
|
+
|
5
|
+
module TraceViz
|
6
|
+
module Formatters
|
7
|
+
module Log
|
8
|
+
class MethodCallFormatter < VerboseFormatter
|
9
|
+
include Helpers::Log::ParamsHelper
|
10
|
+
include Helpers::Log::ResultHelper
|
11
|
+
|
12
|
+
def call(trace_data)
|
13
|
+
[
|
14
|
+
indent_representation(trace_data),
|
15
|
+
format_depth(trace_data, config),
|
16
|
+
format_method_name(trace_data, config),
|
17
|
+
colorize_for(source_location_representation(trace_data), :trace_source_location),
|
18
|
+
format_params(trace_data, config),
|
19
|
+
format_result(trace_data, config),
|
20
|
+
colorize_for(execution_time_representation(trace_data), :trace_execution_time),
|
21
|
+
].compact.join(" ")
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def format_result(trace_data, config)
|
27
|
+
return unless trace_data.method_return
|
28
|
+
|
29
|
+
super(trace_data.method_return, config)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "verbose_formatter"
|
4
|
+
|
5
|
+
module TraceViz
|
6
|
+
module Formatters
|
7
|
+
module Log
|
8
|
+
class MethodReturnFormatter < VerboseFormatter
|
9
|
+
include Helpers::Log::ResultHelper
|
10
|
+
|
11
|
+
def call(trace_data)
|
12
|
+
[
|
13
|
+
indent_representation(trace_data),
|
14
|
+
format_depth(trace_data, config),
|
15
|
+
format_method_name(trace_data, config),
|
16
|
+
format_result(trace_data, config),
|
17
|
+
colorize_for(source_location_representation(trace_data), :trace_source_location),
|
18
|
+
colorize_for(execution_time_representation(trace_data), :trace_execution_time),
|
19
|
+
].compact.join(" ")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "base_formatter"
|
4
|
+
|
5
|
+
module TraceViz
|
6
|
+
module Formatters
|
7
|
+
module Log
|
8
|
+
class SummaryGroupFormatter < BaseFormatter
|
9
|
+
include Helpers::Log::DepthHelper
|
10
|
+
include Helpers::Log::MethodNameHelper
|
11
|
+
include Helpers::Log::Summary::ParamsHelper
|
12
|
+
|
13
|
+
def call(trace_data)
|
14
|
+
[
|
15
|
+
indent_representation(trace_data),
|
16
|
+
format_depth(trace_data, config),
|
17
|
+
Defaults::Actions.emoji_for(:processing),
|
18
|
+
format_method_name(trace_data, config),
|
19
|
+
format_params_template(trace_data, config),
|
20
|
+
summary_info(trace_data),
|
21
|
+
].compact.join(" ")
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def summary_info(trace_data)
|
27
|
+
colorize(
|
28
|
+
"[Summary: #{trace_data.count} calls | Avg Time: #{format(
|
29
|
+
"in %.6fms",
|
30
|
+
trace_data.average_duration,
|
31
|
+
)}]",
|
32
|
+
:bold,
|
33
|
+
:italic,
|
34
|
+
:yellow,
|
35
|
+
)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "base_formatter"
|
4
|
+
|
5
|
+
module TraceViz
|
6
|
+
module Formatters
|
7
|
+
module Log
|
8
|
+
class VerboseFormatter < BaseFormatter
|
9
|
+
include Helpers::Log::DepthHelper
|
10
|
+
include Helpers::Log::MethodNameHelper
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "base_formatter"
|
4
|
+
require_relative "helpers"
|
5
|
+
|
6
|
+
module TraceViz
|
7
|
+
module Formatters
|
8
|
+
class TraceDataFormatter < BaseFormatter
|
9
|
+
#
|
10
|
+
# General formatting methods for TraceData::Base
|
11
|
+
# These methods are used to format the output of the trace data
|
12
|
+
# based on the configuration settings.
|
13
|
+
#
|
14
|
+
|
15
|
+
include Helpers::IndentHelper
|
16
|
+
include Helpers::DepthHelper
|
17
|
+
include Helpers::TimeHelper
|
18
|
+
include Helpers::ParamsHelper
|
19
|
+
include Helpers::SourceHelper
|
20
|
+
include Helpers::ResultHelper
|
21
|
+
include Helpers::MethodDetailsHelper
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TraceViz
|
4
|
+
module Helpers
|
5
|
+
module TracePoint
|
6
|
+
module ParamHelper
|
7
|
+
IGNORED_VARIABLES = [
|
8
|
+
"__ENCODING__", "__LINE__", "__FILE__",
|
9
|
+
].freeze
|
10
|
+
|
11
|
+
IGNORED_METHODS = [
|
12
|
+
"initialize",
|
13
|
+
"inspect",
|
14
|
+
"object_id",
|
15
|
+
"to_s",
|
16
|
+
"class",
|
17
|
+
"method",
|
18
|
+
"instance_variable_get",
|
19
|
+
"instance_variable_set",
|
20
|
+
"instance_variables",
|
21
|
+
"public_methods",
|
22
|
+
"private_methods",
|
23
|
+
"protected_methods",
|
24
|
+
"respond_to?",
|
25
|
+
"send",
|
26
|
+
].freeze
|
27
|
+
|
28
|
+
def extract_params(binding, method_name)
|
29
|
+
method = fetch_method_via_instance_method(binding, method_name)
|
30
|
+
return {} unless method
|
31
|
+
|
32
|
+
extract_parameters_from_signature(method.parameters, binding)
|
33
|
+
end
|
34
|
+
|
35
|
+
def fetch_method_via_instance_method(binding, method_name)
|
36
|
+
klass_instance = safe_eval(binding, "self")
|
37
|
+
return unless klass_instance
|
38
|
+
|
39
|
+
klass = klass_instance.class
|
40
|
+
klass.instance_method(method_name)
|
41
|
+
rescue StandardError
|
42
|
+
# TraceViz.logger.error("Failed to fetch method #{method_name}: #{e.message}")
|
43
|
+
nil
|
44
|
+
end
|
45
|
+
|
46
|
+
def extract_parameters_from_signature(parameters, binding)
|
47
|
+
parameters.each_with_object({}) do |(_, name), hash|
|
48
|
+
next unless name
|
49
|
+
next if should_ignore_parameter?(name)
|
50
|
+
|
51
|
+
hash[name] = safe_local_variable_get(binding, name)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def safe_local_variable_get(binding, name)
|
56
|
+
binding.local_variable_get(name)
|
57
|
+
rescue NameError
|
58
|
+
# class_name = safe_eval(binding, "self.class") || "unknown class"
|
59
|
+
# TraceViz.logger.error("Failed to get local variable '#{name}' in #{class_name}: #{e.message}")
|
60
|
+
nil
|
61
|
+
end
|
62
|
+
|
63
|
+
def safe_eval(binding, expression)
|
64
|
+
binding.eval(expression)
|
65
|
+
rescue StandardError => e
|
66
|
+
TraceViz.logger.error("Failed to eval expression #{expression}: #{e.message}")
|
67
|
+
nil
|
68
|
+
end
|
69
|
+
|
70
|
+
def should_ignore_parameter?(parameter_name)
|
71
|
+
parameter_name_str = parameter_name.to_s
|
72
|
+
return true if should_ignore_variable?(parameter_name_str)
|
73
|
+
return true if should_ignore_method?(parameter_name_str)
|
74
|
+
return true if splat_parameter?(parameter_name_str)
|
75
|
+
return true if placeholder_parameter?(parameter_name_str)
|
76
|
+
|
77
|
+
false
|
78
|
+
end
|
79
|
+
|
80
|
+
def should_ignore_variable?(variable_name_str)
|
81
|
+
IGNORED_VARIABLES.include?(variable_name_str)
|
82
|
+
end
|
83
|
+
|
84
|
+
def should_ignore_method?(method_name_str)
|
85
|
+
IGNORED_METHODS.include?(method_name_str)
|
86
|
+
end
|
87
|
+
|
88
|
+
def splat_parameter?(parameter_name_str)
|
89
|
+
parameter_name_str.include?("*")
|
90
|
+
end
|
91
|
+
|
92
|
+
def placeholder_parameter?(parameter_name_str)
|
93
|
+
parameter_name_str.start_with?("_")
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "trace_viz/context"
|
4
|
+
|
5
|
+
module TraceViz
|
6
|
+
module Helpers
|
7
|
+
module TrackingHelper
|
8
|
+
def tracker
|
9
|
+
Context.for(:tracking)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Helper methods to access tracker attributes
|
13
|
+
def active_call_stack
|
14
|
+
tracker.active_calls
|
15
|
+
end
|
16
|
+
|
17
|
+
def current_call
|
18
|
+
tracker.current_call
|
19
|
+
end
|
20
|
+
|
21
|
+
def current_depth
|
22
|
+
tracker.current_depth
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/trace_viz/logger.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "trace_viz/utils/colorize"
|
4
|
+
|
3
5
|
module TraceViz
|
4
6
|
class Logger
|
5
|
-
LEVELS = Defaults.
|
7
|
+
LEVELS = Defaults::Actions.keys.freeze
|
6
8
|
|
7
9
|
def initialize(output: $stdout)
|
8
10
|
@output = output
|
@@ -18,11 +20,11 @@ module TraceViz
|
|
18
20
|
validate_message!(message)
|
19
21
|
validate_level!(level)
|
20
22
|
|
21
|
-
|
22
|
-
emoji = emoji_for(level)
|
23
|
+
colors = Defaults::Actions.colors_for(level)
|
24
|
+
emoji = Defaults::Actions.emoji_for(level)
|
23
25
|
|
24
26
|
raw_message = build_message(message, level, emoji)
|
25
|
-
formatted_message =
|
27
|
+
formatted_message = apply_colors(raw_message, colors)
|
26
28
|
|
27
29
|
@output.puts(formatted_message)
|
28
30
|
end
|
@@ -37,27 +39,14 @@ module TraceViz
|
|
37
39
|
raise ArgumentError, "Invalid log level: #{level}" unless LEVELS.include?(level)
|
38
40
|
end
|
39
41
|
|
40
|
-
def color_for(level)
|
41
|
-
color_key = Defaults.action_colors.fetch(level)
|
42
|
-
Defaults.colors.fetch(color_key)
|
43
|
-
end
|
44
|
-
|
45
|
-
def default_color
|
46
|
-
color_for(:default)
|
47
|
-
end
|
48
|
-
|
49
|
-
def emoji_for(level)
|
50
|
-
Defaults.action_emojis.fetch(level, "")
|
51
|
-
end
|
52
|
-
|
53
42
|
def build_message(message, level, emoji)
|
54
43
|
level_str = level == :default ? "" : "[#{level.to_s.upcase}]"
|
55
44
|
merged_emoji_level = "#{emoji} #{level_str}".strip
|
56
|
-
format("
|
45
|
+
format("%s%s", merged_emoji_level, message)
|
57
46
|
end
|
58
47
|
|
59
|
-
def
|
60
|
-
|
48
|
+
def apply_colors(message, colors)
|
49
|
+
Utils::Colorize.colorize(message, *colors)
|
61
50
|
end
|
62
51
|
end
|
63
52
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TraceViz
|
4
|
+
module Loggers
|
5
|
+
class BaseLogger
|
6
|
+
def initialize
|
7
|
+
@logger = TraceViz.logger
|
8
|
+
end
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def log(*args)
|
12
|
+
new(*args).log
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def log
|
17
|
+
raise NotImplementedError
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
attr_reader :logger
|
23
|
+
|
24
|
+
def log_message(level, message)
|
25
|
+
logger.send(level, message)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TraceViz
|
4
|
+
module Loggers
|
5
|
+
class LogLevelResolver
|
6
|
+
LOG_LEVELS = {
|
7
|
+
call: :start,
|
8
|
+
return: :finish,
|
9
|
+
}.freeze
|
10
|
+
|
11
|
+
class << self
|
12
|
+
def resolve(trace_data)
|
13
|
+
LOG_LEVELS[trace_data.event] || :info
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|