Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
FREEDOM251

Freedom251 › Blog › distributed tracing

Express production logs: Trace requests with searchable events

By Freedom251 Team · · 12 min read

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

Make Express production logs searchable by emitting one JSON object per event, keeping field names and data types stable, and carrying a request or trace identifier through every logistics and SMS service call. Use request middleware for access records, an application logger such as Pino for business events, and a collector or backend that can parse JSON paths and index the fields you actually query. A cohort label is not a built-in logistics or SMS standard: define it in your application as a stable, non-sensitive grouping key.

What should Express production logging contain?

Production logging records application activity that operators need to diagnose failures, explain customer-visible outcomes, and measure a workflow. Express separates that purpose from debugging output. Its production guidance recommends a logging library such as Pino for activity logs and warns that writing console output to a terminal or file is synchronous unless the output is piped onward. A logger and an ingestion path therefore matter as much as the JSON syntax itself.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A useful record is a single line containing one complete JSON object. Newline-delimited records let collectors process entries independently when a process restarts or one event is malformed. Valid JSON by itself is not a schema: downstream searches remain fragile if one service writes status as a number, another writes it as text, and a third omits it.

Separate the four kinds of telemetry

Kind What it answers Typical fields Use in production
Request or access log Which HTTP request arrived and how did it finish? Method, route template, status, duration, request ID Keep for every request or sample only after a deliberate capacity review.
Application event log What did the logistics or SMS workflow do? Event name, shipment or message operation key, outcome, provider event ID, cohort key Use for state changes and business failures; avoid message bodies and unnecessary personal data.
Debug log What is the framework or router doing internally? Express DEBUG namespace output and diagnostic details Enable temporarily or at a controlled level. It is not a replacement for activity logs.
Trace-correlated log How did one operation cross services? Request ID, trace ID, span ID, service and environment Join API, queue, logistics, and SMS records in a trace-aware backend.

Express debugging namespaces expose framework and router internals. They can explain routing behavior, but they do not reliably describe whether a shipment update was accepted or an SMS provider event was reconciled. Emit those application events explicitly.

#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter | 4Pack Type C Female to A Male Cable Converter for Apple Duo 17 16 15 14 Plus,iWatch Watch 12 11 10,iPad 9 8 Air,Airpods 5 4
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

How do I choose a stable JSON schema?

Start with fields that every service can populate consistently, then add domain fields only when they serve an operational question. The following is an illustrative schema, not a standard mandated by Express or any cloud provider.

{"timestamp":"2026-10-26T14:03:18.492Z","severity":"INFO","service":"delivery-api","environment":"production","event":"sms.dispatch.accepted","route_template":"/v1/shipments/:shipmentId/notifications","http_method":"POST","status":202,"duration_ms":38,"request_id":"req_01J...","trace_id":"4bf92f3577b34da6a3ce929d0e0e4736","cohort_key":"holiday-east-2026","provider_event_id":"evt_..."}

Define a short data dictionary beside the code. For each field, record its type, whether it is required, who owns it, and whether it may contain sensitive data. Keep timestamps in an unambiguous format such as UTC ISO 8601. Keep HTTP status and duration numeric so range filters and aggregations work. Use one spelling for request_id, not a mixture of requestId, correlationId, and request-id unless you document an intentional mapping.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Use route templates or normalized route names. A raw URL can include query strings and identifiers. Express documentation warns that complex or sensitive criteria placed in a URL may appear in logs or browser history, so a route template is safer for routine access records.
  • Make optional fields explicit. Omit a field when it does not apply, or use a documented null policy; do not alternate between empty strings, zero, and null to mean “unknown.”
  • Keep severity and event names controlled. A small vocabulary such as DEBUG, INFO, WARN, and ERROR, plus dotted event names, makes filters predictable.
  • Version breaking changes. If a field changes meaning or type, add a schema version or a new field and update parsers before removing the old one.

How do I add request and application logs in Express?

Use a request logger for HTTP facts and an application logger for workflow events. Morgan can capture method, URL, status, and response time, define a custom request-ID token, skip selected requests, and emit object-mode entries to a structured logger. Pino is a suitable application logger recommended in Express production guidance.

