Skip to content

feat(observability): record http.client.request.duration and log under lowercase names in every client - #916

Open
Tr00d wants to merge 1 commit into
masterfrom
refactor/telemetry-contract
Open

Tr00d wants to merge 1 commit into
masterfrom
refactor/telemetry-contract

Conversation

@Tr00d

@Tr00d Tr00d commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

What changed

Finishes aligning the SDK's telemetry with the Supabase OTel contract before 8.15.0 ships. #840 did it for Postgrest and #842 lowercased the Auth, Storage and Functions source names. This PR does the rest.

  • Lowercase log categories. Realtime now logs under supabase.realtime instead of Supabase.Realtime. The category is defined once (Supabase.Realtime.RealtimeLogging.Category, internal) and used by the socket, the client, the channel and Supabase.Client. Realtime now exposes its internals to the Supabase assembly for this. The value is a const, so it is compiled into Supabase.dll and creates no runtime binding to a Realtime internal. The SupabaseOptions.LoggerFactory doc lists the new category.
  • One request-duration metric. Auth, Storage and Functions now record http.client.request.duration, the same instrument Postgrest records. Each keeps its own meter (supabase.gotrue, supabase.storage, supabase.functions), so the meter scope still names the product. Every measurement carries http.request.method, server.address, server.port and url.scheme, plus http.response.status_code when there was a response and error.type when the request failed. Functions keeps faas.invoked_name. url.path is gone from these metrics, as it is from Postgrest's.
  • Shared HTTP-client metric in Core. The four clients would have built the same tags, so the instrument and its tags now live once in Supabase.Core.Diagnostics.HttpClientRequestDuration (internal). Each product creates it on its own meter with HttpClientRequestDuration.On(Meter) and appends its own attributes to TagsOf(...). Instrumentation.SecondsSince (internal) replaces the four copies of the elapsed-seconds calculation.
  • Zero-cost guard restored. feat(postgrest): align client span and metric with the Supabase OTel contract #840 removed the Enabled check from PostgrestInstrumentation.RecordRequest, so a TagList was built for every request even without a listener. All four products now build tags only when the instrument is enabled, under the same guard: if (RequestDuration.Enabled) RequestDuration.Record(...).
  • Docs. The *Diagnostics XML docs no longer say "(case-sensitive) source names". The OpenTelemetry SDK matches AddSource and AddMeter names without regard to case, so that claim was wrong for the main use. The docs still say to use the constant rather than a string literal. The Auth, Storage and Functions READMEs describe the new metric.

Things to review

  • Storage transfer metrics are unchanged. supabase.storage.transfer.duration and supabase.storage.transfer.size measure a whole upload or download, which can span many HTTP requests (a TUS upload is one span for all its chunks). They are not single HTTP requests, so they keep their names and their attributes, including url.path and storage.transfer.direction.
  • The guard is if (Enabled) Record(...), not if (!Enabled) return;. The two do the same thing, but Stryker turns the early return; into an equivalent mutant: removing it changes nothing a test can see. That is why feat(postgrest): align client span and metric with the Supabase OTel contract #840 dropped the guard. In the positive form, every mutant changes what a listener receives, so the tests kill them all.
  • Auth, Storage and Functions metrics lose url.path. The OTel HTTP client metric does not define it, and on these clients the path holds user ids, factor ids and object names, which are high-cardinality and can identify someone. The spans still carry the path.
  • Realtime log messages change prefix. BackgroundWorkEvent prefixes the component, so messages now read supabase.realtime: connected.
  • Span names and span attributes are unchanged for Auth, Storage and Functions.
  • Whitespace. The gate formats changed files in full, so StorageInstrumentation.cs, FunctionsInstrumentation.cs and SupabaseDiagnostics.cs moved to file-scoped namespaces. Most of their diff is indentation; git diff -w shows the real change.
  • New tests outside the metric rename. TransferMetricsTests (Storage) pins that each transfer metric records when only it is listened to, and that a failed transfer carries error.type. They kill surviving mutants in the transfer guard that the reformat brought into the diff. SupabaseDiagnosticsTests pins SourceNames, which had no hermetic test.

