Module: ScoutApm::Tracer::ClassMethods
- Defined in:
- lib/scout_apm/tracer.rb
Instance Method Summary collapse
-
#instrument(type, name, options = {}) ⇒ Object
Type: the Layer type - “View” or similar Name: specific name - “users/_gravatar”.
-
#instrument_method(method_name, options = {}) ⇒ Object
Wraps a method in a call to #instrument via aggressive monkey patching.
Instance Method Details
#instrument(type, name, options = {}) ⇒ Object
Type: the Layer type - “View” or similar Name: specific name - “users/_gravatar”. The object must respond to “#to_s”. This allows us to be more efficient - in most cases, the metric name isn’t needed unless we are processing a slow transaction. A Block: The code to be instrumented
Options:
-
:ignore_children - will not instrument any method calls beneath this call. Example use case: InfluxDB uses Net::HTTP, which is instrumented. However, we can provide more specific data if we know we’re doing an influx call, so we’d rather just instrument the Influx call and ignore Net::HTTP. when rendering the transaction tree in the UI.
-
:desc - Additional capture, SQL, or HTTP url or similar
-
:scope - set to true if you want to make this layer a subscope
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/scout_apm/tracer.rb', line 25 def instrument(type, name, ={}) # Takes a block layer = ScoutApm::Layer.new(type, name) layer.desc = [:desc] if [:desc] layer.subscopable! if [:scope] req = ScoutApm::RequestManager.lookup req.start_layer(layer) req.ignore_children! if [:ignore_children] begin yield ensure req.acknowledge_children! if [:ignore_children] req.stop_layer end end |
#instrument_method(method_name, options = {}) ⇒ Object
Wraps a method in a call to #instrument via aggressive monkey patching.
Options: type - “View” or “ActiveRecord” and similar name - “users/show”, “App#find”
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/scout_apm/tracer.rb', line 47 def instrument_method(method_name, = {}) ScoutApm::Agent.instance.logger.info "Instrumenting #{method_name}" type = [:type] || "Custom" name = [:name] || "#{self.name}/#{method_name.to_s}" instrumented_name, uninstrumented_name = _determine_instrumented_name(method_name, type) ScoutApm::Agent.instance.logger.info "Instrumenting #{instrumented_name}, #{uninstrumented_name}" return if !_instrumentable?(method_name) or _instrumented?(instrumented_name, method_name) class_eval( _instrumented_method_string(instrumented_name, uninstrumented_name, type, name, {:scope => [:scope] }), __FILE__, __LINE__ ) alias_method uninstrumented_name, method_name alias_method method_name, instrumented_name end |