@@ -30,33 +30,65 @@ export type Fetch = typeof fetch
3030 *
3131 * Enables distributed tracing across Supabase services using W3C Trace Context
3232 * and OpenTelemetry standards. When enabled, the SDK automatically attaches
33- * trace context headers (traceparent, tracestate, baggage) to outgoing requests
34- * to Supabase domains.
33+ * trace context headers (`traceparent`, `tracestate`, `baggage`) to outgoing
34+ * requests to Supabase domains. The resulting `trace_id` appears in API
35+ * Gateway and Edge Function logs, so logs forwarded through Log Drains can
36+ * be correlated back to the originating client-side span.
37+ *
38+ * Requires `@opentelemetry/api` to be installed in the consuming application.
39+ * If it is not installed, or there is no active context at request time,
40+ * propagation silently no-ops.
41+ *
42+ * @example Enable with defaults
43+ * ```ts
44+ * const supabase = createClient(url, key, {
45+ * tracePropagation: { enabled: true },
46+ * })
47+ * ```
3548 *
3649 * @see https://www.w3.org/TR/trace-context/
3750 * @see https://opentelemetry.io/docs/concepts/context-propagation/
51+ * @see https://supabase.com/docs/guides/telemetry/client-side-tracing
3852 */
3953export interface TracePropagationOptions {
4054 /**
4155 * Enable trace propagation. Disabled by default.
4256 *
4357 * When enabled, automatically detects and propagates active trace context
4458 * from the OpenTelemetry API to outgoing Supabase requests. Trace context
45- * is only propagated to Supabase domains (*.supabase.co, *.supabase.in,
46- * localhost) for security.
59+ * is only propagated to Supabase domains (` *.supabase.co`, ` *.supabase.in` ,
60+ * ` localhost` ) for security — third-party hosts never receive trace headers .
4761 *
4862 * @default false
63+ *
64+ * @example
65+ * ```ts
66+ * const supabase = createClient(url, key, {
67+ * tracePropagation: { enabled: true },
68+ * })
69+ * ```
4970 */
5071 enabled ?: boolean
5172
5273 /**
5374 * Respect upstream sampling decisions.
5475 *
55- * When true, trace context will not be propagated if the upstream trace
56- * indicates non-sampling (sampled flag = 0 in traceparent header).
57- * This helps reduce overhead when traces are not being collected.
76+ * When true (the default), trace context is not propagated if the upstream
77+ * trace indicates non-sampling (sampled flag = `0` in the `traceparent`
78+ * header). This avoids overhead when traces are being recorded but dropped.
79+ *
80+ * Set to `false` to always propagate, regardless of the sampling decision
81+ * — useful when you want every Supabase request tagged with a `trace_id`
82+ * for log correlation, even if the trace itself will not be exported.
5883 *
5984 * @default true
85+ *
86+ * @example Always propagate, ignore sampling
87+ * ```ts
88+ * const supabase = createClient(url, key, {
89+ * tracePropagation: { enabled: true, respectSamplingDecision: false },
90+ * })
91+ * ```
6092 */
6193 respectSamplingDecision ?: boolean
6294}
@@ -215,22 +247,49 @@ export type SupabaseClientOptions<SchemaName> = {
215247 * Enable OpenTelemetry / W3C trace context propagation to Supabase services.
216248 *
217249 * Disabled by default. Pass `true` for the common case (auto-detect an
218- * active OTel context and inject `traceparent` / `tracestate` / `baggage`
219- * headers) or an object for fine-grained control.
250+ * active OpenTelemetry context and inject `traceparent` / `tracestate` /
251+ * `baggage` headers) or an object for fine-grained control.
220252 *
221253 * Requires `@opentelemetry/api` to be installed in your application; if
222- * not present, the SDK silently no-ops.
254+ * not present, the SDK silently no-ops. Trace headers are only attached
255+ * to requests targeting Supabase domains, so third-party hosts called
256+ * through a custom `fetch` are never tagged.
223257 *
224- * @example
258+ * The resulting `trace_id` appears in Supabase logs (API Gateway, Edge
259+ * Functions), letting you correlate client-side spans with server-side
260+ * log entries — including logs forwarded via Log Drains.
261+ *
262+ * @example Shorthand — opt in with defaults
263+ * ```ts
264+ * import { createClient } from '@supabase/supabase-js'
265+ *
266+ * const supabase = createClient(url, key, { tracePropagation: true })
267+ * ```
268+ *
269+ * @example With an active OpenTelemetry span
225270 * ```ts
226- * // Shorthand — opt in with defaults.
227- * createClient(url, key, { tracePropagation: true })
271+ * import { createClient } from '@supabase/supabase-js'
272+ * import { trace } from '@opentelemetry/api'
228273 *
229- * // Advanced — always propagate, even for non-sampled traces.
230- * createClient(url, key, {
274+ * const supabase = createClient(url, key, { tracePropagation: true })
275+ * const tracer = trace.getTracer('my-app')
276+ *
277+ * await tracer.startActiveSpan('fetch-users', async (span) => {
278+ * // Request carries the active trace context.
279+ * const { data, error } = await supabase.from('users').select('*')
280+ * span.end()
281+ * })
282+ * ```
283+ *
284+ * @example Advanced — always propagate, even for non-sampled traces
285+ * ```ts
286+ * const supabase = createClient(url, key, {
231287 * tracePropagation: { enabled: true, respectSamplingDecision: false },
232288 * })
233289 * ```
290+ *
291+ * @see https://supabase.com/docs/guides/telemetry/client-side-tracing
292+ * @see https://www.w3.org/TR/trace-context/
234293 */
235294 tracePropagation ?: TracePropagationOptions | boolean
236295}
0 commit comments