feat(zero-client): add query lifecycle hooks to ZeroOptions#5493
Open
Karavil wants to merge 2 commits intorocicorp:mainfrom
Open
feat(zero-client): add query lifecycle hooks to ZeroOptions#5493Karavil wants to merge 2 commits intorocicorp:mainfrom
Karavil wants to merge 2 commits intorocicorp:mainfrom
Conversation
Adds opt-in hooks for observing query materialization events, enabling client-side telemetry (e.g. OpenTelemetry spans). * Add ZeroQueryHooks type with onQueryMaterializeClient and onQueryMaterialize callbacks * Add hooks option to ZeroOptions interface * Wire hooks through Zero constructor to QueryManager * Call hooks in QueryManager.addMetric() with try/catch * Export new types from public API * Add tests for hook invocation, error isolation, and selectivity
|
Someone is attempting to deploy a commit to the Rocicorp Team on Vercel. A member of the Team first needs to authorize it. |
…rialize The client-side materialization metric fires after the IVM pipeline is already built, making it redundant. The end-to-end hook covers the useful case (full round trip timing with AST details). Also removes unnecessary ast guard: ast is always present when metric is query-materialization-end-to-end per ClientMetricMap.
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.
Query Lifecycle Hooks
Adds opt-in hooks to
ZeroOptionsfor observing query materialization events on the client. We use these to create OpenTelemetry spans for every Zero query materialization, sent to BetterStack for monitoring.We've been running this as a bun patch on
@rocicorp/zero@0.25.11in production for a few weeks. Upstreaming removes our patch maintenance burden and makes this available to anyone who wants client-side query telemetry.How It Works
Both hooks are wrapped in try/catch internally, so consumer errors never break query execution. Zero overhead when no hooks are provided (optional chaining short-circuits).
Usage
This gives us spans like:
Changes
Tests
Covers:
onQueryMaterializeClientfires for client materialization metric with correct{id}onQueryMaterializefires for end-to-end metric with correct{id, ast, durationMs, name}query-update-client) don't fire any hook