AWS Lambda Native Tracing for Ruby

This page covers the Ruby specifics for AWS Lambda tracing.

Supported Runtimes

  • ruby3.2

Deprecated runtimes

  • ruby2.7

Starting from 7 January 2024, AWS Lambda no longer applies security patches and other updates to the Ruby 2.7 runtime that is used by Lambda functions. The technical support is not provided to the functions that use Ruby 2.7, and you cannot create Lambda functions that use the Ruby 2.7 runtime.

Installation

In Ruby sensor 1.198.0, the in-process Ruby library automatically detects and reports the information to Instana. Make sure that the library is present in your Gemfile and is required before your handler function.

The Instana Ruby library has native extensions, such as oj, ffi, bigdecimal in its dependency tree. Therefore, make sure that these extensions are available in runtime. For more information, see the AWS recommendations on adding native libraries to the deployment package.

Configuration

In order to send collected traces an AWS Lambda function needs to be provided with two environment variables:

To provide these values to the handler in AWS Console UI go to the Lambda configuration page:

configuring environment variables

  1. Click on your Lambda function box
  2. In within the "Environment Variables" section click "Edit" and add two new variables

There are few optional environment variables that allow changing in-process sensor defaults, such as the list of HTTP headers to collect or a custom service name to use.

Instrumenting a handler function

To instrument your Ruby lambda function, wrap the functional code in a Instana.serverless.wrap_aws block, passing the event and context as arguments. An example has been provided as follows:

require 'bundler/setup'

require 'json'
require 'instana'

def lambda_handler(event:, context:)
  Instana.serverless.wrap_aws(event, context) do
	{
	  statusCode: 200,
	  body: {
		message: "Hello World!",
	  }.to_json
	}
  end
end