module StackifyRubyAPM
This class builds the context of the Transaction/Span Context
represents the HTTP request information such as headers, cookies, body.
This module build errors/exceptions and the Frames/stacktraces affected/related to the error
The Instrumenter
will build/process the transactions and spans.
This class will custom instrument a class and method
Starts the Monkey patch for the generated log by not including the header
@param file @removed the header of the generated log
This module converts its result to a hash.
This class will manupulate the html page d: e.g., call(env)
This will format the root information of the Transaction
.
After the spans are being build it will serialize or rebuild or reformat the spans created into json format
This module gathers the built Errors and Exceptions into hash formats
This class builds and reformats all the gathered spans within the transaction.
Monkey patch for the ActionDispatch::ShowExceptions class which handles exception events.
Monkey patch for the CurbSpy class for sending & receiving Curb responses.
Monkey patch for the CurbSpy class for sending & receiving Curb responses.
Monkey patch for the CurbSpy class for sending & receiving Curb responses.
rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity
Monkey patch for the delayed_job class for running async tasks.
Monkey patch for the Aws::DynamoDB::Client class
Monkey patch for the Faraday class
Monkey patch for the HTTPClient class for sending & receiving HTTP responses.
This class monkey patch the http.rb gem with the request method.
Monkey patch for the Log4r::Outputter class for logging log message.
Monkey patch for the Logger class for logging log messages.
Monkey patch for the Logging::Logger class for logging log messages.
Monkey patch for the Mongo::Monitoring::Global module in mongoDB(api.mongodb.com/ruby/current/Mongo/Monitoring/Global.html) -> Allows subscribing to events for all Mongo clients.
Monkey patch for the Net::HTTP class for sending & receiving HTTP responses.
Monkey patch for Redis.
This class monkey patch the sequel.rb gem with the request method.
Monkey patch for the sidekiq class for running async tasks.
Monkey patch for the Sinatra::Base class which is responsible for handling requests.
Monkeypatch for the MsgObject to set the value id for Logging / Trace Linking
Monkey patch for the sucker_punch class for running async tasks.
Monkey patch for the Tilt::Template class on template rendering and span creation.
Monkey patch for the Yell::Logger class for logging log messages.
This module starts creation for frames
This class creates and initializes a new transaction.
This class handle the selection of the Transport.
This module utilizes or handles the time usage or duration of transaction
Sets the version of the APM
Start medoule for StackifyRubyAPM
Agent
Constants
- TRANSPORT
- VERSION
Public Class Methods
@return [Agent] Currently running [Agent] if any
# File lib/stackify_ruby_apm.rb, line 89 def self.agent Agent.instance end
Build a [Context] from a Rack `env`. The context may include information about the request, response, current user and more
@param rack_env [Rack::Env] A Rack env @return [Context] The built context
# File lib/stackify_ruby_apm.rb, line 141 def self.build_context(rack_env) agent && agent.build_context(rack_env) end
Check if the URL is a domain
@param message [String] The message @return TRUE/FALASE
# File lib/stackify_ruby_apm.rb, line 168 def self.check_isdomain(url) url =~ %r{^(http|https):\/\/|[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6}(:[0-9]{1,5})?(\/.*)?$} end
Returns the currently active transaction (if any)
@return [Transaction] if any
# File lib/stackify_ruby_apm.rb, line 97 def self.current_transaction agent && agent.current_transaction end
# File lib/stackify_ruby_apm.rb, line 52 def self.inject_rum_script config = StackifyRubyAPM::Config.new client_id = config.client_id device_id = config.device_id client_rundomain = config.client_run_domain transaction_id = defined?(StackifyRubyAPM.current_transaction.id) ? StackifyRubyAPM.current_transaction.id : nil inject_flag = false if client_id && device_id inject_flag = true if check_isdomain(client_rundomain) end return unless inject_flag data_request_id = "V2|#{transaction_id}|#{client_id}|#{device_id}" @rum_script_injected = true "<script src=\"#{config.rum_script_src}\" data-host=\"#{client_rundomain}\" data-requestId=\"#{data_request_id}\" data-a=\"#{config.application_name}\" data-e=\"#{config.environment_name}\" data-enableInternalLogging=\"#{config.debug_logging}\" type=\"text/javascript\" async></script>" end
Report and exception to APM
@param exception [Exception] The exception @param handled [Boolean] Whether the exception was rescued @return [Error] The generated [Error]
# File lib/stackify_ruby_apm.rb, line 152 def self.report(exception, handled: true) agent && agent.report(exception, handled: handled) end
Report a custom string error message to APM
@param message [String] The message @return [Error] The generated [Error]
# File lib/stackify_ruby_apm.rb, line 160 def self.report_message(message, **attrs) agent && agent.report_message(message, backtrace: caller, **attrs) end
Check if the RUM Script is Injected
@return TRUE/FALASE
# File lib/stackify_ruby_apm.rb, line 175 def self.rum_script_inject @rum_script_injected end
Run the custom instrument
# File lib/stackify_ruby_apm.rb, line 72 def self.run_custom_instrument return unless running? StackifyRubyAPM::InstrumenterHelper.custom_instrumented_reset StackifyRubyAPM::Spies.run_custom_instrumentation end
@return [Boolean] Whether there's an [Agent] running
# File lib/stackify_ruby_apm.rb, line 84 def self.running? Agent.running? end
Starts a new span under the current transaction
@param name [String] A description of the span, eq `SELECT FROM “users”` @param type [String] The kind of span, eq `db.mysql2.query` @param context [Span::Context] Context
information about the span @yield [Span] Optional block encapsulating span @return [Span] Unless block given
# File lib/stackify_ruby_apm.rb, line 123 def self.span(name, type = nil, context: nil, include_stacktrace: true, &block) return (block_given? ? yield : nil) unless agent agent.span( name, type, context: context, backtrace: include_stacktrace ? caller : nil, &block ) end
Starts the StackifyRubyAPM
Agent
@param config [Config] An instance of Config
@return [Agent] The resulting [Agent]
# File lib/stackify_ruby_apm.rb, line 48 def self.start(config = {}) Agent.start config end
Stops the StackifyRubyAPM
Agent
# File lib/stackify_ruby_apm.rb, line 79 def self.stop Agent.stop end
Start a new transaction or return the currently running
@param name [String] A description of the transaction, eg `ExamplesController#index` @param type [String] The kind of the transaction, eg `app.request.get` or `db.mysql2.query` @param context [Context] An optional [Context] @yield [Transaction] Optional block encapsulating transaction @return [Transaction] Unless block given
# File lib/stackify_ruby_apm.rb, line 110 def self.transaction(name = nil, type = nil, context: nil, &block) return (block_given? ? yield : nil) unless agent agent.transaction(name, type, context: context, &block) end