Custom instrumentation
Elastic Cloud Serverless projects are autoscaled environments, fully managed by Elastic and available on Elastic Cloud. Availability This functionality is generally available and ready for production usage. The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats. Availability This functionality is generally available and ready for production usage. Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments. This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes. The Elastic APM Ruby agent enables you to trace the execution of operations in your Ruby applications, sending performance metrics and errors to the Elastic APM Server. Availability This functionality is generally available and ready for production usage. This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.
Serverless Observability
Generally available
Stack
Generally available
APM Agent Ruby
Generally available
When installed and properly configured, ElasticAPM will automatically wrap your app’s request/responses in transactions and report its errors. It also wraps each background job if you use Sidekiq or DelayedJob.
But it is also possible to create your own transactions as well as provide spans for any automatic or custom transaction.
See ElasticAPM.start_transaction and ElasticAPM.start_span.
ElasticAPM includes some nifty helpers if you just want to instrument a regular method.
class Thing
include ElasticAPM::SpanHelpers
def do_the_work
# ...
end
span_method :do_hard_work
def self.do_all_the_work
# ...
end
span_class_method :do_hard_work, 'Custom name', 'custom.work_thing'
end
- takes optional
nameandtype
If you are already inside a Transaction (most likely) and you want to instrument some work inside it, add a custom span:
class ThingsController < ApplicationController
def index
@result_of_work = ElasticAPM.with_span "Heavy work" do
do_the_heavy_work
end
end
end
If you are not inside a Transaction already (eg. outside of your common web application) start and manage your own transactions like so:
class Something
def do_work
transaction = ElasticAPM.start_transaction 'Something#do_work'
begin
Sequel[:users]
rescue Exception => e
ElasticAPM.report(e)
raise
ensure
ElasticAPM.end_transaction('result')
end
end
end
- many third party libs will be automatically instrumented
Note: If the agent isn’t started beforehand this will do nothing. See ElasticAPM.start.