Instrumenting Elastic APM with Grape/Rack (incomplete docs?)

(David Wu) #1

I'm making attempts to instrument Elastic APM with Ruby Grape/Rack following the documentation provided here:

This is important to us as we are an enterprise consumer and we are currently experiencing a huge bottleneck with limited introspection.

I've forked the repo and have been able to inspect the Elastic APM transaction results locally, but I've seen elsewhere that it should essentially work out of the box (Ruby transactions - workers and grape) with Sidekiq to pass them to Kibana on Elastic Cloud. This is the part I can't seem to figure out and would be grateful for any help. Note, I'm making attempts to do this locally. The only message that I see when I'm in Elastic cloud's dashboard under APM is, "Looks like you don't have any services with APM installed. Let's add some!".

Note, my fork (locally) not updated on my GitHub includes some of the code (with minor changes) following what was listed under this discussion on GH: and I've tried this fork:

I've double-checked the server URL and server token. Now, I'm wondering if I need to do some sort of an IP safelisting in Elastic Cloud/Kibana or whether I'm missing some additional steps to ensure that the dashboard is populated.

This is what my elastic_apm.yml looks like:

# Set service name - allowed characters:
# a-z, A-Z, 0-9, -, _ and space
# Defaults to the name of your Rails app
service_name: 'ElasticAPM'

# Use if APM Server requires a token
secret_token: <%= ENV["APM_SECRET"] || ''  %>

# Set custom APM Server URL (
# default: http://localhost:8200)
server_url: <%= ENV["APM_SERVER_URL"] || ''  %>

Thanks in advance!

(Mikkel Malmberg) #2

Hi David

There's no official, automatic Grape support yet. It's something we want to have eventually but I can't tell you when we'll have it.

The implementations you link to are user submitted and not official solutions. They are using the old 1.x APIs. There was a significant update to the APIs with the 2.0 update.

The approach of using a custom middleware can work. The examples just need to be updated per the new APIs:
See perhaps the built-in Middleware for something to built off of: