Cloudflare Docs
Workers
Edit this page
Report an issue with this page
Log into the Cloudflare dashboard
Set theme to dark (⇧+D)

Version metadata binding

Beta

The version metadata binding can be used to access metadata associated with a version from inside the Workers runtime.

Worker version ID, version tag and timestamp of when the version was created are available through the version metadata binding. They can be used in events sent to Workers Analytics Engine or to any third-party analytics/metrics service in order to aggregate by Worker version.

To use the version metadata binding, update your Worker’s wrangler.toml file:

wrangler.toml
[version_metadata]
binding = "CF_VERSION_METADATA"

​​ Interface

An example of how to access the version ID and version tag from within a Worker to send events to Workers Analytics Engine:

export default {
async fetch(request, env, ctx) {
const { id: versionId, tag: versionTag, timestamp: versionTimestamp } = env.CF_VERSION_METADATA;
env.WAE.writeDataPoint({
indexes: [versionId],
blobs: [versionTag, versionTimestamp],
//...
});
//...
},
};
interface Environment {
CF_VERSION_METADATA: WorkerVersionMetadata;
WAE: AnalyticsEngineDataset;
}
export default {
async fetch(request, env, ctx) {
const { id: versionId, tag: versionTag } = env.CF_VERSION_METADATA;
env.WAE.writeDataPoint({
indexes: [versionId],
blobs: [versionTag],
//...
});
//...
},
} satisfies ExportedHandler<Env>;