firebasefirebase-toolschargebee

Firebase emulator: see outgoing HTTP traffic


I have a Cloud Function that calls to Chargebee. In index.ts:

const chargeBee = new ChargeBee();
...
chargeBee.configure({
    site,
    api_key: apiKey
});
...
export const finalizeSignup = https.onCall(
    async (info: SignupInfo, ctx: CallableContext) => {
        const cbCmd = chargeBee.hosted_page.retrieve(info.cbHostedPage);
        const callbackResolver = new Promise<any>((resolve, reject) => {
            // cbCmd.request returns a Promise that seems to do nothing.
            // The callback works, however.
            // Resolve/reject the Promise with the callback.
            void cbCmd.request((err: any, res: any) => {
                if (err) {
                    reject(err);
                }
                resolve(res);
            });
        });
        // Calling Promise.resolve subscribes to the Promise.
        return Promise.resolve(callbackResolver);
    }
);

I am testing this function using the Firebase emulators, started via firebase emulators:start --only functions. Chargebee is responding strangely. They require the domain of their incoming requests to be whitelisted: my first guess is that the domain being used by my locally emulated Cloud Function is not whitelisted on the Chargebee side.

How do I see outgoing HTTP information sent by my locally emulated Cloud Function?


Solution

  • The connection is actually HTTPS, not HTTP.

    The emulators provide no functionality to intercept network traffic of any form.

    For HTTP: you have to apply your own tooling to monitor the HTTP traffic (ie Wireshark).

    For HTTPS: possible to monitor using Wireshark, but impossible to analyze without knowing the SSL key. And in the setup above, where a third-party library is handling the request, there is currently no way to obtain the SSL key. I entered a feature request with Firebase to gauge the interest of developing a way to define an SSL key log when starting the Functions emulator, similar to Chrome. A user only identifying themselves as 'Oscar' told me in a private email that "I've already filed a feature regarding this topic to our engineering team regarding this matter, which will be discussed internally." So that tells us that (1) Firebase is aware that the feature is currently lacking, and (2) there is no progress to report on the feature.