Module: Codebeacon::Tracer
- Defined in:
- lib/codebeacon-tracer.rb,
lib/codebeacon/tracer/version.rb,
lib/codebeacon/tracer/src/logger.rb,
lib/codebeacon/tracer/src/tracer.rb,
lib/codebeacon/tracer/src/configuration.rb,
lib/codebeacon/tracer/src/data/database.rb,
lib/codebeacon/tracer/src/rails/railtie.rb,
lib/codebeacon/tracer/src/models/tpklass.rb,
lib/codebeacon/tracer/src/models/call_tree.rb,
lib/codebeacon/tracer/src/models/tree_node.rb,
lib/codebeacon/tracer/src/rails/middleware.rb,
lib/codebeacon/tracer/src/data/type_detector.rb,
lib/codebeacon/tracer/src/models/node_source.rb,
lib/codebeacon/tracer/src/data/trace_metadata.rb,
lib/codebeacon/tracer/src/models/node_builder.rb,
lib/codebeacon/tracer/src/data/metadata_mapper.rb,
lib/codebeacon/tracer/src/data/safe_serializer.rb,
lib/codebeacon/tracer/src/data/tree_node_mapper.rb,
lib/codebeacon/tracer/src/data/node_source_mapper.rb,
lib/codebeacon/tracer/src/data/persistence_manager.rb,
lib/codebeacon/tracer/src/models/thread_local_call_tree_manager.rb
Overview
The Tracer module provides tools to trace and analyze the runtime performance of your Ruby applications. It captures method calls, execution times, and generates reports to help identify bottlenecks.
Defined Under Namespace
Classes: CallTree, Configuration, DatabaseSchema, Logger, MetadataMapper, Middleware, NodeBuilder, NodeSource, NodeSourceMapper, PersistenceManager, ProgressLogger, Railtie, SafeSerializer, TPKlass, ThreadLocalCallTreeManager, TraceMetadata, Tracer, TreeNode, TreeNodeMapper, TypeDetector
Constant Summary collapse
- VERSION =
"0.4.0"
Class Attribute Summary collapse
-
.tree_manager ⇒ ThreadLocalCallTreeManager
readonly
The current tree manager.
Class Method Summary collapse
-
.config ⇒ Configuration
Returns the configuration object for Codebeacon::Tracer.
-
.current_tree ⇒ CallTree
Returns the current call tree.
-
.logger ⇒ Logger
Returns the logger instance.
-
.start(name: nil, description: nil, trigger_type: "manual") ⇒ void
Starts tracing without a block.
-
.stop ⇒ void
Stops tracing and persists the results.
-
.trace(name: nil, description: nil, trigger_type: "manual") {|tracer| ... } ⇒ Object
Traces a block of code and collects runtime information.
Class Attribute Details
.tree_manager ⇒ ThreadLocalCallTreeManager (readonly)
Returns The current tree manager.
27 28 29 |
# File 'lib/codebeacon-tracer.rb', line 27 def tree_manager @tree_manager end |
Class Method Details
.config ⇒ Configuration
Returns the configuration object for Codebeacon::Tracer
31 32 33 |
# File 'lib/codebeacon-tracer.rb', line 31 def config @config ||= Configuration.new end |
.current_tree ⇒ CallTree
Returns the current call tree
37 38 39 |
# File 'lib/codebeacon-tracer.rb', line 37 def current_tree @tracer&.tree_manager&.current() end |
.logger ⇒ Logger
Returns the logger instance
43 44 45 |
# File 'lib/codebeacon-tracer.rb', line 43 def logger config.logger end |
.start(name: nil, description: nil, trigger_type: "manual") ⇒ void
This method returns an undefined value.
Starts tracing without a block
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/codebeacon-tracer.rb', line 90 def start(name: nil, description: nil, trigger_type: "manual") # Capture caller information immediately at entry point caller_location = caller_locations(1, 1).first return unless config.trace_enabled? setup @tracer = Tracer.new(name:, description:, caller_location:, trigger_type:) @tracer.start end |
.stop ⇒ void
This method returns an undefined value.
Stops tracing and persists the results
103 104 105 106 107 108 109 |
# File 'lib/codebeacon-tracer.rb', line 103 def stop return unless @tracer # checks whether trace_enabled? was false when start was called or if it was called @tracer.stop persist(@tracer.) cleanup end |
.trace(name: nil, description: nil, trigger_type: "manual") {|tracer| ... } ⇒ Object
Traces a block of code and collects runtime information
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/codebeacon-tracer.rb', line 55 def trace(name: nil, description: nil, trigger_type: "manual") # Capture caller information immediately at entry point caller_location = caller_locations(1, 1).first unless config.trace_enabled? logger.info("Tracing is disabled. Skipping trace: #{name} - #{description}") return yield(nil) end if config.skip_tracing?(name, description) logger.info("Exclusion rules matched. Skipping trace: #{name} - #{description}") return yield(nil) end begin setup @tracer = Tracer.new(name:, description:, caller_location:, trigger_type:) result = @tracer.enable_traces do yield @tracer end persist(@tracer.) cleanup result rescue => e Codebeacon::Tracer.logger.error("Error during tracing: #{e.}") Codebeacon::Tracer.logger.error(e.backtrace.join("\n")) if Codebeacon::Tracer.config.debug? # Continue execution without crashing the application yield nil if block_given? end end |