Install and configure a logger

npm install express morgan pino

The exact package versions should follow your supported Node.js and Express versions. The example below creates a Pino logger and a request ID before Morgan runs.

const express = require('express');
const crypto = require('node:crypto');
const pino = require('pino');
const morgan = require('morgan');

const app = express();
const logger = pino({
  level: process.env.LOG_LEVEL || 'info'
});

app.use((req, res, next) => {
  const supplied = req.get('x-request-id');
  req.requestId = supplied || crypto.randomUUID();
  res.set('x-request-id', req.requestId);
  next();
});

morgan.token('request-id', (req) => req.requestId);

const accessStream = {
  write: (line) => {
    try {
      logger.info({ access: JSON.parse(line) }, 'http request');
    } catch {
      logger.warn({ raw_access_line: line.trim() }, 'unparseable access record');
    }
  }
};

app.use(morgan((tokens, req, res) => JSON.stringify({
  timestamp: new Date().toISOString(),
  http_method: tokens.method(req, res),
  url: tokens.url(req, res),
  status: Number(tokens.status(req, res)),
  duration_ms: Number(tokens['response-time'](req, res)),
  request_id: tokens['request-id'](req, res)
}), {
  stream: accessStream,
  skip: (req) => req.path === '/healthz'
}));

Morgan’s object-mode capability can also be used with a stream that receives an object, depending on the middleware configuration you choose. Whichever form you use, ensure the final logger serializes one JSON object per line and that parse failures are visible rather than silently discarded. Skipping health checks reduces noise only when those requests are not part of an availability investigation; document the decision.

Log workflow events separately

app.post('/v1/shipments/:shipmentId/notifications', async (req, res, next) => {
  const started = process.hrtime.bigint();
  try {
    const cohortKey = req.get('x-cohort-key'); // validate against your own allow-list
    const result = await dispatchNotification({
      shipmentId: req.params.shipmentId,
      cohortKey
    });

    logger.info({
      event: 'sms.dispatch.accepted',
      request_id: req.requestId,
      route_template: '/v1/shipments/:shipmentId/notifications',
      cohort_key: cohortKey,
      provider_event_id: result.providerEventId,
      duration_ms: Number(process.hrtime.bigint() - started) / 1e6
    });
    res.status(202).json({ accepted: true });
  } catch (err) {
    logger.error({
      event: 'sms.dispatch.failed',
      request_id: req.requestId,
      error_name: err.name,
      error_code: err.code
    }, 'notification dispatch failed');
    next(err);
  }
});

Do not log an exception object wholesale if it may contain request data, authorization headers, or provider payloads. Select stable error fields and keep the message concise enough for a search result. The illustrative cohort_key is an application field; the sources do not define a universal logistics or SMS cohort schema.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Sale
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter | USB C Dongle with 90W Max Power Delivery, 3×5Gbps USB A Data Ports, for MacBook, Dell, and More (Charger Not Included)
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

How do I correlate logs across logistics and SMS services?

Generate or accept one request identifier at the edge, return it to the caller, and propagate it on every outbound service call. Distributed tracing adds trace and span identifiers: a trace identifies the overall operation, while spans identify individual service work. OpenTelemetry’s log model supports recording trace, span, and resource context so a backend can join logs with traces.

Propagate identifiers without assuming a provider-specific header

async function callLogisticsService(url, payload, req, traceContext) {
  const headers = {
    'content-type': 'application/json',
    'x-request-id': req.requestId
  };
  if (traceContext?.traceparent) {
    headers.traceparent = traceContext.traceparent;
  }

  const response = await fetch(url, {
    method: 'POST',
    headers,
    body: JSON.stringify(payload)
  });

  logger.info({
    event: 'logistics.call.completed',
    request_id: req.requestId,
    trace_id: traceContext?.traceId,
    downstream_status: response.status
  });
  return response;
}

The header names and trace propagation behavior must match the systems you operate; the snippet is an implementation pattern, not a claim that every SMS or logistics provider accepts these headers. Record a provider’s event identifier when it is needed to reconcile an asynchronous callback, but do not copy the entire callback body into every log entry.

