Skip to content

feat: Add OnCompleteCallback interceptor for HTTP call tracing#100

Merged
alexisandreason merged 2 commits intomasterfrom
addingTraceFunctions
Mar 25, 2026
Merged

feat: Add OnCompleteCallback interceptor for HTTP call tracing#100
alexisandreason merged 2 commits intomasterfrom
addingTraceFunctions

Conversation

@alexisandreason
Copy link
Copy Markdown
Contributor

Summary

Adds an optional OnCompleteCallback hook to FamisClient that fires after every HTTP request (success or failure), providing structured call metadata including timing, method, URL, request/response bodies, and status codes. This enables callers (e.g. a tracing/logging service) to observe all SDK-level HTTP traffic without modifying internal SDK code.

Changes

  • Introduced SdkCallInfo interface capturing method, URL, base URL, request headers/body, response status/body, duration, and optional error message
  • Added OnCompleteCallback type alias ((info: SdkCallInfo) => void)
  • Added onComplete optional property to FamisClient
  • Threaded onComplete through all three construction paths: withLoginCredential, withClientCredential, and the private constructor
  • Installed an axios request interceptor to stamp __startTime on each outgoing request config
  • Installed an axios response interceptor (success + error paths) that computes duration, builds SdkCallInfo, and fires the callback asynchronously (via Promise.resolve().then(...)) to avoid blocking the response chain

Modified Files

Core Changes

  • famis_client.ts – Added onComplete field, wired it through all constructors, and registered axios interceptors
  • model/common.ts – Added SdkCallInfo interface and OnCompleteCallback type

Breaking Changes

None — onComplete is optional and all existing call sites remain unchanged.

Testing

  • Instantiate FamisClient with an onComplete callback and verify it fires for each API call
  • Verify duration values are reasonable
  • Verify the callback fires on error responses as well as successes
  • Verify existing SDK usage without onComplete is unaffected

Additional Context

This callback is designed to integrate with the facility360_r7 trace service, which collects and stores HTTP call records for observability and debugging purposes.


🤖 Generated with Claude Code

Made with Cursor

@alexisandreason alexisandreason merged commit 5790198 into master Mar 25, 2026
1 check passed
@alexisandreason alexisandreason deleted the addingTraceFunctions branch March 25, 2026 19:46
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.

2 participants