getTraceContext
The trace the current request belongs to — continued from the incoming
W3C traceparent when there was one, originated by the runtime
otherwise; in observe/dev builds, merged with the installed provider's
answer (OBSERVE.server.trace). Same object for every read within the
request, direct server-function calls included. For a render outside a
request scope, the render's own trace, read within it (under its owner).
undefined outside both, and on the client. Forward it downstream from a
server function with getTraceContext()?.entries.traceparent.
Import
import { getTraceContext } from "@solidjs/web";Type signature
function getTraceContext(): TraceContext | undefined;Examples
await fetch(url, { headers: { ...getTraceContext()?.entries } });Learn more
- Read trusted request context
- Follow a request into the browser
- Mutations and responses
- Middleware and API routes
Related types
TraceContext
The trace the current request belongs to — continued from the incoming
W3C traceparent when there was one, originated by the runtime
otherwise. Read with getTraceContext().
interface TraceContext { traceId: string; spanId: string; parentId?: string; sampled?: boolean; state?: string; baggage?: string; entries: Record<string, string>;}traceId
- Type:
string
32 lowercase hex — the whole trace.
spanId
- Type:
string
16 lowercase hex — this request's span: runtime-generated unless a provider supplied it.
parentId
- Type:
string
The incoming parent span, when the request continued a trace.
sampled
- Type:
boolean
The incoming traceparent sampled flag (bit 0); undefined when the runtime originated.
state
- Type:
string
The incoming tracestate header, verbatim.
baggage
- Type:
string
The incoming baggage header, verbatim.
entries
- Type:
Record<string, string>
Named entries handed to the browser on the first response — emitted
both as Server-Timing entries (<name>;desc="<value>") and, for HTML
documents, as <meta name="<name>" content="<value>"> in the shell.
The runtime fills traceparent; a provider adds its vendor pair
(sentry-trace, baggage). Also what application code forwards
downstream: fetch(url, { headers: { traceparent: entries.traceparent } }).
TraceProvider
An observer's answer for the trace a request belongs to, merged over the
runtime's default derivation: fields it returns replace the derived
ones (traceId/spanId from an APM's active span), its entries merge
by name over the runtime's. Called once per request (or per render, for
a render outside a request scope — request is then undefined), at
shell flush or the first getTraceContext(), whichever comes first.
Return undefined to leave the derivation alone.
type TraceProvider = ( request: Request | undefined) => Partial<TraceContext> | undefined;