feat: propagate request_id through pgSettings and metering context#1205
Merged
Conversation
- graphile.ts: add request.id to pgSettings for both authenticated and
anonymous requests (sourced from req.requestId, already generated by
request-logger middleware via X-Request-Id header or crypto.randomUUID)
- llm-api.ts: add request.id to getPgSettings() for REST LLM endpoints
- metering.ts: add requestId to MeteringContext, include in record_usage
billing metadata for correlation
- metering-plugin.ts: extract request.id from pgSettings into context
Available in SQL via current_setting('request.id', true). Enables
distributed tracing across Express → GraphQL → billing → inference log.
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Propagates the per-request
request_id(already generated byrequest-logger.tsmiddleware viaX-Request-Idheader orcrypto.randomUUID()) into PostgreSQL session settings and the LLM metering pipeline.Changes:
graphile.ts: addsrequest.idto pgSettings for both authenticated and anonymous GraphQL requestsllm-api.ts: addsrequest.idtogetPgSettings()for REST LLM endpointsmetering.ts: addsrequestIdtoMeteringContextinterface; includesrequest_idinrecord_usage()billing metadata for both embed and chat operationsmetering-plugin.ts: extractsrequest.idfrom pgSettings into the metering contextAfter this change,
request.idis available in SQL viacurrent_setting('request.id', true)— enabling distributed tracing and correlation across Express → GraphQL → billing → inference log layers.Companion PR: constructive-io/constructive-db#1276 (adds
request_id uuidcolumn toinference_log_module)Review & Testing Checklist for Human
request.idappears in pgSettings during a real GraphQL request (check viacurrent_setting('request.id', true)in a PG function or trigger)record_usagemetadata includesrequest_id— check the billing ledger jsonb after an LLM callNotes
No new dependencies. The
request_idgeneration already existed inrequest-logger.ts— this PR just wires it through to pgSettings and metering. Therequest.idpgSetting is the standard Constructive convention (matchingjwt.claims.*pattern).Link to Devin session: https://app.devin.ai/sessions/2b5a29d83d3f478e8d3d972653b4879c
Requested by: @pyramation