Conversation
serikjensen
approved these changes
Mar 12, 2026
Made-with: Cursor
jeffredodd
approved these changes
Mar 13, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an SDK-level observability hook (errors + performance metrics) intended for integration with external monitoring tools, with built-in PII sanitization before data leaves the SDK.
Changes:
- Introduces
ObservabilityHook+ related types, and wires anObservabilityProviderinto the provider tree. - Adds PII sanitization utilities with tests, and a wrapper hook to sanitize data before invoking consumer callbacks.
- Emits observability events for error boundaries and form submit / suspense-loading durations, plus docs for usage/integrations.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| src/types/observability.ts | Defines public observability types and sanitization config. |
| src/index.ts | Exports observability types and createObservabilityError from package entrypoint. |
| src/contexts/index.ts | Re-exports observability context/provider APIs. |
| src/contexts/ObservabilityProvider/useSanitizedObservability.ts | Wraps callbacks to sanitize errors/metrics before dispatching. |
| src/contexts/ObservabilityProvider/useObservability.ts | Context hook returning a sanitized observability hook. |
| src/contexts/ObservabilityProvider/sanitization.ts | Implements recursive sanitization + PII redaction patterns. |
| src/contexts/ObservabilityProvider/sanitization.test.ts | Adds sanitization unit tests. |
| src/contexts/ObservabilityProvider/observabilityUtils.ts | Converts known SDK error classes into ObservabilityError. |
| src/contexts/ObservabilityProvider/index.ts | Public exports for the ObservabilityProvider module. |
| src/contexts/ObservabilityProvider/ObservabilityProvider.tsx | Context provider for passing consumer observability hook. |
| src/contexts/ObservabilityProvider/ObservabilityContext.ts | Creates observability React context value type. |
| src/contexts/GustoProvider/GustoProviderCustomUIAdapter.tsx | Wraps app with ObservabilityProvider and reports top-level boundary errors. |
| src/components/Contractor/Payments/CreatePayment/CreatePayment.tsx | Supplies a component name into BaseComponent for tagging. |
| src/components/Base/useBaseSubmit.ts | Emits observability errors + submit duration metrics on base submits. |
| src/components/Base/useBase.tsx | Extends BaseContext to include an optional component name. |
| src/components/Base/Base.tsx | Emits boundary errors + suspense loading-duration metrics, propagates component name. |
| docs/integration-guide/observability.md | Adds observability + sanitization documentation and integration guidance. |
| docs/integration-guide/observability-examples.md | Adds sample implementations (console/Sentry/Datadog/custom). |
| docs/integration-guide/error-handling.md | Links error handling docs to observability hooks. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+8
to
+13
| if (context === undefined) { | ||
| return { observability: undefined } | ||
| } | ||
|
|
||
| const sanitizedObservability = useSanitizedObservability(context.observability) | ||
|
|
| // Sample metrics at different rates based on name | ||
| const sampleRates: Record<string, number> = { | ||
| 'sdk.form.submit_duration': 0.1, // 10% of form submissions | ||
| 'sdk.component.mount': 0.01, // 1% of component mounts |
src/types/observability.ts
Outdated
| } | ||
|
|
||
| export interface ObservabilityMetric { | ||
| /** Metric name (e.g., 'sdk.component.mount', 'sdk.form.submit_duration') */ |
src/types/observability.ts
Outdated
Comment on lines
+55
to
+56
| /** The original error object */ | ||
| originalError: unknown |
- Pass additionalSensitiveFields to sanitizeObject instead of mutating global array - Ensure consistent sanitization behavior across error and metric calls - Prevent config leakage between different SDK instances - Add tests to verify non-mutation and consistent behavior Made-with: Cursor
- Import and use sanitizeError in GustoProviderCustomUIAdapter - Ensure top-level internal_error reports respect sanitization config - Prevent PII leakage in message, stack, and originalError - Add tests to verify sanitization behavior for top-level errors Made-with: Cursor
- Store observability and componentName in refs that update on change - Ensures cleanup function uses current values, not stale mount-time captures - Fixes metrics reporting incorrect observability hook or component name if they change during suspense Made-with: Cursor
- Update docs to indicate componentName is reported 'when available' - Note that not all SDK components currently report their names - Add clarification that componentName may be undefined - Adjust metric table to reflect 'when available' status Made-with: Cursor
Made-with: Cursor
…nent type Made-with: Cursor
…t sanitization behavior Made-with: Cursor
Made-with: Cursor
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
Adds comprehensive observability hooks for error tracking and performance monitoring with built-in PII protection. SDK consumers can now integrate with tools like Sentry, Datadog, or custom monitoring solutions to track errors and performance metrics.
Usage Example:
Changes
ObservabilityHookinterface withonErrorandonMetriccallbacksRelated
Testing
Manual Testing:
Automated Tests:
Test Results:
Documentation:
docs/integration-guide/observability.md- Complete guidedocs/integration-guide/observability-examples.md- Integration examples