Class: Codebeacon::Tracer::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/codebeacon/tracer/src/configuration.rb

Constant Summary collapse

MAX_DB_FILES =
100
RETURN_VAL_MAX_LENGTH =
1000
MAX_CALL_COUNT =
100000000
MAX_DEPTH =
99999
SERIALIZATION_TIMEOUT_MS =
10

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



19
20
21
22
23
# File 'lib/codebeacon/tracer/src/configuration.rb', line 19

def initialize()
  @query = ""
  @exclude_paths = []
  ensure_db_path
end

Instance Method Details

#config_pathObject



92
93
94
# File 'lib/codebeacon/tracer/src/configuration.rb', line 92

def config_path
  File.expand_path(File.join(lib_root, 'config.yml')) 
end

#data_dirObject



72
73
74
# File 'lib/codebeacon/tracer/src/configuration.rb', line 72

def data_dir
  File.join(root_path, ".code-beacon")
end

#db_nameObject



106
107
108
# File 'lib/codebeacon/tracer/src/configuration.rb', line 106

def db_name
  "codebeacon_tracer"
end

#db_pathObject



76
77
78
# File 'lib/codebeacon/tracer/src/configuration.rb', line 76

def db_path
 File.join(data_dir, "db")
end

#debug=(value) ⇒ Object



192
193
194
195
# File 'lib/codebeacon/tracer/src/configuration.rb', line 192

def debug=(value)
  Codebeacon::Tracer.logger.level = value ? ::Logger::DEBUG : ::Logger::INFO
  @debug = value
end

#debug?Boolean

Returns:

  • (Boolean)


188
189
190
# File 'lib/codebeacon/tracer/src/configuration.rb', line 188

def debug?
  @debug
end

#debug_somethingObject



247
248
249
250
251
252
# File 'lib/codebeacon/tracer/src/configuration.rb', line 247

def debug_something
  #### debug return
  # @return_count += 1
  # Codebeacon::Tracer.logger.info("Call count: #{@return_count}")
  # Codebeacon::Tracer.logger.info("Return @depth: #{@depth}, method: #{tp.method_id}, line: #{tp.lineno}, path: #{tp.path}")
end

#dry_run=(value) ⇒ Object



201
202
203
# File 'lib/codebeacon/tracer/src/configuration.rb', line 201

def dry_run=(value)
  @dry_run = value
end

#dry_run?Boolean

Returns:

  • (Boolean)


197
198
199
# File 'lib/codebeacon/tracer/src/configuration.rb', line 197

def dry_run?
  @dry_run
end

#ensure_db_pathObject



58
59
60
# File 'lib/codebeacon/tracer/src/configuration.rb', line 58

def ensure_db_path
  FileUtils.mkpath(db_path)
end

#exclude_paths(*paths) ⇒ Object



135
136
137
# File 'lib/codebeacon/tracer/src/configuration.rb', line 135

def exclude_paths(*paths)
  @exclude_paths += paths
end

#gem_pathObject



114
115
116
# File 'lib/codebeacon/tracer/src/configuration.rb', line 114

def gem_path
  @gem_path ||= ENV['GEM_HOME'] || Gem.paths.home
end

#lib_rootObject

def load_ruby_flow_config

if File.exist?('.code-beacon.yml')
  @config = YAML.load_file('.code-beacon.yml')
end

end



68
69
70
# File 'lib/codebeacon/tracer/src/configuration.rb', line 68

def lib_root
  File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..'))
end

#load_exclude_paths(excludes) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/codebeacon/tracer/src/configuration.rb', line 39

def load_exclude_paths(excludes)
  return if excludes.nil?
  (excludes['paths'] || []).each { |path| exclude_paths << path }
  (excludes['gems'] || []).each do |gem_name|
    Gem::Specification.find_all_by_name(gem_name).each do |gem_spec|
      exclude_paths << gem_spec.gem_dir
    end
  end
end

#load_main_configObject



32
33
34
35
36
37
# File 'lib/codebeacon/tracer/src/configuration.rb', line 32

