Quickstart

Quickstart: Add metrics and tracing to your API calls

Wrap every call in a span and a timer, tag it with the request_id, and you get latency, error-rate and end-to-end tracing for free. This recipe gives you the exact code, uses only the unauthenticated public ring, and links to the endpoints and the application flow so the reader always has a next step.

2 min read

spanOne per call
request_idTag it on the span
REDRate, errors, duration

Instrument the client

async function tracedCall(url, init) {
  const span = tracer.startSpan('credicorp.call', { attributes: { 'http.url': url } });
  const start = performance.now();
  try {
    const res = await fetch(url, init);
    span.setAttribute('credicorp.request_id', res.headers.get('X-Request-Id'));
    span.setAttribute('http.status_code', res.status);
    metrics.histogram('credicorp.latency', performance.now() - start);
    if (!res.ok) metrics.increment('credicorp.errors');
    return res;
  } finally {
    span.end();
  }
}

Correlate with support

Because the span carries the request_id, a spike in your dashboard links directly to specific requests you can quote to support. This turns monitoring into actionable diagnostics.

Frequently asked questions

What metrics matter most?

Rate, errors and duration (the RED method). Add a saturation signal (your local rate-limit budget from RateLimit-Remaining) and you have full coverage.

How does tracing help with support?

Tagging spans with request_id lets you jump from a slow or failing trace straight to the exact request support can look up on their side.

Funding for UK limited companies

Credicorp lends to your company, not to you personally — short-term working capital with no personal guarantee. See what your business could access.