Advanced

Socket Telemetry

Rezo tracks connection timing automatically for every request. You get precise measurements for DNS resolution, TCP handshake, TLS negotiation, and time to first byte — without any additional setup.

Response Timing

Every response includes a timing property with connection-level timing data:

import rezo from 'rezo';

const response = await rezo.get('https://api.example.com/data');

console.log(response.timing);
// {
//   dns: 12,        // DNS lookup (ms)
//   tcp: 45,        // TCP handshake (ms)
//   tls: 89,        // TLS negotiation (ms)
//   ttfb: 210,      // Time to first byte (ms)
//   total: 350,     // Total request time (ms)
// }

Connection Reuse Detection

When a request reuses an existing connection, the DNS, TCP, and TLS timings are 0 because no new connection was established:

// First request -- new connection
const r1 = await rezo.get('https://api.example.com/users');
console.log(r1.timing.dns); // 12
console.log(r1.timing.tcp); // 45
console.log(r1.timing.tls); // 89

// Second request -- reused connection
const r2 = await rezo.get('https://api.example.com/posts');
console.log(r2.timing.dns); // 0 (connection reused)
console.log(r2.timing.tcp); // 0
console.log(r2.timing.tls); // 0

This makes it easy to see whether requests are benefiting from connection pooling.

Monitoring Hooks

Rezo provides hooks for real-time monitoring of connection events. Use these to feed metrics into your observability stack:

onDns

Called when DNS resolution completes:

const client = new Rezo({
  onDns(info) {
    console.log(`DNS resolved to ${info.address} in ${info.duration}ms`);
  },
});

onSocket

Called when a TCP connection is established:

const client = new Rezo({
  onSocket(info) {
    console.log(`TCP connected in ${info.duration}ms`);
    console.log(`Connection reused: ${info.reused}`);
  },
});

onTls

Called when the TLS handshake completes (HTTPS only):

const client = new Rezo({
  onTls(info) {
    console.log(`TLS ${info.protocol} in ${info.duration}ms`);
    console.log(`Cipher: ${info.cipher}`);
  },
});

TLS Connection Details

For HTTPS requests, the response timing includes TLS-specific information:

const response = await rezo.get('https://example.com');

// TLS info is available alongside timing data
console.log(response.tlsInfo);
// {
//   protocol: 'TLSv1.3',
//   cipher: 'TLS_AES_128_GCM_SHA256',
//   authorized: true,
//   certificate: {
//     subject: 'example.com',
//     issuer: "Let's Encrypt",
//     validTo: '2026-06-01T00:00:00.000Z',
//     fingerprint: 'AB:CD:EF:...',
//   },
// }

Debug Logging

Enable debug mode to see timing information in the console:

const response = await rezo.get('https://api.example.com/data', {
  debug: true,
});
// [Rezo Debug] DNS: 12ms → 93.184.216.34
// [Rezo Debug] TCP: 45ms
// [Rezo Debug] TLS: 89ms (TLSv1.3)
// [Rezo Debug] TTFB: 210ms

Use Cases

  • Performance monitoring: Track latency breakdowns across DNS, TCP, TLS, and server response time
  • Connection pool validation: Verify that connections are being reused by checking for zero DNS/TCP/TLS times
  • Certificate monitoring: Detect upcoming certificate expirations or unexpected issuers
  • Network diagnostics: Identify whether latency comes from DNS, network, or server processing