Module: Appsignal

Extended by:
Helpers::Instrumentation, Helpers::Metrics, Gem::Deprecate
Defined in:
lib/appsignal.rb,
lib/appsignal/cli.rb,
lib/appsignal/demo.rb,
lib/appsignal/hooks.rb,
lib/appsignal/config.rb,
lib/appsignal/marker.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/que.rb,
lib/appsignal/auth_check.rb,
lib/appsignal/hooks/puma.rb,
lib/appsignal/hooks/rake.rb,
lib/appsignal/utils/data.rb,
lib/appsignal/utils/json.rb,
lib/appsignal/cli/helpers.rb,
lib/appsignal/cli/install.rb,
lib/appsignal/hooks/redis.rb,
lib/appsignal/transaction.rb,
lib/appsignal/transmitter.rb,
lib/appsignal/cli/diagnose.rb,
lib/appsignal/hooks/sequel.rb,
lib/appsignal/hooks/sidekiq.rb,
lib/appsignal/hooks/unicorn.rb,
lib/appsignal/hooks/net_http.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/webmachine.rb,
lib/appsignal/integrations/que.rb,
lib/appsignal/hooks/data_mapper.rb,
lib/appsignal/hooks/delayed_job.rb,
lib/appsignal/cli/diagnose/paths.rb,
lib/appsignal/cli/diagnose/utils.rb,
lib/appsignal/hooks/action_cable.rb,
lib/appsignal/integrations/grape.rb,
lib/appsignal/utils/rails_helper.rb,
lib/appsignal/integrations/resque.rb,
lib/appsignal/cli/notify_of_deploy.rb,
lib/appsignal/integrations/padrino.rb,
lib/appsignal/integrations/railtie.rb,
lib/appsignal/utils/hash_sanitizer.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/js_exception_transaction.rb,
lib/appsignal/rack/js_exception_catcher.rb,
lib/appsignal/utils/deprecation_message.rb,
lib/appsignal/rack/rails_instrumentation.rb,
lib/appsignal/garbage_collection_profiler.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/resque_active_job.rb,
lib/appsignal/integrations/delayed_job_plugin.rb,
lib/appsignal/hooks/active_support_notifications.rb,
lib/appsignal/event_formatter/moped/query_formatter.rb,
lib/appsignal/event_formatter/faraday/request_formatter.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: Grape, Helpers, Integrations, Rack, System, Utils Classes: AuthCheck, CLI, Capistrano, Config, Demo, EventFormatter, Extension, GarbageCollectionProfiler, Hooks, JSExceptionTransaction, Marker, Minutely, NilGarbageCollectionProfiler, StreamWrapper, Transaction, Transmitter

Constant Summary collapse

VERSION =
"2.9.16".freeze

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Helpers::Metrics

add_distribution_value, increment_counter, set_gauge, set_host_gauge, set_process_gauge

Methods included from Helpers::Instrumentation

instrument, instrument_sql, listen_for_error, monitor_single_transaction, monitor_transaction, send_error, set_action, set_error, set_namespace, tag_request, without_instrumentation

Class Attribute Details

.configConfig?

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.

Examples:

Appsignal.config

Setting the configuration

Appsignal.config = Appsignal::Config.new(Dir.pwd, "production")

Returns:

See Also:



36
37
38
# File 'lib/appsignal.rb', line 36

def config
  @config
end

.extension_loadedBoolean?

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.

Returns:

  • (Boolean, nil)

See Also:



46
47
48
# File 'lib/appsignal.rb', line 46

def extension_loaded
  @extension_loaded
end

.loggerLogger

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.

Note:

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.

Returns:

  • (Logger)

See Also:



59
# File 'lib/appsignal.rb', line 59

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:

This logic is used within instrument helper such as instrument so it's not necessary to wrap instrument calls with this method.

Examples:

Do this

Appsignal.instrument(..) do
  # Do this
end

Don't do this

