Sha256: aa2df83fe3722b372b5668a996e3ed42a56a88d1de845bfe26b9b75ea4a45811

Contents?: true

Size: 1.69 KB

Versions: 4

Compression:

Stored size: 1.69 KB

Contents

###############################################################
# BASIC TRACING EXAMPLES
###############################################################

# set APPOPTICS_SERVICE_KEY and run with
# `bundle exec ruby 01_basic_tracing.rb`

require 'appoptics_apm'
unless AppopticsAPM::SDK.appoptics_ready?(10_000)
  puts "aborting!!! Agent not ready after 10 seconds"
  exit false
end


###############################################################
# Starting a trace and adding a span
###############################################################

# USE CASE:
# You may want to either trace a piece of your own code or a
# call to a method from a gem that isn't auto-instrumented by
# appoptics_apm

# The first example will not create a span, because no trace has
# been started, but the second and third ones will.

# The string argument is the name for the span

##
# AppOpticsAPM::SDK.trace()
# most of the time this is the method you need.  It adds a span
# to a trace that has probably been started by rack.

# Example 1
def do_work
  42
end

AppOpticsAPM::SDK.trace('simple_span') do
  do_work
end

##
# 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

# Example 2
AppOpticsAPM::SDK.start_trace('outer_span') do

  AppOpticsAPM::SDK.trace('simple_span') do
    do_work
    AppOpticsAPM::API.log_info(AppOpticsAPM.layer, { some: :fancy, hash: :to, send: 1 })
  end

end

# Example 3
def do_traced_work
  AppOpticsAPM::SDK.trace('simple_span_2') do
    do_work
  end
end

# Example with logging
AppOpticsAPM::SDK.start_trace('outer_span_2') do
  AppopticsAPM.logger.warn "Hello World!"
  do_traced_work
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
appoptics_apm-4.8.2 examples/SDK/01_basic_tracing.rb
appoptics_apm-4.8.1 examples/SDK/01_basic_tracing.rb
appoptics_apm-4.8.0 examples/SDK/01_basic_tracing.rb
appoptics_apm-4.7.0 examples/SDK/01_basic_tracing.rb