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

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Make Express production logs searchable by emitting one-line JSON records with a stable schema, assigning every request a request ID, and propagating that identifier (plus trace and span IDs when tracing is enabled) through logistics and SMS calls. Store the records in a system that parses JSON paths and can index the fields you query most often. Treat a “cohort” as an application-defined, access-controlled label—not as a universal logistics or SMS standard.

This design lets an operator start with a request ID, narrow results by route, status, service, or cohort key, and then follow dispatch, carrier, SMS-provider, and callback events without putting message bodies or recipient details into ordinary logs.

What is the right logging model for an Express API in production?

Use separate streams for request activity, application events, debugging, and distributed-trace correlation. They answer different operational questions and should not be treated as interchangeable.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Log type Purpose Typical fields Production guidance
Request/access log Shows what reached the API and how it completed HTTP method, route, status, duration, request ID Emit one record per completed request; omit or normalize query strings.
Application event log Describes business steps such as shipment accepted or SMS send requested Event name, service, cohort key, shipment or provider event identifier Write explicit events at state transitions; do not rely on URL logs to reconstruct them.
Debug log Explains framework or router internals during diagnosis Express or router namespace messages Enable selectively. Express documents DEBUG namespaces as debugging output, not a replacement for activity logs.
Trace correlation Connects logs to a distributed trace and individual spans Trace ID, span ID, service and resource context Use the propagation and instrumentation configured for your tracing system.

Express’s production guidance recommends a logging library such as Pino for application activity. It also cautions that writing console output to a terminal or file is synchronous unless the output is piped onward, so a high-volume API should send records through an appropriate collector or stream rather than treating a terminal as its log backend.

#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.

Morgan is useful for access records: its tokens can report method, URL, status, and response time; a custom token can add a request ID. Morgan can feed a structured logger through a custom stream and can skip selected requests, such as health checks. Keep Morgan’s request record distinct from business events written by your application logger.

What fields should a searchable JSON log record contain?

Valid JSON is only the starting point. Downstream search works when field names, types, and meanings remain consistent across every service and deployment.

Field Example value Why it matters
timestamp RFC 3339 time in UTC Orders events from different machines.
severity info, warn, error Supports alerting and triage.
service and environment dispatch-api, production Separates similarly named events across deployments.
event shipment.accepted Provides a stable, queryable business action.
route /shipments/:id/notify Uses a route template instead of exposing a full URL.
http_method, status, duration_ms POST, 202, 37 Measures request outcomes with predictable types.
request_id Opaque identifier Joins all logs for one inbound request.
trace_id and span_id Tracing identifiers when enabled Links records to distributed traces.
cohort_key pilot-west-2026q4 Groups records for an application-defined analysis.
provider_event_id Opaque callback or send identifier Lets support staff find a provider interaction without logging message content.

The names above are an illustrative schema, not a standard required by Express, logistics systems, or SMS providers. Define a short schema document, specify whether each field is a string, number, Boolean, or timestamp, and reject or quarantine records that violate it. Keep the same spelling and nesting in every service; a mix of requestId, request_id, and numeric-versus-string IDs makes path searches unreliable.

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

How do I add request IDs and structured access logs to Express?

Create or accept an opaque request ID at the edge, attach it to the request context, return it in the response, and include it in every log emitted during that request. Validate incoming values for length and allowed characters; an ID is for correlation, not authentication.

1. Establish the request context before routes

const crypto = require('node:crypto');

app.use((req, res, next) => {
  const incoming = req.get('x-request-id');
  req.id = incoming && /^[A-Za-z0-9._-]{1,128}$/.test(incoming)
    ? incoming
    : crypto.randomUUID();
  res.set('x-request-id', req.id);
  next();
});

If your platform already supplies a request identifier, preserve it after validation. Heroku’s request-ID documentation describes an X-Request-ID value that correlates router and application logs; that page was updated January 28, 2026. Other platforms may use a different mechanism, so map their value into your internal request_id field.

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.

2. Emit a JSON access record when the response finishes

Morgan can provide method, URL, status, and response-time tokens, including a custom request-ID token. A stream adapter can parse Morgan’s JSON line and pass an object to Pino or another logger:

const morgan = require('morgan');
const pino = require('pino');
const logger = pino();

