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/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/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/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/utils/integration_logger.rb,
lib/appsignal/integrations/action_cable.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/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, Hooks, Logger, Marker, Minutely, Span, StreamWrapper, Transaction, Transmitter
Constant Summary collapse
- VERSION =
"3.4.0".freeze
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.
-
.logger ⇒ Logger
private
Accessor for the 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
-
.in_memory_log ⇒ StringIO
private
In memory logger used before any 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 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 |
.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 AppSignal logger.
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.
60 |
# File 'lib/appsignal.rb', line 60 attr_writer :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.
251 252 253 |
# File 'lib/appsignal.rb', line 251 def active? config && config.active? && extension_loaded? end |
.extension_loaded? ⇒ Boolean
Returns if the C-extension was loaded properly.
222 223 224 |
# File 'lib/appsignal.rb', line 222 def extension_loaded? !!extension_loaded end |
.forked ⇒ Object
153 154 155 156 157 158 |
# File 'lib/appsignal.rb', line 153 def forked return unless active? Appsignal.start_logger logger.debug("Forked process, resubscribing and restarting extension") Appsignal::Extension.start end |
.get_server_state(key) ⇒ Object
160 161 162 |
# File 'lib/appsignal.rb', line 160 def get_server_state(key) Appsignal::Extension.get_server_state(key) 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 logger used before any logger is started with start_logger.
The contents of this logger are flushed to the logger in start_logger.
170 171 172 173 174 175 176 |
# File 'lib/appsignal.rb', line 170 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.
186 187 188 189 190 191 192 |
# File 'lib/appsignal.rb', line 186 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.
92 93 94 95 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 |
# File 'lib/appsignal.rb', line 92 def start unless extension_loaded? logger.info("Not starting appsignal, extension is not loaded") return end logger.debug("Starting appsignal") @config ||= Config.new( Dir.pwd, ENV["APPSIGNAL_APP_ENV"] || ENV["RAILS_ENV"] || ENV["RACK_ENV"] ) if config.valid? logger.level = config.log_level if config.active? 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 logger.info("Not starting, not active for #{config.env}") end else logger.error("Not starting, no valid config for this environment") end end |
.start_logger ⇒ void
This method returns an undefined value.
Start the AppSignal logger.
Sets the log level and sets the logger. Uses a file-based logger or the
STDOUT-based logger. See the :log
configuration option.
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/appsignal.rb', line 201 def start_logger if config && config[:log] == "file" && config.log_file_path start_file_logger(config.log_file_path) else start_stdout_logger end logger.level = if config config.log_level else Appsignal::Config::DEFAULT_LOG_LEVEL end 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.
144 145 146 147 148 149 150 151 |
# File 'lib/appsignal.rb', line 144 def stop(called_by = nil) if called_by logger.debug("Stopping appsignal (#{called_by})") else 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.
63 64 65 |
# File 'lib/appsignal.rb', line 63 def testing? false end |