Some platforms add their own correlation value. Heroku’s request-ID documentation, updated January 28, 2026, describes an X-Request-ID value that links router and application logs. Treat such a platform value as an input to your schema, normalize its spelling internally, and preserve your own identifier if requests can enter through more than one platform.

How should I define a logistics or SMS cohort key?

A cohort is an application-defined grouping for analysis, such as a rollout wave, a delivery region code, or a campaign generation. It is not a universal field with prescribed values. Define a key that is stable for the analysis period and does not expose a phone number, message text, recipient name, or exact address.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Document the cohort contract

  • Specify who creates the key and when it is assigned.
  • Use an allow-list or validated format so arbitrary user input cannot create unlimited field values.
  • Decide whether the key identifies a shipment, a notification attempt, a software rollout, or another unit; never mix meanings under one field.
  • Record the cohort definition outside the log stream so a future analyst can interpret historical values.
  • Restrict access to cohort fields when they could reveal operational or customer patterns.

For retries, keep the same cohort key when the retry belongs to the same experiment or operational group, and add a separate attempt or event identifier. For a new rollout, create a new key rather than changing the meaning of an existing one. These are local design choices, not requirements imposed by Express.

How do I search JSON paths and index the fields that matter?

Send newline-delimited JSON to a collector that parses the payload instead of treating the entire line as an opaque message. Google Cloud Logging documents querying JSON payload paths and indexing selected fields; other backends provide equivalent concepts under different names. AWS guidance describes agents, parsers, normalization, and searchable backends. Choose based on capabilities, not on a presumed best vendor.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter | 85W Max PD, 2 USB 3.0 & 1 USBC Data Ports, SD/TF Card Reader, for Laptops/Mac and Other Type C Devices (Charger Not Included)
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Search by exact fields first

Typical investigations combine a time range with exact values: service = 'delivery-api', event = 'sms.dispatch.failed', cohort_key = 'holiday-east-2026', and a specific request_id. Add a status or duration range only after the exact filter narrows the result set. Query the parsed JSON path, not a string search for text that merely resembles a field.

Index fields that are frequently filtered or joined and have bounded operational value, such as request ID, trace ID, event name, service, environment, status, and cohort key. Indexing every nested value increases storage and maintenance work without guaranteeing a useful query. Confirm how your backend treats missing fields, numeric comparisons, case sensitivity, and timestamps before writing runbooks.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Keep a local fallback for incident work

# Find failed dispatch events for one cohort in newline-delimited logs
jq 'select(.event == "sms.dispatch.failed" and .cohort_key == "holiday-east-2026")' production.log

# Follow one request through all services
jq 'select(.request_id == "req_01J..." or .trace_id == "4bf92f...")' production.log

This command assumes each line is valid JSON and that your shell log copy is authorized for the investigation. It is not a substitute for retention, access, and deletion controls in the production backend.

What should I do with complex or sensitive search criteria?

Put complex criteria in a request body rather than a URL when the operation supports it. Express notes that URL criteria can appear in logs or browser history. Mount the matching body parser before the route accesses req.body.

const express = require('express');
const app = express();

app.use(express.json({ limit: '64kb' }));

app.post('/v1/log-search', (req, res) => {
  const { cohortKey, eventNames, from, to } = req.body;
  // Validate type, range, and authorization before building a query.
  res.json({ accepted: true });
});

A body is not automatically private: access logs, application logs, proxies, and audit systems may still record metadata. Do not log message bodies, phone numbers, credentials, authorization headers, or full search filters by default. Log a validation result, a query identifier, or a count when that is enough to troubleshoot. Data minimization is prudent operational guidance; retention and privacy obligations depend on your jurisdiction and organization.

Which log pipeline or backend fits this workload?

No single backend is established as the best choice for logistics and SMS cohorts. Evaluate the following dimensions with a representative sample of your own records.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray | Data transfer & Fast charging for MacBook, iPhone 17/16/15, iPad, Samsung Galaxy, Apple Watch
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Decision axis Questions to answer
Parsing and schema Can the collector parse one JSON object per line, enforce types, and route malformed records for repair?
JSON-path search and indexing Can investigators filter nested fields, compare numbers, search time ranges, and index request or cohort keys?
Correlation Can the system join request ID, trace ID, span ID, and service/resource metadata?
Collection and buffering Where do agents run, what happens during a network outage, and how are backpressure and duplicate delivery handled?
Access and retention Can you apply role-based access, redact sensitive fields, set retention by log class, and audit searches?
Operations model Does a hosted service or self-managed stack fit your ownership, deployment, and recovery skills?

