Workers - Workers tracing now supports custom spans
19d ago
Source
CloudflareWorkers - Workers tracing now supports custom spanscloudflare.comYou can now create custom trace spans in your Workers code using tracing.enterSpan() . Custom spans appear alongside the automatic platform instrumentation (fetch calls, KV reads, D1 queries, and other platform operations) in your traces and OpenTelemetry exports, with correct parent-child nesting. The API is available via import { tracing } from "cloudflare:workers" or through the handler context as ctx.tracing : import { tracing } from "cloudflare:workers" ; export default { async fetch ( request , env , ctx ) { return tracing . enterSpan ( "handleRequest" , async ( span ) => { span . setAttribute ( "url.path" , new URL ( request . url ) . pathname ) ; const data = await env . MY_KV . get ( "key" ) ; return new Response ( data ) ; } ) ; }, }; Spans nest automatically based on the JavaScript async context, and are auto-ended when the callback returns or its returned promise settles. The Span object provides setAttribute(key, value) for attaching metadata and an isTraced property to check whether the current request is being sampled. Tracing must be enabled in your Wrangler configuration for spans to be recorded. For full API details and examples, refer to Custom spans .
You might also wanna read
Cloudflare expands AI bot management tools with granular traffic controls for all customers
Cloudflare is celebrating the second "Content Independence Day" by expanding AI traffic management options for all website owners. Building
Workers - Simpler runtime types with @cloudflare/workers-types v5
Cloudflare·2d ago
AI Search - Manage AI Search sync jobs with Wrangler CLI
Cloudflare·3d ago
Workers - Work across multiple accounts with Wrangler auth profiles
Cloudflare·3d ago
Cache - Cache multiple versions of a URL with Vary
Cloudflare·3d ago
Cloudflare One - Hostname routing for Cloudflare Mesh
Cloudflare·3d ago

Comments
Sign in to join the conversation.
No comments yet. Be the first.