Fix Payment Gateway Propagation

15 minutes

In this step, you’ll edit application code in the payment gateway proxy so it forwards W3C Trace Context to payment-api then rebuild and redeploy the service.

Note

After fixing the edge NGINX gateway (step 06), traces may connect from the browser through frontend-api and into order-api. But when frontend-api submits payment via payment-gateway, the proxy forwards to payment-api without W3C trace headers.

This break is a common Node.js proxy bug: the service is instrumented and visible in APM, but the outbound fetch does not propagate trace context.

In Splunk APM you’ll see this behaviour:

nginx-aft1

The payment gateway still creates its own spans (so it shows in the service map), but the upstream call starts a new trace on payment-api. This mirrors real teams who add a custom BFF/proxy and forget to propagate context on outbound HTTP calls - or when code uses suppressTracing() trying to avoid “double spans” which accidentally breaks propagation.

The Fix

Open the server.js file and locate buildUpstreamHeaders().

text
cd ~/workshop/context-propagation
vi services/payment-gateway/server.js

Inject W3C trace context into upstream headers

  1. Uncomment/add propagation.inject() before the return:
  2. Remove suppressTracing on the upstream fetch
javascript
function buildUpstreamHeaders() {
  const headers = {
    'Content-Type': 'application/json',
  };
  return headers;
}

const upstreamContext = suppressTracing(context.active());

Check your work before proceeding

Run the following command from ./workshop/context-propagation folder to compare your changes with the expected solution:

bash
diff ./services/payment-gateway/server.js ./services/payment-gateway/server-fixed.js