From d5f9b4d6345a3a8dec70cba180c1822da130d593 Mon Sep 17 00:00:00 2001 From: s1gr1d <32902192+s1gr1d@users.noreply.github.com> Date: Mon, 9 Nov 2026 17:32:07 +0100 Subject: [PATCH 1/2] docs(span-links): Add `server_request` link type and pageload `cache_origin` links --- .../sdk/telemetry/traces/span-links.mdx | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/develop-docs/sdk/telemetry/traces/span-links.mdx b/develop-docs/sdk/telemetry/traces/span-links.mdx index 02de4768affa8..7139943a31f8d 100644 --- a/develop-docs/sdk/telemetry/traces/span-links.mdx +++ b/develop-docs/sdk/telemetry/traces/span-links.mdx @@ -146,8 +146,9 @@ Any string can be used, but these types have predefined meanings: | `sentry.link.type` | Usage | UI Implications | |--------------------|--------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------| | "previous_trace" | Linking e.g. a navigation span to the previous page load span. | Used to query linked traces. Shows a button to go to linked previous trace in the trace explorer. | -| "cache_origin" | Linking a span that reads a cached value to the trace that produced that value (e.g. server-side rendering). | Used to navigate from a cache-hit span to the origin trace. | +| "cache_origin" | Linking a span that uses a cached value (e.g. a cache read, or a page load of a reused page) to the span that produced that value. | Used to navigate from a cache-hit span to the origin trace. | | "message_origin" | Linking a span that processes a queue message to the span that published the message (e.g. a queue job). | Used to navigate from a consumer span to the producer trace. | +| "server_request" | Linking a page load span to the server request that rendered its document, when the trace context arrived too late to continue it. | Used to navigate from a page load span to the trace of its server request. | ### `previous_trace` @@ -210,6 +211,16 @@ The origin trace may be negatively sampled. The link is still added, with `sampl A background revalidation (for example, stale-while-revalidate) starts its own trace rather than continuing the serving trace, and becomes the origin for future cache hits. +#### Page Loads of Reused Pages + +A server can render a page, or a static part of it (a shell), once and reuse the HTML for later requests. Examples are an ISR page or the shell of a partially prerendered page. +The page load span of such a page uses HTML that an earlier render produced, so that render is the cache origin of the page load span. + +- Send the origin with the reused HTML, in a different field than `sentry-trace`. For example, the Next.js SDK uses a `sentry-cache-origin` meta tag. The render belongs to the request that started it, so the page load span must never continue its trace. +- Add the link at span start, so that `tracesSampler` and `ignoreSpans` can see it. +- Set [`page.server_rendering.type`](https://conventions.sentry.dev/attributes/page/#page-server_rendering-type) on the page load span. +- If the server renders the other parts of the page for the current request (`partially_static`), the page load span continues the trace of that request as usual. The `cache_origin` link points only to the render of the reused part. + ### `message_origin` When a consumer processes a message, the work often runs long after the producer published it, in another process, and with a different sampling decision. @@ -239,6 +250,38 @@ span.addLink({ The producer trace may be negatively sampled. The link is still added, with `sampled: false` from the stored span context (same behavior as `previous_trace`). +### `server_request` + +A page load span continues the trace of the server request that rendered its document, if the SDK reads the trace context of that request (e.g. from a `sentry-trace` meta tag) before the span starts. +With streamed HTML, the context can arrive after that. For example, a prerendered shell is served first and the part of the document that the server renders for this request, which carries the context, streams in later. +A started span cannot move to another trace, so the page load span stays in its own trace. + +A `server_request` link connects such a page load span to the server request that rendered its document: + +```ts +pageloadSpan.addLink({ + context: serverRequestSpanContext, // parsed from the late `sentry-trace` value + attributes: { + 'sentry.link.type': 'server_request' + } +}) +``` + +- Add the link only when the page load span could not continue the trace. A page load span that continues the trace of its server request needs no link. +- Add the link to the page load root span, and only while that span is still recording. +- Only use trace context that the server rendered for the current request. Trace context that a cached document carries belongs to the request that produced the cached document. Use `cache_origin` for that relationship. + +The server request may be negatively sampled. The link is still added, with `sampled: false` from the trace context (same behavior as `previous_trace`). + +#### `server_request` or `cache_origin` + +Both types can link a page load span to a server span, but the linked spans have different roles: + +- `server_request`: the linked span handled the request of this page load. It would be the parent of the page load span if its trace context had arrived in time. +- `cache_origin`: the linked span rendered HTML that the server reused from an earlier request. It is never the parent of the page load span. + +A page load span can have both links. For example, the page reuses a prerendered shell (`cache_origin`), and the trace context of the part that the server renders for this request arrives late (`server_request`). + ## Usage Example Adding span links should be possible at span start time, as well as when holding a reference to the span. From dc3ff627a26682c82ae6cccd89309de04dc3bb4f Mon Sep 17 00:00:00 2001 From: s1gr1d <32902192+s1gr1d@users.noreply.github.com> Date: Mon, 9 Nov 2026 17:39:16 +0100 Subject: [PATCH 2/2] improve wording --- .../sdk/telemetry/traces/span-links.mdx | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/develop-docs/sdk/telemetry/traces/span-links.mdx b/develop-docs/sdk/telemetry/traces/span-links.mdx index 7139943a31f8d..ac0ba7e6869fa 100644 --- a/develop-docs/sdk/telemetry/traces/span-links.mdx +++ b/develop-docs/sdk/telemetry/traces/span-links.mdx @@ -143,12 +143,12 @@ Links that are stored in child spans are serialized in `spans[i].links`. Links don't require a special meaning or type but if necessary (e.g. for identifying special links in the product), set the `sentry.link.type` attribute on the link to define the link type. Any string can be used, but these types have predefined meanings: -| `sentry.link.type` | Usage | UI Implications | -|--------------------|--------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------| -| "previous_trace" | Linking e.g. a navigation span to the previous page load span. | Used to query linked traces. Shows a button to go to linked previous trace in the trace explorer. | -| "cache_origin" | Linking a span that uses a cached value (e.g. a cache read, or a page load of a reused page) to the span that produced that value. | Used to navigate from a cache-hit span to the origin trace. | -| "message_origin" | Linking a span that processes a queue message to the span that published the message (e.g. a queue job). | Used to navigate from a consumer span to the producer trace. | -| "server_request" | Linking a page load span to the server request that rendered its document, when the trace context arrived too late to continue it. | Used to navigate from a page load span to the trace of its server request. | +| `sentry.link.type` | Usage | UI Implications | +|--------------------|------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------| +| "previous_trace" | Linking e.g. a navigation span to the previous page load span. | Used to query linked traces. Shows a button to go to linked previous trace in the trace explorer. | +| "cache_origin" | Linking a span that uses a cached value (e.g. a cache read, or a page load of a reused page) to the span that produced that value. | Used to navigate from a cache-hit span to the origin trace. | +| "message_origin" | Linking a span that processes a queue message to the span that published the message (e.g. a queue job). | Used to navigate from a consumer span to the producer trace. | +| "server_request" | Linking a page load span to the server request for its document, when the trace context arrived too late to continue it. | Used to navigate from a page load span to the trace of its server request. | ### `previous_trace` @@ -198,7 +198,7 @@ span.addLink({ ``` One trace can read multiple cache entries. Each cache-read span carries its own link. -In case the entire response is the cached unit (for example, a cached HTML page) the link belongs on the root span instead. +If the entire response is the cached unit (for example, a cached HTML page), the link belongs on the root span of the serving trace instead. To attach the link on a cache hit, the SDK must record trace context at cache-fill time: @@ -216,9 +216,9 @@ A background revalidation (for example, stale-while-revalidate) starts its own t A server can render a page, or a static part of it (a shell), once and reuse the HTML for later requests. Examples are an ISR page or the shell of a partially prerendered page. The page load span of such a page uses HTML that an earlier render produced, so that render is the cache origin of the page load span. -- Send the origin with the reused HTML, in a different field than `sentry-trace`. For example, the Next.js SDK uses a `sentry-cache-origin` meta tag. The render belongs to the request that started it, so the page load span must never continue its trace. -- Add the link at span start, so that `tracesSampler` and `ignoreSpans` can see it. -- Set [`page.server_rendering.type`](https://conventions.sentry.dev/attributes/page/#page-server_rendering-type) on the page load span. +- Send the origin with the reused HTML, but not as `sentry-trace`. Every visitor gets the same HTML, so with `sentry-trace` every visitor would continue the trace of one earlier request. For example, the Next.js SDK uses a `sentry-cache-origin` meta tag. +- Add the link at span start. +- If the SDK knows how the server rendered the page, set [`page.server_rendering.type`](https://conventions.sentry.dev/attributes/page/#page-server_rendering-type) at span start. Then `tracesSampler` and `ignoreSpans` can use it. - If the server renders the other parts of the page for the current request (`partially_static`), the page load span continues the trace of that request as usual. The `cache_origin` link points only to the render of the reused part. ### `message_origin` @@ -252,11 +252,11 @@ The producer trace may be negatively sampled. The link is still added, with `sam ### `server_request` -A page load span continues the trace of the server request that rendered its document, if the SDK reads the trace context of that request (e.g. from a `sentry-trace` meta tag) before the span starts. -With streamed HTML, the context can arrive after that. For example, a prerendered shell is served first and the part of the document that the server renders for this request, which carries the context, streams in later. +A page load span continues the trace of the server request for its document, if the SDK reads the trace context of that request (e.g. from a `sentry-trace` meta tag) before the span starts. +With streamed HTML, the context can arrive later. For example, the server first sends a prerendered shell. The part that the server renders for this request comes later, and it carries the context. A started span cannot move to another trace, so the page load span stays in its own trace. -A `server_request` link connects such a page load span to the server request that rendered its document: +A `server_request` link connects such a page load span to the server request for its document: ```ts pageloadSpan.addLink({ @@ -269,15 +269,15 @@ pageloadSpan.addLink({ - Add the link only when the page load span could not continue the trace. A page load span that continues the trace of its server request needs no link. - Add the link to the page load root span, and only while that span is still recording. -- Only use trace context that the server rendered for the current request. Trace context that a cached document carries belongs to the request that produced the cached document. Use `cache_origin` for that relationship. +- Use only the trace context of the request for this document. Trace context in a part of the page that the server reused belongs to an earlier request. Use `cache_origin` for it. -The server request may be negatively sampled. The link is still added, with `sampled: false` from the trace context (same behavior as `previous_trace`). +The server request may be negatively sampled. Add the link anyway, with `sampled: false` from the trace context (same behavior as `previous_trace`). #### `server_request` or `cache_origin` Both types can link a page load span to a server span, but the linked spans have different roles: -- `server_request`: the linked span handled the request of this page load. It would be the parent of the page load span if its trace context had arrived in time. +- `server_request`: the linked span handled the request for the document of this page load. It would be the parent of the page load span if its trace context had arrived in time. - `cache_origin`: the linked span rendered HTML that the server reused from an earlier request. It is never the parent of the page load span. A page load span can have both links. For example, the page reuses a prerendered shell (`cache_origin`), and the trace context of the part that the server renders for this request arrives late (`server_request`).