Skip to content

refactor(supabase)!: require a traceContextProvider in TracePropagationOptions - #1882

Merged
spydon merged 1 commit into
mainfrom
refactor/trace-propagation-provider-required
Sep 24, 2026
Merged

spydon merged 1 commit into
mainfrom
refactor/trace-propagation-provider-required

Conversation

@spydon

@spydon spydon commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

TracePropagationOptions had two switches that had to agree, which left two dead states: enabled: true without a provider sent nothing, and a provider with enabled: false was never called. enabled was read exactly once, to decide whether to wrap the HTTP client, so it could not be toggled at runtime anyway.

This collapses the two into one:

  • TracePropagationOptions.enabled is gone and traceContextProvider is required.
  • The tracePropagationOptions parameter on SupabaseClient and Supabase.initialize is nullable and defaults to null, which means off.
  • TracePropagationClient no longer warns about a missing provider, since that state cannot be constructed anymore. The malformed traceparent warning is unchanged.

Breaking change

supabase and supabase_flutter are at 3.0.0-dev.7, so this lands before 3.0.0 ships. MIGRATION.md gets a section under v3 and sdk-compliance.yaml drops the removed symbol.

// Before
tracePropagationOptions: TracePropagationOptions(
  enabled: true,
  traceContextProvider: () => TraceContext.fromCarrier(carrier),
),

// After
tracePropagationOptions: TracePropagationOptions(
  traceContextProvider: () => TraceContext.fromCarrier(carrier),
),

Testing

  • melos analyze and melos format are clean.
  • dart test in packages/supabase and flutter test in packages/supabase_flutter pass. The test for the warning on a missing provider is removed with the state it covered, and the disabled-client test now passes no options.
  • The SDK compliance symbol, drift and schema checks pass locally against the pinned capability-matrix-v1.9.0 tooling.

Closes SDK-1938.

Summary by CodeRabbit

  • Changes
    • Trace propagation is now enabled by providing a context provider in TracePropagationOptions; the enabled flag is no longer available.
    • Trace propagation options are optional when initializing Supabase clients. Omitting them sends no trace headers; providing them enables propagation.
    • The migration guide explains how to update existing configurations.

…onOptions

TracePropagationOptions had two switches that had to agree, which left
two dead states: enabled without a provider sent nothing, and a provider
with enabled set to false was never called. The enabled flag was read
once, to decide whether to wrap the HTTP client, so it could not be
toggled at runtime anyway.

The flag is gone and traceContextProvider is required. The
tracePropagationOptions parameter on SupabaseClient and
Supabase.initialize is nullable, with null meaning off.
@spydon
spydon requested a review from a team as a code owner September 24, 2026 07:17
@coderabbitai

coderabbitai Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: supabase/supabase-flutter/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: f9466610-c48d-4257-b5d3-d573f6ad8f65

📥 Commits

Reviewing files that changed from the base of the PR and between afb0772 and f971e8e.

📒 Files selected for processing (7)
  • MIGRATION.md
  • packages/supabase/lib/src/supabase_client.dart
  • packages/supabase/lib/src/trace_http_client.dart
  • packages/supabase/lib/src/trace_propagation.dart
  • packages/supabase/test/trace_propagation_test.dart
  • packages/supabase_flutter/lib/src/supabase.dart
  • sdk-compliance.yaml
💤 Files with no reviewable changes (1)
  • sdk-compliance.yaml

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

Trace propagation now requires a context provider when options are supplied. SupabaseClient and Supabase.initialize accept nullable options; when options are omitted, the client sends no trace headers.

Changes

Trace propagation options

Layer / File(s) Summary
Required trace context provider
packages/supabase/lib/src/trace_propagation.dart, packages/supabase/lib/src/trace_http_client.dart
TracePropagationOptions requires a non-null traceContextProvider and no longer has an enabled field. TracePropagationClient invokes the provider directly.
Nullable options and migration
packages/supabase/lib/src/supabase_client.dart, packages/supabase_flutter/lib/src/supabase.dart, packages/supabase/test/trace_propagation_test.dart, MIGRATION.md, sdk-compliance.yaml
The client constructors accept nullable options and wrap the base HTTP client when options are supplied. Tests, migration guidance, and compliance symbols reflect the updated API.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Suggested reviewers: grdsdev

Merge Risk: ⚪ Minimal · up to f971e

The documented v3 API change is consistent across the client and initialization paths, and no incompatible in-repository callers were found. No actionable merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main API change: TracePropagationOptions now requires a traceContextProvider.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@spydon
spydon merged commit d69f644 into main Sep 24, 2026
45 checks passed
@spydon
spydon deleted the refactor/trace-propagation-provider-required branch September 24, 2026 07:38
spydon added a commit that referenced this pull request Sep 25, 2026
…1887)

## Summary

Trace propagation and request ids had no documentation outside their
dartdocs. This adds a "Request ids and tracing" section to the
`supabase_flutter` README, plus a short pointer to it from the
`supabase` README. It covers the current API: the options shape from
#1882 and `requestId` from #1885.

The section starts with the request id, because most people need it and
it needs no setup, and covers tracing after it:

- **Request id on a failure**: `requestId` on `SupabaseException`, what
to do with it (log explorer, support), that `toString()` includes it,
the `sb-request-id`/`x-request-id` fallback, and when it is `null`.
- **Trace propagation**: opt-in through `TracePropagationOptions`, with
recipes for Sentry (`formatAsW3CHeader(span.toSentryTrace())` plus
baggage), OpenTelemetry (the global propagator into a map, then
`TraceContext.fromCarrier`), and `TraceContext.w3c` for other tracing
tools.
- Which hosts receive the headers (third-party hosts never do), that
realtime broadcasts over HTTP carry them but the WebSocket does not, and
how sampling works with `respectSamplingDecision`.

## Testing

The Sentry, OpenTelemetry, `TraceContext.w3c` and `requestId` snippets
were compiled in a scratch project against this branch's packages,
`sentry` 9.22.0 and `opentelemetry` 0.18.11, and `dart analyze` reports
no issues.

## Not in this PR

The ticket also asks for an entry in the Dart reference spec in
supabase/supabase. That repository only has `supabase_dart_v1.yml` and
`supabase_dart_v2.yml`, and both features only exist in 3.0.0, so the
entry has to go into a v3 spec once one exists.

Part of SDK-1939.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Documentation**
* Added guidance on using request IDs from client exceptions to locate
corresponding server logs across authentication, database, storage, and
functions requests.
* Documented optional trace propagation for correlating requests with
traces, including Sentry and OpenTelemetry examples.
* Clarified how request IDs are selected or may be unavailable, and
described trace-header validation, destination restrictions, and
sampling behavior.
* Noted that traced requests may forward trace headers across redirects
to another host on VM clients.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants