---
description: Read the trace and span IDs of a span, mark spans as failed or successful, and rename spans after they start.
title: Workers tracing — new spanContext(), setStatus(), and updateName() APIs
image: https://developers.cloudflare.com/changelog/post/2026-10-26-span-context-status-update-name/og.png?v=4c6c84b699a1a4e6
---

[Skip to content](#main-content)

[View RSS feeds](https://developers.cloudflare.com/fundamentals/new-features/available-rss-feeds/) [ Subscribe to RSS](https://developers.cloudflare.com/changelog/rss/index.xml)

[Back to all posts](https://developers.cloudflare.com/changelog)

October 26, 2026

## Workers tracing — new spanContext(), setStatus(), and updateName() APIs

[Workers](https://developers.cloudflare.com/workers/)

Copy as Markdown| [View as Markdown](https://developers.cloudflare.com/changelog/post/2026-10-26-span-context-status-update-name/index.md)| [Agent setup](https://developers.cloudflare.com/agent-setup/)

[Custom spans](https://developers.cloudflare.com/workers/observability/traces/custom-spans/) in Workers now support three more methods from the OpenTelemetry span API.

- **`span.spanContext()`** returns the span's `traceId`, `spanId`, and `traceFlags`. The IDs match the trace and span IDs in Workers Observability and in exported traces, so you can log them or return them to clients to correlate a request with its trace.
- **`span.setStatus(status)`** sets the span status to `"unset"`, `"ok"`, or `"error"`, with an optional message for errors. Span status is included in traces exported to [OpenTelemetry destinations](https://developers.cloudflare.com/workers/observability/opentelemetry-export/). The Workers Observability dashboard does not display it yet.
- **`span.updateName(name)`** renames a span after it starts, such as once you know which route a request matched. You can also rename the invocation's root span returned by `tracing.getActiveSpan()`.

*src/index.jsjs*

```js
import { tracing } from "cloudflare:workers";

export default {
	async fetch(request, env) {
		const root = tracing.getActiveSpan();
		const route = router.match(request);
		root?.updateName(`${request.method} ${route.pattern}`);

		return tracing.startActiveSpan("handle", async (span) => {
			try {
				const response = await route.handler(request, env);
				span.setStatus({ code: "ok" });
				return response;
			} catch (err) {
				span.recordException(err);
				span.setStatus({ code: "error", message: "Route handler failed" });
				return Response.json(
					{ error: "Internal error", traceId: root?.spanContext().traceId },
					{ status: 500 },
				);
			} finally {
				span.end();
			}
		});
	},
};
```

*src/index.tsts*

```ts
import { tracing } from "cloudflare:workers";

export default {
	async fetch(request: Request, env: Env): Promise<Response> {
		const root = tracing.getActiveSpan();
		const route = router.match(request);
		root?.updateName(`${request.method} ${route.pattern}`);

		return tracing.startActiveSpan("handle", async (span) => {
			try {
				const response = await route.handler(request, env);
				span.setStatus({ code: "ok" });
				return response;
			} catch (err) {
				span.recordException(err as Error);
				span.setStatus({ code: "error", message: "Route handler failed" });
				return Response.json(
					{ error: "Internal error", traceId: root?.spanContext().traceId },
					{ status: 500 },
				);
			} finally {
				span.end();
			}
		});
	},
};
```

For more details, refer to the [custom spans documentation](https://developers.cloudflare.com/workers/observability/traces/custom-spans/).

```json
{"@context":"https://schema.org","@type":"BlogPosting","@id":"https://developers.cloudflare.com/changelog/post/2026-10-26-span-context-status-update-name/#page","headline":"Workers tracing — new spanContext(), setStatus(), and updateName() APIs","description":"Read the trace and span IDs of a span, mark spans as failed or successful, and rename spans after they start.","url":"https://developers.cloudflare.com/changelog/post/2026-10-26-span-context-status-update-name/","inLanguage":"en","image":"https://developers.cloudflare.com/changelog/post/2026-10-26-span-context-status-update-name/og.png?v=4c6c84b699a1a4e6","dateModified":"2026-10-26","datePublished":"2026-10-26","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}
```
