#OpenTelemetry for Cloudflare Workers
Instrument your Cloudflare Worker applications with OpenTelemetry using the the otel-cf-workers SDK.
#Instrumentation
#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
#Step 3: Configure the tracer
In your Cloudflare worker file, add the following configuration code to configure OpenTelemetry.
#Step 4: Set the Baselime environment variables
In your Cloudflare Workers Secret Configuration add the BASELIME_API_KEY
.
To enable tracing for local dev add your BASELIME_API_KEY
to your .dev.vars
file
In your wrangler.toml
file set the SERVICE_NAME
variable
Get your pulic BASELIME_API_KEY from the Baselime console.
Once these steps are completed, distributed traces from your Cloudflare Workers application should be available in Baselime to query via the console or the Baselime CLI.
#Adding custom OpenTelemetry spans
To add custom spans to your OpenTelemetry traces, install the @opentelemetry/api
package.
And manually add spans to your traces.
#Special Thanks
This is powered by otel-cf-workers developed by Erwin van der Koogh. It's a fantastic vendor agnostic OpenTelemetry SDK for Cloudflare Workers and you should check it out.