AWS Elastic Beanstalk
This guide walks you through instrumenting AWS Elastic Beanstalk with OpenTelemetry and Middleware.
Introduction
OpenTelemetry offers a standardized method for collecting telemetry data across applications. However, integrating OpenTelemetry with AWS Elastic Beanstalk poses specific challenges due to its serverless infrastructure. This guide aims to simplify the process of setting up OpenTelemetry for various programming languages within Elastic Beanstalk.
Key Challenges
Since AWS Elastic Beanstalk runs on EC2 instances, you would typically SSH into the underlying instance to instrument your application. However, any changes made to the EC2 instance are lost when the environment is restarted, as Elastic Beanstalk replaces the instance with a fresh one, which lacks the previous instrumentation.
Features Supported
Traces | Metrics | App Logs | Custom Logs | Profiling |
---|---|---|---|---|
✅ | ✅ | ✅ | ✅ | ✖ |
Installation
1 Create .ebextensions
Directory
In your Laravel project’s root directory, create a folder named .ebextensions
and add a 99-mwinstrumentation.config
file with the following content:
container_commands: 01_install_agent: command: | MW_API_KEY="<MW_API_KEY>" MW_TARGET=https://<MW_UID>.middleware.io:443 bash -c "$(curl -L https://install.middleware.io/scripts/rpm-install.sh)" 02_run_instrumentation: command: | cd /var/app/staging curl -O https://install.middleware.io/apm/php/laravel-instrument.php COMPOSER_ALLOW_SUPERUSER=1 php laravel-instrument.php install
2 Configure Environment Variables
In the Elastic Beanstalk environment configurations, add the following environment variables:
OTEL_PHP_AUTOLOAD_ENABLED=true OTEL_SERVICE_NAME=your-service-name OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:9320
For frontend-backend trace correlation, add this additional environment variable:
OTEL_PROPAGATORS=baggage,tracecontext,b3multi
3 Additional Configuration
For enabling metrics and further customization, refer to the Laravel instrumentation documentation.