Description
Description
Cloudflare exposes lots of it's services via bindings which get attached to the Env
that gets passed to your handlers:
https://developers.cloudflare.com/workers/runtime-apis/bindings/
This includes:
- AI
- Analytics Engine
- Assets
- Browser Rendering
- D1
- Dispatcher (Workers for Platforms)
- Durable Objects
- Images
- KV
- mTLS
- Queues
- R2
- Rate Limiting
- Secrets
- Secrets Store
- Service bindings
- Tail Workers
- Vectorize
- Workflows
Since we wrap many of the functions that get passed the Env
, we should be able to add wrappers around the individual service bindings to instrument them. For example, it would be great to be able to include spans for calls to R2 object storage.
export default {
async fetch(request, env) {
const url = new URL(request.url);
const key = url.pathname.slice(1);
switch (request.method) {
case "PUT":
await env.MY_BUCKET.put(key, request.body);
return new Response(`Put ${key} successfully!`);
default:
return new Response(`${request.method} is not allowed.`, {
status: 405,
headers: {
Allow: "PUT",
},
});
}
},
};
I'm not sure if env
in enumerable and even if it is, we probably won't know for sure what kind of service each property exposes. This feature might need bundler support so we can read the wrangler configuration and include some details in the bundle so we know what kind of service each env property exposes and how to wrap it.