Module: Appsignal
- Extended by:
- Helpers::Instrumentation, Helpers::Metrics
- Defined in:
- lib/appsignal.rb,
lib/appsignal/cli.rb,
lib/appsignal/demo.rb,
lib/appsignal/span.rb,
lib/appsignal/hooks.rb,
lib/appsignal/config.rb,
lib/appsignal/logger.rb,
lib/appsignal/marker.rb,
lib/appsignal/probes.rb,
lib/appsignal/system.rb,
lib/appsignal/version.rb,
lib/appsignal/cli/demo.rb,
lib/appsignal/minutely.rb,
lib/appsignal/extension.rb,
lib/appsignal/heartbeat.rb,
lib/appsignal/hooks/gvl.rb,
lib/appsignal/hooks/mri.rb,
lib/appsignal/hooks/que.rb,
lib/appsignal/auth_check.rb,
lib/appsignal/hooks/http.rb,
lib/appsignal/hooks/puma.rb,
lib/appsignal/hooks/rake.rb,
lib/appsignal/probes/gvl.rb,
lib/appsignal/probes/mri.rb,
lib/appsignal/utils/data.rb,
lib/appsignal/utils/json.rb,
lib/appsignal/cli/helpers.rb,
lib/appsignal/cli/install.rb,
lib/appsignal/environment.rb,
lib/appsignal/hooks/excon.rb,
lib/appsignal/hooks/redis.rb,
lib/appsignal/transaction.rb,
lib/appsignal/transmitter.rb,
lib/appsignal/cli/diagnose.rb,
lib/appsignal/hooks/resque.rb,
lib/appsignal/hooks/sequel.rb,
lib/appsignal/hooks/sidekiq.rb,
lib/appsignal/hooks/unicorn.rb,
lib/appsignal/hooks/net_http.rb,
lib/appsignal/probes/helpers.rb,
lib/appsignal/probes/sidekiq.rb,
lib/appsignal/event_formatter.rb,
lib/appsignal/extension/jruby.rb,
lib/appsignal/helpers/metrics.rb,
lib/appsignal/hooks/celluloid.rb,
lib/appsignal/hooks/passenger.rb,
lib/appsignal/hooks/shoryuken.rb,
lib/appsignal/hooks/active_job.rb,
lib/appsignal/hooks/webmachine.rb,
lib/appsignal/integrations/que.rb,
lib/appsignal/hooks/data_mapper.rb,
lib/appsignal/hooks/delayed_job.rb,
lib/appsignal/hooks/dry_monitor.rb,
lib/appsignal/integrations/http.rb,
lib/appsignal/integrations/rake.rb,
lib/appsignal/cli/diagnose/paths.rb,
lib/appsignal/cli/diagnose/utils.rb,
lib/appsignal/garbage_collection.rb,
lib/appsignal/hooks/action_cable.rb,
lib/appsignal/hooks/redis_client.rb,
lib/appsignal/integrations/excon.rb,
lib/appsignal/integrations/grape.rb,
lib/appsignal/integrations/redis.rb,
lib/appsignal/utils/rails_helper.rb,
lib/appsignal/hooks/action_mailer.rb,
lib/appsignal/integrations/hanami.rb,
lib/appsignal/integrations/resque.rb,
lib/appsignal/integrations/padrino.rb,
lib/appsignal/integrations/railtie.rb,
lib/appsignal/integrations/sidekiq.rb,
lib/appsignal/integrations/unicorn.rb,
lib/appsignal/utils/hash_sanitizer.rb,
lib/appsignal/integrations/net_http.rb,
lib/appsignal/helpers/instrumentation.rb,
lib/appsignal/hooks/mongo_ruby_driver.rb,
lib/appsignal/integrations/webmachine.rb,
lib/appsignal/rack/streaming_listener.rb,
lib/appsignal/integrations/data_mapper.rb,
lib/appsignal/integrations/dry_monitor.rb,
lib/appsignal/utils/integration_logger.rb,
lib/appsignal/integrations/action_cable.rb,
lib/appsignal/integrations/redis_client.rb,
lib/appsignal/utils/deprecation_message.rb,
lib/appsignal/rack/rails_instrumentation.rb,
lib/appsignal/rack/generic_instrumentation.rb,
lib/appsignal/rack/sinatra_instrumentation.rb,
lib/appsignal/utils/query_params_sanitizer.rb,
lib/appsignal/integrations/mongo_ruby_driver.rb,
lib/appsignal/integrations/delayed_job_plugin.rb,
lib/appsignal/event_formatter/rom/sql_formatter.rb,
lib/appsignal/hooks/active_support_notifications.rb,
lib/appsignal/event_formatter/sequel/sql_formatter.rb,
lib/appsignal/event_formatter/faraday/request_formatter.rb,
lib/appsignal/integrations/active_support_notifications.rb,
lib/appsignal/integrations/capistrano/capistrano_2_tasks.rb,
lib/appsignal/event_formatter/active_record/sql_formatter.rb,
lib/appsignal/event_formatter/action_view/render_formatter.rb,
lib/appsignal/event_formatter/elastic_search/search_formatter.rb,
lib/appsignal/event_formatter/mongo_ruby_driver/query_formatter.rb,
lib/appsignal/event_formatter/active_record/instantiation_formatter.rb,
ext/appsignal_extension.c
Overview
AppSignal for Ruby gem's main module.
Provides method to control the AppSignal instrumentation and the system agent. Also provides direct access to instrumentation helpers (from Helpers::Instrumentation) and metrics helpers (from Helpers::Metrics) for ease of use.
Defined Under Namespace
Modules: GarbageCollection, Grape, Helpers, Integrations, Probes, Rack, System, Utils Classes: AuthCheck, CLI, Capistrano, Config, Demo, Environment, EventFormatter, Extension, Heartbeat, Hooks, Logger, Marker, Minutely, Span, StreamWrapper, Transaction, Transmitter
Constant Summary collapse
- VERSION =
"3.7.0"
Class Attribute Summary collapse
-
.config ⇒ Config?
Accessor for the AppSignal configuration.
-
.extension_loaded ⇒ Boolean?
private
Accessor for toggle if the AppSignal C-extension is loaded.
- .internal_logger ⇒ Object
-
.logger ⇒ Logger
private
Accessor for the internal AppSignal logger.
Class Method Summary collapse
-
.active? ⇒ Boolean
Returns the active state of the AppSignal integration.
-
.extension_loaded? ⇒ Boolean
Returns if the C-extension was loaded properly.
- .forked ⇒ Object
- .get_server_state(key) ⇒ Object
- .heartbeat(name) ⇒ Object
-
.in_memory_log ⇒ StringIO
private
In memory internal logger used before any internal logger is started with Appsignal.start_logger.
- .log_formatter(prefix = nil) ⇒ Object private
-
.start ⇒ void
Start the AppSignal integration.
-
.start_logger ⇒ void
Start the AppSignal internal logger.
-
.stop(called_by = nil) ⇒ void
Stop AppSignal's agent.
- .testing? ⇒ Boolean private
Methods included from Helpers::Metrics
add_distribution_value, increment_counter, set_gauge, set_host_gauge, set_process_gauge
Methods included from Helpers::Instrumentation
add_breadcrumb, instrument, instrument_sql, listen_for_error, monitor_single_transaction, monitor_transaction, send_error, set_action, set_error, set_namespace, tag_request, without_instrumentation
Methods included from Utils::DeprecationMessage
Class Attribute Details
.config ⇒ Config?
Accessor for the AppSignal configuration. Return the current AppSignal configuration.
Can return nil
if no configuration has been set or automatically loaded
by an automatic integration or by calling start.
37 38 39 |
# File 'lib/appsignal.rb', line 37 def config @config end |
.extension_loaded ⇒ Boolean?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Accessor for toggle if the AppSignal C-extension is loaded.
Can be nil
if extension has not been loaded yet. See
extension_loaded? for a boolean return value.
47 48 49 |
# File 'lib/appsignal.rb', line 47 def extension_loaded @extension_loaded end |
.internal_logger ⇒ Object
184 185 186 187 188 189 190 |
# File 'lib/appsignal.rb', line 184 def internal_logger @internal_logger ||= Appsignal::Utils::IntegrationLogger.new(in_memory_log).tap do |l| l.level = ::Logger::INFO l.formatter = log_formatter("appsignal") end end |
.logger ⇒ Logger
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
some classes may have options to set custom loggers. Their defaults are pointed to this attribute.
Accessor for the internal AppSignal logger.
Not to be confused with our logging feature. This is part of our private internal API. Do not call this method directly.
If no logger has been set, it will return a "in memory logger", using
in_memory_log
. Once AppSignal is started (using start) the
contents of the "in memory logger" is written to the new logger.
64 |
# File 'lib/appsignal.rb', line 64 attr_writer :internal_logger |
Class Method Details
.active? ⇒ Boolean
Returns the active state of the AppSignal integration.
Conditions apply for AppSignal to be marked as active:
- There is a config set on the config attribute.
- The set config is active Appsignal::Config#active?.
- The AppSignal Extension is loaded extension_loaded?.
This logic is used within instrument helper such as instrument so it's not necessary to wrap instrument calls with this method.
258 259 260 |
# File 'lib/appsignal.rb', line 258 def active? config&.active? && extension_loaded? end |
.extension_loaded? ⇒ Boolean
Returns if the C-extension was loaded properly.
229 230 231 |
# File 'lib/appsignal.rb', line 229 def extension_loaded? !!extension_loaded end |
.forked ⇒ Object
157 158 159 160 161 162 163 |
# File 'lib/appsignal.rb', line 157 def forked return unless active? Appsignal.start_logger internal_logger.debug("Forked process, resubscribing and restarting extension") Appsignal::Extension.start end |
.get_server_state(key) ⇒ Object
165 166 167 |
# File 'lib/appsignal.rb', line 165 def get_server_state(key) Appsignal::Extension.get_server_state(key) end |
.heartbeat(name) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/appsignal/heartbeat.rb', line 59 def self.heartbeat(name) heartbeat = Appsignal::Heartbeat.new(:name => name) output = nil if block_given? heartbeat.start output = yield end heartbeat.finish output end |
.in_memory_log ⇒ StringIO
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
In memory internal logger used before any internal logger is started with start_logger.
The contents of this logger are flushed to the logger in start_logger.
176 177 178 179 180 181 182 |
# File 'lib/appsignal.rb', line 176 def in_memory_log if defined?(@in_memory_log) && @in_memory_log @in_memory_log else @in_memory_log = StringIO.new end end |
.log_formatter(prefix = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
193 194 195 196 197 198 199 |
# File 'lib/appsignal.rb', line 193 def log_formatter(prefix = nil) pre = "#{prefix}: " if prefix proc do |severity, datetime, _progname, msg| "[#{datetime.strftime("%Y-%m-%dT%H:%M:%S")} (process) " \ "##{Process.pid}][#{severity}] #{pre}#{msg}\n" end end |
.start ⇒ void
This method returns an undefined value.
Start the AppSignal integration.
Starts AppSignal with the given configuration. If no configuration is set yet it will try to automatically load the configuration using the environment loaded from environment variables and the currently working directory.
This is not required for the automatic integrations AppSignal offers, but this is required for all non-automatic integrations and pure Ruby applications. For more information, see our integrations list and our Integrating AppSignal guide.
To start the logger see start_logger.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/appsignal.rb', line 96 def start unless extension_loaded? internal_logger.info("Not starting appsignal, extension is not loaded") return end internal_logger.debug("Starting appsignal") @config ||= Config.new( Dir.pwd, ENV["APPSIGNAL_APP_ENV"] || ENV["RAILS_ENV"] || ENV.fetch("RACK_ENV", nil) ) if config.valid? internal_logger.level = config.log_level if config.active? internal_logger.info "Starting AppSignal #{Appsignal::VERSION} " \ "(#{$PROGRAM_NAME}, Ruby #{RUBY_VERSION}, #{RUBY_PLATFORM})" config.write_to_environment Appsignal::Extension.start Appsignal::Hooks.load_hooks if config[:enable_allocation_tracking] && !Appsignal::System.jruby? Appsignal::Extension.install_allocation_event_hook Appsignal::Environment.report_enabled("allocation_tracking") end Appsignal::Minutely.start if config[:enable_minutely_probes] else internal_logger.info("Not starting, not active for #{config.env}") end else internal_logger.error("Not starting, no valid config for this environment") end end |
.start_logger ⇒ void
This method returns an undefined value.
Start the AppSignal internal logger.
Sets the log level and sets the logger. Uses a file-based logger or the
STDOUT-based logger. See the :log
configuration option.
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/appsignal.rb', line 208 def start_logger if config && config[:log] == "file" && config.log_file_path start_internal_file_logger(config.log_file_path) else start_internal_stdout_logger end internal_logger.level = if config config.log_level else Appsignal::Config::DEFAULT_LOG_LEVEL end internal_logger << @in_memory_log.string if @in_memory_log end |
.stop(called_by = nil) ⇒ void
This method returns an undefined value.
Stop AppSignal's agent.
Stops the AppSignal agent. Call this before the end of your program to make sure the agent is stopped as well.
148 149 150 151 152 153 154 155 |
# File 'lib/appsignal.rb', line 148 def stop(called_by = nil) if called_by internal_logger.debug("Stopping appsignal (#{called_by})") else internal_logger.debug("Stopping appsignal") end Appsignal::Extension.stop end |
.testing? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
67 68 69 |
# File 'lib/appsignal.rb', line 67 def testing? false end |