Skip to content

feat: add sb-request-id logging#1041

Open
ferhatelmas wants to merge 1 commit intomasterfrom
ferhat/request-id
Open

feat: add sb-request-id logging#1041
ferhatelmas wants to merge 1 commit intomasterfrom
ferhat/request-id

Conversation

@ferhatelmas
Copy link
Copy Markdown
Member

@ferhatelmas ferhatelmas commented Apr 22, 2026

What kind of change does this PR introduce?

feat

What is the current behavior?

Supabase specific request id isn't supported.

What is the new behavior?

Supabase specific request id sb-request-id header is read and propagated downstream and serialized as request_id at top level for logflare.

Additional context

Increased coverage a bit when applicable.
Refactored a few places not using log schema.
Also propagate the existing reqId where missed.
Fixed any usage in touched files except db to keep scope smaller, related to #922

Copilot AI review requested due to automatic review settings April 22, 2026 19:19
@ferhatelmas ferhatelmas requested a review from a team as a code owner April 22, 2026 19:19
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for capturing Supabase’s sb-request-id header, propagating it through request context, queue jobs/events, and structured logging so downstream operations can be correlated using the Supabase request identifier.

Changes:

  • Introduces requestContext + getSbReqId* helpers to extract sb-request-id and expose it as request.sbReqId.
  • Threads sbReqId through storage DB context (StorageKnexDB), queue/event payloads, and many logSchema calls (including Logflare mapping to request_id).
  • Adds/updates tests across queue, migrations, JWKS, TUS lifecycle, and webhooks to validate propagation.

Reviewed changes

Copilot reviewed 60 out of 60 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/test/webhooks.test.ts Adds coverage ensuring reqId (trace) stays distinct from sbReqId in queued webhook payloads.
src/test/tenant-jwks.test.ts Ensures JWKS roll queue payload carries sbReqId.
src/test/admin-migrations.test.ts Ensures admin migrations endpoints pass sbReqId into migration scheduling.
src/storage/uploader.ts Propagates sbReqId into uploader error/event logs.
src/storage/storage.ts Propagates sbReqId into storage logs/events.
src/storage/scanner/scanner.ts Adds sbReqId to scanner event payload/log context.
src/storage/object.ts Adds sbReqId propagation across object operations/events/logging.
src/storage/events/pgboss/upgrade-v10.ts Logs pg-boss upgrade failures with sbReqId.
src/storage/events/pgboss/upgrade-v10.test.ts Tests sbReqId is included in upgrade error logs.
src/storage/events/pgboss/move-jobs.ts Logs move-jobs errors with sbReqId.
src/storage/events/pgboss/move-jobs.test.ts Tests sbReqId presence in move-jobs error logs.
src/storage/events/objects/object-admin-delete.ts Threads sbReqId through admin delete logs (including dispose failures).
src/storage/events/objects/object-admin-delete-all-before.ts Threads sbReqId through admin delete-all-before logs (including dispose failures).
src/storage/events/objects/backup-object.ts Threads sbReqId through backup/delete logs (including dispose failures).
src/storage/events/migrations/run-migrations.ts Adds sbReqId to migrations event logs.
src/storage/events/migrations/run-migrations.test.ts Extends tests asserting sbReqId is logged on success/failure.
src/storage/events/migrations/reset-migrations.ts Threads sbReqId into reset logs and follow-up job scheduling.
src/storage/events/migrations/reset-migrations.test.ts Adds tests for sbReqId propagation in reset flow.
src/storage/events/lifecycle/webhook.ts Extends webhook payload typing + logs to include sbReqId.
src/storage/events/lifecycle/bucket-deleted.ts Passes sbReqId into bucket-deleted handling context.
src/storage/events/jwks/jwks-roll-url-signing-key.ts Includes sbReqId in JWKS roll logs.
src/storage/events/jwks/jwks-roll-url-signing-key.test.ts Adds tests for sbReqId in JWKS roll success/failure logs.
src/storage/events/jwks/jwks-create-signing-secret.ts Includes sbReqId in JWKS create logs.
src/storage/events/base-event.ts Threads reqId/sbReqId into storage creation + webhook send error log context.
src/storage/database/knex.ts Adds sbReqId to StorageKnexDB state.
src/storage/database/adapter.ts Extends DB interfaces/options to include sbReqId.
src/internal/queue/queue.ts Extracts sbReqId from job payload and includes it in queue-task error logs.
src/internal/queue/queue.test.ts Adds coverage for sbReqId extraction (top-level and nested webhook payload).
src/internal/queue/index.ts Re-exports queue constants (incl. SYSTEM_TENANT).
src/internal/queue/event.ts Adds sbReqId to BasePayload and queue error logs.
src/internal/queue/constants.ts Introduces SYSTEM_TENANT placeholder for fleet/system queue jobs.
src/internal/monitoring/request-context.ts Adds helpers to extract sbReqId from headers and job payloads.
src/internal/monitoring/request-context.test.ts Tests header/payload extraction behavior.
src/internal/monitoring/logger.ts Extends log schema types + allowlists sb-request-id header.
src/internal/monitoring/logger.test.ts Adds test ensuring Logflare transport hooks are wired when enabled.
src/internal/monitoring/logflare.ts Maps sbReqId into Logflare request_id.
src/internal/monitoring/logflare.test.ts Adds unit tests for Logflare payload shaping and error handler.
src/internal/monitoring/index.ts Re-exports request-context helpers.
src/internal/database/migrations/migrate.ts Threads sbReqId through fleet migration/reset scheduler + lock logging.
src/internal/database/migrations/migrate.test.ts Adds tests for sbReqId propagation into fleet scheduler logs/jobs.
src/internal/auth/jwks/generator.ts Threads sbReqId through JWKS generator logs and jobs.
src/http/routes/tus/lifecycle.ts Uses logSchema for TUS lifecycle warnings/errors and includes sbReqId.
src/http/routes/tus/lifecycle.test.ts Adds tests for sbReqId in TUS lifecycle logging paths.
src/http/routes/tus/index.ts Threads sbReqId into raw TUS upload context; exports publicRoutes for testing.
src/http/routes/tus/index.test.ts Tests sbReqId is present on public TUS route raw upload context.
src/http/routes/admin/queue.ts Sends sbReqId + SYSTEM_TENANT for fleet queue maintenance tasks.
src/http/routes/admin/queue.test.ts Adds tests asserting sbReqId is passed into scheduled queue tasks.
src/http/routes/admin/objects.ts Converts orphan stream error logging to logSchema with sbReqId.
src/http/routes/admin/migrations.ts Passes sbReqId into fleet migrate/reset helpers.
src/http/routes/admin/jwks.ts Passes sbReqId into JWKS roll and generator; updates generator call signature.
src/http/plugins/tracing.ts Adds sbReqId to tracing mode error logs.
src/http/plugins/storage.ts Adds sbReqId to StorageKnexDB construction for request-scoped storage.
src/http/plugins/request-context.ts New plugin extracting sbReqId from headers onto the Fastify request.
src/http/plugins/request-context.test.ts Tests request-context behavior with/without header.
src/http/plugins/log-request.ts Uses request logger as sink for otel/log metadata errors and includes sbReqId in request logs.
src/http/plugins/log-request.test.ts Adds test ensuring sbReqId appears in emitted request log lines.
src/http/plugins/index.ts Exports the new requestContext plugin.
src/http/plugins/db.ts Adds sbReqId to DB dispose error logs.
src/app.ts Registers requestContext plugin in the main app.
src/admin-app.ts Registers requestContext plugin in the admin app.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/http/routes/admin/jwks.ts
Comment thread src/http/plugins/request-context.ts
@coveralls
Copy link
Copy Markdown