Test a failure path, a successful SMS dispatch, a delayed callback, a logistics timeout, and a retry. Verify that one request ID remains searchable across each hop, that trace context is present where tracing is enabled, and that a malformed record does not block subsequent lines.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Why are my JSON logs difficult to search?

Every field appears as text

Your collector may be ingesting the line as plain text. Configure JSON parsing at the agent or backend and inspect the stored payload to confirm that status and duration_ms are numeric paths.

One request has several IDs

Different middleware may generate IDs independently. Choose an edge-to-edge request ID, copy it into child loggers, and map platform IDs into a separate field. If you use tracing, keep trace and span IDs distinct from the request ID.

Searches miss records from one service

Compare field names, casing, timestamp zones, and environment values between services. A schema version and a small conformance test can catch a producer that changed cohort_key to another name or sent a number as a string.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Logs expose query data

Inspect Morgan’s URL token, reverse-proxy access logs, and error serializers. Replace raw URLs with route templates where possible, move sensitive criteria into a body, and redact before serialization; do not assume a body parser or route template automatically removes data from every upstream log.

Logs disappear during a restart

Console output and collectors can buffer differently. Follow the Express production warning about synchronous terminal or file output, use a supported transport path, and test shutdown behavior so buffered records are flushed or intentionally discarded according to your incident policy.

Best Value
Sale
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display | 85W Max PD, 1 Powered USB-C 5Gbps & 2 Powered USB-A 3.0 5Gbps Data Ports, for MacBook Pro, MacBook Air, Dell and More (Black)
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

What is a practical rollout checklist?

  1. Write the field dictionary and identify an owner for request, trace, event, and cohort fields.
  2. Add request-ID middleware before access logging and return the chosen ID in the response.
  3. Configure Morgan or equivalent access logging with a route template, status, duration, and skip policy.
  4. Configure Pino or another structured logger for application events; keep debug namespaces separate.
  5. Propagate request and trace context through logistics and SMS calls, recording only necessary provider event IDs.
  6. Place body-parser middleware before routes that accept complex search criteria and validate every filter.
  7. Configure the collector to parse JSON, quarantine malformed lines, and preserve timestamps.
  8. Index the fields your incident queries actually use, then test JSON-path searches and joins.
  9. Apply access, redaction, and retention controls appropriate to your organization and jurisdiction.
  10. Run a simulated failure across all services and verify that one request can be followed from ingress to callback.

Frequently Asked Questions

Can I use Express DEBUG output as my production log?

No. DEBUG namespaces are useful for framework and router diagnostics, while production activity logging should emit deliberate, structured application events. Keep the two streams separately configurable so a temporary debug session does not change the business-event schema.

Should every request ID be a UUID?

A UUID is one possible locally generated format, but uniqueness across the systems you operate is the real requirement. Choose a format your gateways, log indexes, and support tools can carry without truncation, and never derive it from a phone number or other customer identifier.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How long should logistics and SMS logs be retained?

There is no universal period in the documented sources. Set retention by log class, operational need, contractual requirements, and the rules that apply to your organization; keep sensitive payloads for the shortest period that still supports a defined use.

How can I investigate duplicate SMS callbacks?

Search the request or trace identifier together with the provider event identifier and your own attempt identifier. Compare timestamps and event names, then check whether your callback handler is idempotent; do not rely on message text as the deduplication key.

What happens if one log line is not valid JSON?

A robust collector routes that line to a visible error or quarantine stream and continues processing later lines. Alert on the parse failure, inspect the serializer or exception path that produced it, and repair the producer rather than silently indexing a mixture of text and JSON.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

distributed tracingExpressJSON logslog searchlogistics softwareproduction loggingrequest IDSMS systemsstructured logging

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.