Skip to content

feat(observability): add typed connector request/response fields - #2036

Open
AmitsinghTanwar007 wants to merge 5 commits into
mainfrom
typed-message
Open

feat(observability): add typed connector request/response fields#2036
AmitsinghTanwar007 wants to merge 5 commits into
mainfrom
typed-message

Conversation

@AmitsinghTanwar007

Copy link
Copy Markdown
Contributor

Summary

Adds typed_connector_request and typed_connector_response fields across the entire connector service stack to provide structured, domain-typed observability data separate from raw wire-format payloads.

Problem

Currently, only raw_connector_request / raw_connector_response exist — these carry the literal HTTP bytes sent/received. For debugging and analytics, we also need the typed representation (the Rust domain struct, masked and serialized) so consumers can reason about connector data in a connector-agnostic way without parsing raw JSON/XML from different providers.

What changed

Proto definitions (payment.proto, frm.proto):

  • Added typed_connector_request and typed_connector_response optional fields to all response messages (Authorize, Get, Void, Capture, Refund, CreateOrder, SetupRecurring, MandateRevoke, FRM pre/post risk check, etc.)

Domain types (connector_types.rs, frm_types.rs, surcharge_types.rs, payouts_types.rs, merchant_authentication_flow_data.rs):

  • Added typed_connector_request / typed_connector_response fields to all flow data structs (PaymentFlowData, RefundFlowData, DisputeFlowData, FrmFlowData, SurchargeFlowData, VerifyWebhookSourceFlowData, RefreshPaymentMethodFlowData, PayoutFlowData)
  • Extended the RawConnectorRequestResponse trait with get/set_typed_connector_request and get/set_typed_connector_response methods
  • Implemented the new trait methods for all flow data structs

Connector integration trait (connector_integration_v2.rs):

  • Added get_typed_connector_request() default method returning None
  • Wired it into build_request_v2() via set_typed_connector_request() on the request builder

Request infrastructure (request.rs):

  • Added typed_connector_request field to Request and RequestBuilder
  • Added set_typed_connector_request() builder method

Connector macros (macros.rs):

  • Added serialize_typed_connector_payload() utility — masked serialization of typed structs
  • Added expand_fn_get_typed_connector_request! macro — generates get_typed_connector_request() for each flow
  • Modified expand_fn_handle_response! to capture and set typed_connector_response on the flow data
  • Wired both macros into all 4 macro_connector_implementation! variants

Connector-specific (bamboraapac/transformers.rs):

  • Added Serialize derive to request structs that were missing it (required for typed serialization)

Service layer (service.rs):

  • Set typed_connector_request on flow data from the request object after connector call

gRPC response generators (types.rs, frm/types.rs, payments.rs):

  • All generate_*_response() functions now extract and pass typed fields to proto responses

Server layer (events.rs):

  • Added typed_connector_request/response: None to VerifyWebhookSourceFlowData construction

Key design principle: raw ≠ typed

  • raw: the literal bytes off the wire (HTTP body as-is)
  • typed: the domain Rust struct, masked-serialized to JSON — these MUST be different values

Test plan

  • cargo check passes across all crates
  • Existing connector tests (razorpay, calida, bamboraapac) compile with new fields
  • Verify typed fields are None by default for connectors not using the macro system
  • Verify typed fields are populated for macro-based connectors (e.g., bamboraapac)
  • Confirm raw and typed values differ when both are populated

🤖 Generated with Claude Code

…ss all flows

Add `typed_connector_request` and `typed_connector_response` fields alongside
existing `raw_connector_*` fields to enable structured, connector-agnostic
observability data separate from the raw wire-format payloads.

- raw fields: literal HTTP request/response bytes (what went over the wire)
- typed fields: masked serialization of the domain-typed Rust structs

Changes span proto definitions, domain types, flow data structs, gRPC response
generators, connector macros, and the connector integration trait.
@AmitsinghTanwar007
AmitsinghTanwar007 requested review from a team as code owners August 3, 2026 09:29
hyperswitch-bot Bot and others added 4 commits August 3, 2026 09:50
Auto-applied by CI:
- cargo +nightly fmt --all
- make -C sdk generate (if applicable)
- make docs (if applicable)

This commit was automatically generated by GitHub Actions.
Add typed_connector_response: None and typed_connector_request: None
to all PaymentFlowData initializations in razorpay and adyen test files.
Add tracing::warn! logs when a connector does not provide typed_connector_request
or typed_connector_response. This surfaces non-macro connectors (razorpay,
razorpayv2, itaubank) and hybrid connector flows (cybersource, paypal, redsys,
worldpayvantiv manual impls) that haven't implemented typed observability yet.

Warnings fire at runtime so they show up in logs/dashboards, making it easy to
track which connectors still need typed support without breaking existing flows.
Auto-applied by CI:
- cargo +nightly fmt --all
- make -C sdk generate (if applicable)
- make docs (if applicable)

This commit was automatically generated by GitHub Actions.
}
}

pub fn generate_mandate_revoke_response(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was these functions added in this file instead of type.rs
not related to this pr though, but how did we missed

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