if Appsignal.active?
  Appsignal.instrument(..) do
    # Don't do this
  end
end

Returns:

  • (Boolean)

Since:

  • 0.2.7



277
278
279
# File 'lib/appsignal.rb', line 277

def active?
  config && config.active? && extension_loaded?
end

.extension_loaded?Boolean

Returns if the C-extension was loaded properly.

Returns:

  • (Boolean)

See Also:

Since:

  • 1.0.0



248
249
250
# File 'lib/appsignal.rb', line 248

def extension_loaded?
  !!extension_loaded
end

.extensionsObject

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.



62
63
64
# File 'lib/appsignal.rb', line 62

def extensions
  @extensions ||= []
end

.forkedObject



172
173
174
175
176
177
# File 'lib/appsignal.rb', line 172

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



179
180
181
# File 'lib/appsignal.rb', line 179

def get_server_state(key)
  Appsignal::Extension.get_server_state(key)
end

.in_memory_logStringIO

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.

Returns:

  • (StringIO)


189
190
191
192
193
194
195
# File 'lib/appsignal.rb', line 189

def in_memory_log
  if defined?(@in_memory_log) && @in_memory_log
    @in_memory_log
  else
    @in_memory_log = StringIO.new
  end
end

.initialize_extensionsObject

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
70
71
72
73
# File 'lib/appsignal.rb', line 67

def initialize_extensions
  Appsignal.logger.debug("Initializing extensions")
  extensions.each do |extension|
    Appsignal.logger.debug("Initializing #{extension}")
    extension.initializer
  end
end

.is_ignored_action?(action) ⇒ Boolean

Deprecated.

No replacement

Returns:

  • (Boolean)


289
290
291
# File 'lib/appsignal.rb', line 289

def is_ignored_action?(action) # rubocop:disable Naming/PredicateName
  Appsignal.config[:ignore_actions].include?(action)
end

.is_ignored_error?(error) ⇒ Boolean Also known as: is_ignored_exception?

Deprecated.

No replacement

Returns:

  • (Boolean)


282
283
284
# File 'lib/appsignal.rb', line 282

def is_ignored_error?(error) # rubocop:disable Naming/PredicateName
  Appsignal.config[:ignore_errors].include?(error.class.name)
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.



205
206
207
208
209
210
211
# File 'lib/appsignal.rb', line 205

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

.startvoid

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.

Examples:

Appsignal.start

with custom loaded configuration

Appsignal.config = Appsignal::Config.new(Dir.pwd, "production")
Appsignal.start

Since:

  • 0.7.0



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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/appsignal.rb', line 105

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 =
      if config[:debug]
        Logger::DEBUG
      else
        Logger::INFO
      end
    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
      Appsignal::EventFormatter.initialize_deprecated_formatters
      initialize_extensions

      if config[:enable_allocation_tracking] && !Appsignal::System.jruby?
        Appsignal::Extension.install_allocation_event_hook
      end

      GC::Profiler.enable if config[:enable_gc_instrumentation]

      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(path_arg = nil) ⇒ 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.

Parameters:

  • path_arg (nil) (defaults to: nil)

    Deprecated param. Use the :log_path configuration option instead.

Since:

  • 0.7.0



222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/appsignal.rb', line 222

def start_logger(path_arg = nil)
  if path_arg
    logger.info("Setting the path in start_logger has no effect anymore, set it in the config instead")
  end

  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[:debug]
      Logger::DEBUG
    else
      Logger::INFO
    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.

Examples:

Appsignal.start
# Run your application
Appsignal.stop

Parameters:

  • called_by (String) (defaults to: nil)

    Name of the thing that requested the agent to be stopped. Will be used in the AppSignal log file.

Since:

  • 1.0.0



163
164
165
166
167
168
169
170
# File 'lib/appsignal.rb', line 163

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.

Returns:

  • (Boolean)


76
77
78
# File 'lib/appsignal.rb', line 76

def testing?
  false
end