def load_main_config
  if File.exist?(config_path)
    config_data = YAML.load_file(config_path)
    load_exclude_paths(config_data['exclude'])
  end
end

#local_lines_only=(value) ⇒ Object



219
220
221
# File 'lib/codebeacon/tracer/src/configuration.rb', line 219

def local_lines_only=(value)
  @local_lines_only = value
end

#local_lines_only?Boolean

Returns:

  • (Boolean)


214
215
216
217
# File 'lib/codebeacon/tracer/src/configuration.rb', line 214

def local_lines_only?
  # @local_lines_only
  true
end

#local_methods_only=(value) ⇒ Object



210
211
212
# File 'lib/codebeacon/tracer/src/configuration.rb', line 210

def local_methods_only=(value)
  @local_methods_only = value
end

#local_methods_only?Boolean

Returns:

  • (Boolean)


205
206
207
208
# File 'lib/codebeacon/tracer/src/configuration.rb', line 205

def local_methods_only?
  # @local_methods_only
  true
end

#loggerObject



243
244
245
# File 'lib/codebeacon/tracer/src/configuration.rb', line 243

def logger
  @logger ||= Codebeacon::Tracer::Logger.new()
end

#max_call_countObject



231
232
233
# File 'lib/codebeacon/tracer/src/configuration.rb', line 231

def max_call_count
  MAX_CALL_COUNT
end

#max_db_filesObject



110
111
112
# File 'lib/codebeacon/tracer/src/configuration.rb', line 110

def max_db_files
  MAX_DB_FILES
end

#max_depthObject



235
236
237
# File 'lib/codebeacon/tracer/src/configuration.rb', line 235

def max_depth
  MAX_DEPTH
end

#max_value_lengthObject



227
228
229
# File 'lib/codebeacon/tracer/src/configuration.rb', line 227

def max_value_length
  RETURN_VAL_MAX_LENGTH
end

#paths_pathObject



88
89
90
# File 'lib/codebeacon/tracer/src/configuration.rb', line 88

def paths_path
  File.join(data_dir, "paths.yml")
end

#paths_to_recordObject



126
127
128
# File 'lib/codebeacon/tracer/src/configuration.rb', line 126

def paths_to_record
  @paths_to_record ||= [Codebeacon::Tracer.config.root_path, *Codebeacon::Tracer.config.read_paths]
end

#read_pathsObject



100
101
102
103
104
# File 'lib/codebeacon/tracer/src/configuration.rb', line 100

def read_paths
  if File.exist?(paths_path)
    YAML.load_file(paths_path)
  end
end

#recording_meta_exclude_patternsObject



158
159
160
161
162
163
164
# File 'lib/codebeacon/tracer/src/configuration.rb', line 158

def recording_meta_exclude_patterns
  if @donotcache
    load_recording_meta_exclude_patterns
  else
    @recording_meta_exclude_patterns ||= load_recording_meta_exclude_patterns
  end
end

#refresh_pathObject



84
85
86
# File 'lib/codebeacon/tracer/src/configuration.rb', line 84

def refresh_path
  File.join(data_dir, "tmp", "refresh")
end

#reload_main_configObject



153
154
155
156
# File 'lib/codebeacon/tracer/src/configuration.rb', line 153

def reload_main_config
  @root_path = nil  # Force reload of root_path
  load_main_config
end

#reload_paths_to_recordObject



130
131
132
133
# File 'lib/codebeacon/tracer/src/configuration.rb', line 130

def reload_paths_to_record
  @paths_to_record = nil
  paths_to_record
end

#reload_tracer_configObject



147
148
149
150
151
# File 'lib/codebeacon/tracer/src/configuration.rb', line 147

def reload_tracer_config
  @trace_enabled = load_tracer_config_enabled
  @config_root_path = load_tracer_config_root_path
  @recording_meta_exclude_patterns = nil  # Force reload of exclusion patterns
end

#root_pathObject



118
119
120
# File 'lib/codebeacon/tracer/src/configuration.rb', line 118

