Documentation forAppOptics

Instrumentation SDK (legacy agent)

The following content pertains to the instrumentation SDK for the legacy AppOptics Ruby Agent.

AppOptics agents are no long receiving updates. The new SolarWinds Observability libraries are regularly updated with new features and improvements. If you are still relying on the AppOptics agents and your components are supported by the new libraries, consider migrating to SolarWinds Observability.

If you have already transitioned to the new SolarWinds Observability Ruby Library, see the SolarWinds Ruby Library documentation for the instrumentation SDK information.

SolarWinds Observability libraries are not compatible with AppOptics agents. Do not use a mix of SolarWinds Observability libraries and AppOptics agents to instrument applications that are part of a distributed trace.

See the AppopticsAPM::SDK documentation in RubyDocs:

Examples

###############################################################
# START A TRACE, ADD A SPAN, AND LOG AN INFO EVENT
###############################################################
#
# AppOpticsAPM::SDK.start_trace()
# This method starts a trace. It is handy for background jobs,
# workers, or scripts, that are not part of a rack application
AppOpticsAPM::SDK.start_trace('outer_span') do
  AppOpticsAPM::SDK.trace('first_child_span') do
    [9, 6, 12, 2, 7, 1, 9, 3, 4, 14, 5, 8].sort
    AppOpticsAPM::SDK.log_info({ some: :fancy, hash: :to, send: 1 })
  end
end

###############################################################
# LOG AN ERROR EVENT
###############################################################
#
# AppOpticsAPM::SDK.log_exception()
# This method adds an error event to the trace, which will be
# displayed and counted as exception on the appoptics dashboard.
def do_raise
  raise StandardError.new("oops")
end

AppOpticsAPM::SDK.start_trace('with_error') do
  begin
    do_raise
  rescue => e
    AppOpticsAPM::SDK.log_exception(e)
  end
end

###############################################################
# TRACE A METHOD
###############################################################
#
# AppOpticsAPM::SDK.trace_method()
# This creates a span every time the defined method is run.
# The method can be of any (accessible) type (instance,
# singleton, private, protected etc.).
module ExampleModule
  def self.do_sum(a, b)
    a + b
  end
end

AppOpticsAPM::SDK.trace_method(ExampleModule,
                               :do_sum,
                               { name: 'computation', backtrace: true },
                               { CustomKey: "some_info"})
                               
AppOpticsAPM::SDK.start_trace('trace_a_method') do
  ExampleModule.do_sum(1, 2)
  ExampleModule.do_sum(3, 4)
end

###############################################################
# SET A CUSTOM TRANSACTION NAME
###############################################################
#
# AppOpticsAPM::SDK.set_transaction_name()
#
# this method can be called anytime after a trace has been started to add a
# custom name for the whole transaction.
# In case of a controller the trace is usually started in rack.
class FakeController
  def create(params)
    # @fake = fake.new(params.permit(:type, :title))
    # @fake.save
    AppOpticsAPM::SDK.set_transaction_name("fake.#{params[:type]}")
    # redirect_to @fake
  end
end

AppOpticsAPM::SDK.start_trace('set_transaction_name') do
  FakeController.new.create(type: 'news')
end

###############################################################
# LOG INJECTION OF TRACE_ID
###############################################################
#
# AppOpticsAPM::SDK.current_trace
# This method creates an object with the current trace ID and
# helper methods to add the ID to logs for cross-referencing.
AppOpticsAPM::Config[:log_traceId] = :always

AppOpticsAPM::SDK.start_trace('log_trace_id') do
  trace = AppOpticsAPM::SDK.current_trace
  AppOpticsAPM.logger.warn "Some log message #{trace.for_log}"
end

The scripts are not supported under any SolarWinds support program or service. The scripts are provided AS IS without warranty of any kind. SolarWinds further disclaims all warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The risk arising out of the use or performance of the scripts and documentation stays with you. In no event shall SolarWinds or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the scripts or documentation.