morgan.token('request-id', req => req.id);
app.use(morgan((tokens, req, res) => JSON.stringify({
  timestamp: new Date().toISOString(),
  severity: 'info',
  service: 'dispatch-api',
  event: 'http.request',
  request_id: tokens['request-id'](req, res),
  http_method: tokens.method(req, res),
  route: req.route && req.route.path ? req.route.path : req.path,
  status: Number(tokens.status(req, res)),
  duration_ms: Number(tokens['response-time'](req, res))
})), {
  stream: {
    write: line => logger.info(JSON.parse(line))
  },
  skip: (req, res) => req.path === '/healthz'
}));

Middleware timing matters: the request-ID middleware must run first, and a route template may not be available until routing has occurred. Verify the actual output in your Express version and logger adapter. If a raw URL can contain sensitive criteria, use req.path or a known route identifier and do not serialize the query string.

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

3. Write application events explicitly

function event(req, name, fields = {}) {
  logger.info({
    timestamp: new Date().toISOString(),
    service: 'dispatch-api',
    event: name,
    request_id: req.id,
    ...fields
  });
}

app.post('/shipments/:id/notify', (req, res) => {
  event(req, 'shipment.notification.requested', {
    route: '/shipments/:id/notify',
    cohort_key: req.cohortKey,
    shipment_id: req.params.id
  });
  res.sendStatus(202);
});

Use event names for state transitions rather than logging every internal function call. If a shipment service calls an SMS service, carry the request or trace context through that outbound request and log the SMS provider’s opaque event identifier when it is needed for operations.

How should logistics and SMS cohorts be represented?

A cohort is an application grouping for analysis, such as a rollout segment, warehouse region, carrier program, or notification experiment. There is no universal logistics or SMS cohort schema in the documented sources, so define yours locally and document who may query it.

Choose a stable, non-sensitive key

  • Use an opaque value such as pilot-west-2026q4, not a phone number, message text, or a concatenation of customer attributes.
  • Keep the key stable for the analysis period; changing its meaning midstream makes historical searches misleading.
  • Record the cohort on events that need grouping, including shipment acceptance, notification request, provider response, and callback handling.
  • Store a separate mapping from the key to business definitions in an access-controlled system rather than embedding sensitive descriptions in every log line.

Follow one operation across services

For a request that creates a shipment and triggers an SMS, the inbound API log, logistics-service log, outbound SMS request log, and callback log should share the propagated correlation identifier. Add a trace ID and span ID when OpenTelemetry instrumentation is present; OpenTelemetry’s logs specification defines trace, span, and resource context for this purpose. A provider event ID can connect a later delivery callback without recording the message body.

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.

Do not assume that a callback arrives with the original request ID. Persist the provider event ID and your own shipment or notification operation ID in a controlled store, then log both when processing the callback. This gives operators a second join key when the original HTTP context no longer exists.

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.

How do I keep sensitive search criteria out of production logs?

Express documents using a request body for complex or sensitive criteria instead of putting them in a URL, because URLs can appear in logs and browser history. Mount the matching body parser before the route that reads req.body.

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

app.post('/shipments/search', (req, res) => {
  const criteria = req.body;
  // Validate criteria, execute the search, and log only a redacted summary.
  res.json({ ok: true });
});

The parser limit is an example you should tune to your API; it is not a requirement from Express documentation. Apply allowlists and validation to body fields, and log only facts needed for operations. By default, omit SMS message bodies, phone numbers, credentials, authorization headers, and complete search filters. Redaction is data-minimization guidance, not a substitute for a jurisdiction-specific privacy or retention policy.

Where should JSON logs be parsed, searched, and indexed?

Choose a pipeline based on field parsing, JSON-path queries, correlation, collection and buffering, access controls, retention, and whether your team wants hosted or self-managed operations. The documentation describes capabilities and patterns, not a workload-specific vendor ranking.

Pipeline choice Parsing and schema Search and indexing Operational trade-off
Hosted log service Collector or agent parses newline-delimited JSON Usually supports JSON-path filters and selected-field indexes Less infrastructure to run; verify region, retention, access roles, and ingestion limits.
Self-managed searchable backend You operate agents, parsers, and schema mappings Control which fields are indexed and how long they remain searchable More control and responsibility for capacity, upgrades, durability, and incident response.
Object storage plus query engine Batch or streaming normalization is required Good for inexpensive historical analysis; interactive correlation may be slower Useful as an archive, but design a separate near-real-time path for active incidents.

AWS guidance describes agents, parsers, normalized JSON, and searchable backends as pipeline components. Google Cloud Logging documents filtering JSON payloads by path and indexing selected fields. In a Google-style query, a field filter might look like jsonPayload.cohort_key="pilot-west-2026q4"; adapt the syntax to the backend you actually operate. Index only fields used for frequent investigations, because indexing every high-cardinality value can increase cost or storage pressure.

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