def root_path
  @root_path ||= @config_root_path || (defined?(Rails) ? Rails.root.to_s : Dir.pwd)
end

#rubylib_pathObject



122
123
124
# File 'lib/codebeacon/tracer/src/configuration.rb', line 122

def rubylib_path
  @rubylib_path ||= RbConfig::CONFIG['rubylibdir']
end

#serialization_timeout_msObject



239
240
241
# File 'lib/codebeacon/tracer/src/configuration.rb', line 239

def serialization_timeout_ms
  SERIALIZATION_TIMEOUT_MS
end

#set_query_config(query) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/codebeacon/tracer/src/configuration.rb', line 49

def set_query_config(query)
  @query = query || ""
  # self.trace_enabled = @query.include?('rf__trace_enabled=true')
  self.debug = @query.include?('rf__debug=true')
  self.dry_run = @query.include?('rf__dry_run=true')
  # self.local_methods_only = @query.include?('rf__local_methods_only=true')
  # self.local_lines_only = @query.include?('rf__local_lines_only=true')
end

#setupObject



25
26
27
28
29
30
# File 'lib/codebeacon/tracer/src/configuration.rb', line 25

def setup
  exclude_paths << lib_root
  reload_paths_to_record
  load_main_config
  start_config_file_watcher
end

#skip_internal?Boolean

Returns:

  • (Boolean)


223
224
225
# File 'lib/codebeacon/tracer/src/configuration.rb', line 223

def skip_internal?
  true
end

#skip_tracing?(name, description) ⇒ Boolean

Returns:

  • (Boolean)


166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/codebeacon/tracer/src/configuration.rb', line 166

def skip_tracing?(name, description)
  return false unless recording_meta_exclude_patterns&.any?
  
  name_str = name.to_s
  description_str = description.to_s
  
  excluded = recording_meta_exclude_patterns.any? do |pattern|
    name_matches = File.fnmatch(pattern['name'], name_str, File::FNM_CASEFOLD)
    description_matches = File.fnmatch(pattern['description'], description_str, File::FNM_CASEFOLD)
    name_matches && description_matches
  end
  
  if excluded && debug?
    logger.debug("Skipping trace due to metadata exclusion - name: '#{name_str}', description: '#{description_str}'")
  end
  
  excluded
rescue => e
  logger.warn("Error checking skip_tracing patterns: #{e.message}")
  false  # Default to not skipping on error
end

#start_config_file_watcherObject



254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/codebeacon/tracer/src/configuration.rb', line 254

def start_config_file_watcher
  return unless defined?(Listen) && !@config_listener
  return unless File.directory?(data_dir)
  
  begin
    @config_listener = Listen.to(data_dir, only: /tracer_config\.yml$/) do |modified, added, removed|
      if (modified + added + removed).any? { |path| File.basename(path) == 'tracer_config.yml' }
        reload_tracer_config
      end
    end
    @config_listener.start
  rescue => e
    @donotcache = true
    logger.warn("Failed to start config file watcher: #{e.message}")
  end
end

#stop_config_file_watcherObject



271
272
273
274
275
276
# File 'lib/codebeacon/tracer/src/configuration.rb', line 271

def stop_config_file_watcher
  if @config_listener
    @config_listener.stop
    @config_listener = nil
  end
end

#tmp_dirObject



80
81
82
# File 'lib/codebeacon/tracer/src/configuration.rb', line 80

def tmp_dir
  File.join(data_dir, "tmp")
end

#trace_enabled?Boolean

Returns:

  • (Boolean)


139
140
141
142
143
144
145
# File 'lib/codebeacon/tracer/src/configuration.rb', line 139

def trace_enabled?
  if @donotcache
    load_tracer_config_enabled
  else
    @trace_enabled ||= load_tracer_config_enabled
  end
end

#tracer_config_pathObject



96
97
98
# File 'lib/codebeacon/tracer/src/configuration.rb', line 96

def tracer_config_path
  File.join(data_dir, "tracer_config.yml")
end