Verification

  • Changed-lines coverage (changed-lines-coverage.py): 100% for every touched package. Core 19/19, Postgrest 8/8, Functions 19/19, Storage 41/41, Realtime 7/7, Supabase 7/7, Gotrue 3/3.
  • Stryker on HttpClientRequestDuration.cs, Instrumentation.cs, PostgrestInstrumentation.cs, GotrueInstrumentation.cs, StorageInstrumentation.cs and FunctionsInstrumentation.cs: 0 survived and 0 uncovered mutants in these files, not only on changed lines. Core scored 100% (22 tested). Storage: 23 killed, 6 timeouts. Postgrest: 24 killed. Functions: 5 killed. Gotrue: 3 killed. The rest are compile errors or ignored. SupabaseDiagnostics.cs and RealtimeLogging.cs hold only constants and produce no testable mutants.
  • gate.sh per package: INCOMPLETE for Core, Gotrue, Storage, Functions, Postgrest, Realtime and Supabase. Build (at baseline), format, inner loop, public API declared, vulnerability scan and public API diff all PASS. E2E and coverage were skipped because the local stack was down, so CI is the gate. No public API changes.
Package Inner loop
Core 128 passed
Gotrue 938 passed
Storage 758 passed
Functions 71 passed
Postgrest 239 passed
Realtime 379 passed
Supabase 117 passed

Telemetry changes in 8.15.0

Every name the SDK emits telemetry under is now lowercase. Auth, Database, Storage and Functions record the standard OpenTelemetry http.client.request.duration metric.

ActivitySource and Meter names (*Diagnostics.SourceName)

Client Before After
Auth Supabase.Gotrue supabase.gotrue
Database Supabase.Postgrest supabase.postgrest
Storage Supabase.Storage supabase.storage
Functions Supabase.Functions supabase.functions

Log categories (SupabaseOptions.LoggerFactory)

Client Before After
Auth Supabase.Gotrue supabase.gotrue
Database Supabase.Postgrest supabase.postgrest
Storage Supabase.Storage supabase.storage
Functions Supabase.Functions supabase.functions
Realtime Supabase.Realtime supabase.realtime

Background-work messages start with the category, so they now read supabase.gotrue: ... and supabase.realtime: ....

Metrics

Client Before After
Auth supabase.gotrue.http.request.duration http.client.request.duration on the supabase.gotrue meter
Database supabase.postgrest.http.request.duration http.client.request.duration on the supabase.postgrest meter
Storage (other than file transfers) supabase.storage.http.request.duration http.client.request.duration on the supabase.storage meter
Functions supabase.functions.invoke.duration http.client.request.duration on the supabase.functions meter

supabase.storage.transfer.duration and supabase.storage.transfer.size are unchanged.

Attributes of http.client.request.duration, for every client:

  • Added: server.port and url.scheme.
  • Removed: url.path. The metric carries no URL.
  • Unchanged: http.request.method, server.address, http.response.status_code, error.type, and faas.invoked_name on Functions.

Database span and metric attributes

  • db.operation → supabase.postgrest.operation.
  • A count (HEAD) is reported as select instead of count.
  • New: supabase.postgrest.table on table calls, and supabase.postgrest.function on RPC calls.
  • url.full on the span now includes the query string with every value replaced by REDACTED, except the values of select, order, limit and offset. Before, the query string was dropped.

Recompile if you use the constants. GotrueDiagnostics.SourceName, PostgrestDiagnostics.SourceName, StorageDiagnostics.SourceName and FunctionsDiagnostics.SourceName are const, so an assembly compiled against an earlier version keeps the old name until it is recompiled. If you registered a source, meter or log category as a string literal, or filter on a metric name, update the string.

…r lowercase names in every client

Auth, Storage and Functions now record the OpenTelemetry
http.client.request.duration metric on their own meters, with the same
HTTP client attributes Postgrest emits and no URL. The instrument and its
attributes live once in Core. Every client builds the attributes only when
something listens. Realtime logs under supabase.realtime, defined once.
The Diagnostics docs no longer call the source names case-sensitive.
@Tr00d
Tr00d marked this pull request as ready for review November 26, 2026 13:22

This branch has not been deployed

No deployments
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.

1 participant