Cloudflare Workers
Monitor Cloudflare Workers using OpenTelemetry and Last9
This document lists step-by-step instructions for setting up monitoring for Cloudflare Workers with Last9.
Prerequisites
- Create a Last9 account by following Getting Started.
- Keep the following information handy from the Integrations page:
$last9_otlp_endpoint
: Last9’s OTLP endpoint copies from Cloudflare Integration section from Integrations page.$last9_basic_auth_header
: OTLP Basic authorization header
Setup
Instrument your Cloudflare Worker applications with OpenTelemetry using the the otel-cf-workers SDK.
Step 1: Install the SDK
Install @microlabs/otel-cf-workers
in your project.
Step 2: Add Node.js Compatibility Flags
OpenTelemetry requires the Node.js Compatibility flag is enabled at the top level of your wrangler.toml
file.
Step 3: Configure the tracer
In your Cloudflare worker file, add the following configuration code to configure OpenTelemetry.
Step 4: Set the Last9 environment variables
In your Cloudflare Workers Secret Configuration add the LAST9_BASIC_AUTH
.
To enable tracing for local dev add your LAST9_BASIC_AUTH
to your .dev.vars
file
In your wrangler.toml
file set the SERVICE_NAME
variable
Once these steps are completed, distributed traces from your Cloudflare Workers application should be available in Last9 Trace Explorer.
Adding custom OpenTelemetry spans
To add custom spans to your OpenTelemetry traces, install the @opentelemetry/api
package.
And manually add spans to your traces.
Verification
Visit Trace Explorer to see the Cloudflare traces in action.
Troubleshooting
Please get in touch with us on Discord or Email if you have any questions.