refactor: O11Y-957 - Refactor error handling and state management in replay exporter #348
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
Replaces try/catch-based error handling in SessionReplayApiService with a throwOnErrors helper that throws a custom exception on GraphQL errors. Refactors SessionReplayEventGenerator to support state snapshot/restore for reliable retries, and updates SessionReplayExporter to snapshot and restore state on failure, ensuring event and payload ID consistency. Also improves naming and documentation for clarity.
Note
Improves reliability and observability of replay and sampling flows by adding structured logging, centralized GraphQL error handling, and resilient state management with rollback on failures.
GraphQLClient: acceptsLDLogger; logs GraphQL errors vialogErrors; all call sites (e.g.,InstrumentationManager,SessionReplayExporter) pass the loggerSamplingApiServiceminor cleanup (const path, remove local error printing)throwOnErrors(...)and aSessionReplayApiException; all operations now surface GraphQL errorsSessionReplayEventGeneratoradds sid/canvas state snapshot/restore (getState/restoreState), renames fields for claritySessionReplayExporternow takes a logger, snapshots and restores internal state on exceptions (including payload IDs and generator state) for consistent retries; logs identify failures; minor naming tidy-upsSessionReplayExporterGraphQLClient/SessionReplayExporterand new behaviorsWritten by Cursor Bugbot for commit 8c79eda. This will update automatically on new commits. Configure here.