Keep collection loss and duplication visible

  • Use newline-delimited records so a collector can process one event at a time.
  • Include a timestamp generated at the application and let the collector add its receipt time.
  • Monitor collector errors, parser failures, queue depth, and dropped-record counters.
  • Expect retries to duplicate records; include an event identifier or deterministic key when downstream deduplication matters.
  • Restrict access to cohorts and identifiers according to your organization’s roles and retention decisions.

How do I search and correlate an incident?

Start with the narrowest stable identifier, then widen the search only when necessary.

  1. Copy the request ID from the client response, gateway record, or support ticket.
  2. Search the parsed request_id field across the API, logistics, and notification services.
  3. Inspect the ordered events for status codes, durations, cohort key, shipment operation ID, and provider event ID.
  4. If the request crossed asynchronous boundaries, search the provider event ID or operation ID in callback and worker logs.
  5. Use the trace ID to open the distributed trace and inspect the slow or failed span; use span IDs to distinguish concurrent outbound calls.
  6. Only after correlation is complete, aggregate by cohort_key, route, status, or event name to find a pattern.

Searching by a raw URL, message text, or recipient number is both less reliable and more likely to expose sensitive data. Stable fields make the same investigation repeatable across services.

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

What commonly breaks JSON log search, and how can I fix it?

Records look like JSON but fields are not parsed

Check that each line contains exactly one valid JSON object, that the collector is configured for newline-delimited JSON, and that application exceptions are not wrapped in unescaped text. Send a sample through the collector’s parser and inspect the resulting field tree before changing queries.

The request ID disappears between services

Verify that the outbound client copies the configured correlation or trace context, that each service logs the same canonical field name, and that asynchronous workers receive the context explicitly in their job payload or message metadata. Never generate a fresh ID at every hop unless you also retain the parent identifier.

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

Queries return mixed types

Normalize status and duration to numbers, timestamps to one format, and identifiers to strings. A value logged as 404 in one service and "404" in another can behave differently in filters and indexes.

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.

Search results expose query strings or SMS content

Replace raw URL logging with a route template or path, move complex criteria into a parsed body, and add redaction before the logger receives request data. Rotate or restrict access to already-collected records according to your incident and retention procedures.

Health checks overwhelm useful events

Use Morgan’s skip capability for routine probes or route them to a lower-severity stream. Keep enough probe metrics to detect outages, but do not let repetitive checks dominate request searches.

Callbacks cannot be tied to the original operation

Record an internal operation ID and the provider’s opaque event ID when the outbound action is created. Log both identifiers on callback receipt, along with the callback’s own request ID, because the original HTTP request may have ended long before delivery status arrives.

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

What should be tested before enabling this in production?

  • Send a request through every relevant service and confirm one request ID appears in each expected record.
  • Verify that trace and span IDs are present only when tracing is configured and that they match the trace viewer.
  • Check that route templates, not sensitive query strings, are emitted.
  • Inject an error and confirm severity, status, duration, and error context remain valid JSON.
  • Exercise an asynchronous SMS callback and search it by provider event ID and operation ID.
  • Run representative JSON-path searches and confirm the fields intended for indexing are actually indexed.
  • Review access permissions and retention settings with the owners of shipment and notification data.

The practical outcome is a log stream that answers both “What happened to this request?” and “What happened to this application-defined cohort?” without depending on message content or fragile URL parsing. Keep the schema small, propagate correlation context deliberately, and treat backend indexing and access as operational design choices rather than defaults.

Frequently Asked Questions

Should I use Pino or Morgan for an Express API?

They solve different parts of the problem. Use a logger such as Pino for application events and errors; use Morgan when you want standardized HTTP access fields, custom tokens, filtering, or a stream into that logger. Many teams run Morgan for access records and Pino calls for business events.

Can a request ID replace distributed tracing?

No. A request ID is a practical join key for logs, while tracing adds parent-child spans, timing, and service topology. Keep the request ID for support searches and add trace and span context when you need latency or dependency analysis.

How often should cohort keys change?

Change a key when the business definition changes, not on every deployment or request. Version the definition in your internal cohort registry so analysts can tell whether two records use the same membership rules.

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

What is the safest way to log an SMS delivery failure?

Log the failure category, service, timestamps, request or operation ID, and the provider event ID. Avoid logging the message body, full phone number, authorization material, or unrestricted provider payload unless a controlled, redacted diagnostic workflow specifically requires it.

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.