coveralls commented Apr 22, 2026

Coverage Report for CI Build 24802340028

Coverage increased (+1.3%) to 71.253%

Details

  • Coverage increased (+1.3%) from the base build.
  • Patch coverage: 8 uncovered changes across 6 files (80 of 88 lines covered, 90.91%).
  • 6 coverage regressions across 4 files.

Uncovered Changes

File Changed Covered %
src/http/plugins/log-request.ts 4 2 50.0%
src/http/routes/admin/objects.ts 2 0 0.0%
src/http/plugins/tracing.ts 1 0 0.0%
src/http/routes/tus/lifecycle.ts 9 8 88.89%
src/internal/database/migrations/migrate.ts 16 15 93.75%
src/storage/events/jwks/jwks-create-signing-secret.ts 1 0 0.0%

Coverage Regressions

6 previously-covered lines in 4 files lost coverage.

File Lines Losing Coverage Coverage
src/http/routes/admin/objects.ts 2 28.85%
src/internal/queue/event.ts 2 62.1%
src/http/plugins/signals.ts 1 85.71%
src/http/routes/admin/jwks.ts 1 98.89%

Coverage Stats

Coverage Status
Relevant Lines: 9729
Covered Lines: 7330
Line Coverage: 75.34%
Relevant Branches: 5431
Covered Branches: 3472
Branch Coverage: 63.93%
Branches in Coverage %: Yes
Coverage Strength: 377.86 hits per line

💛 - Coveralls

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 60 out of 60 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 67 out of 67 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/http/routes/admin/migrations.ts Outdated
Also propagate the existing `reqId` where missed.

Signed-off-by: ferhat elmas <elmas.ferhat@gmail.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 67 out of 67 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

3 participants