• 4 min read

Bunyan: Structured JSON Logging for Node.js Applications

In the complex world of modern Node.js applications, traditional string-based logging falls short of meeting developers' needs for structured, searchable log data. Bunyan has established itself as the premier JSON logging framework for Node.js, offering a powerful combination of structured data logging and developer-friendly tools.

Bunyan: Structured JSON Logging for Node.js Applications in 2025

Introduction to Bunyan: The JSON-First Logger for Node.js

In the complex world of modern Node.js applications, traditional string-based logging falls short of meeting developers' needs for structured, searchable log data. Bunyan has established itself as the premier JSON logging framework for Node.js, offering a powerful combination of structured data logging and developer-friendly tools.

Why Bunyan Stands Out in the Node.js Logging Ecosystem

Bunyan has gained widespread adoption among Node.js developers for several compelling features:

  • Native JSON Output: All logs are JSON objects by default, making them easy to parse and analyze
  • Built-in CLI Tool: View and filter logs directly from the command line
  • Serializers: Automatically format common objects like errors and HTTP requests
  • Stream-based Architecture: Flexible output destinations using Node.js streams
  • Child Loggers: Create context-specific loggers that inherit properties
  • Runtime Log Level Changes: Modify logging verbosity without application restarts

Getting Started with Bunyan

Installation is straightforward via npm:

batchfile
1
npm install bunyan

Basic setup requires minimal code:

JavaScript
12345689111213
const bunyan = require('bunyan');
const log = bunyan.createLogger({
name: 'myapp',
level: 'info',
serializers: bunyan.stdSerializers
});
log.info('Application started');
log.error({ err: new Error('Database connection failed') }, 'Fatal error');
// Create a child logger with context
const requestLogger = log.child({ reqId: '123abc' });
requestLogger.info({ path: '/api/users' }, 'Request received');

Elevating Bunyan with OpenTelemetry for Comprehensive Observability

While Bunyan excels at structured logging, today's distributed applications demand a more integrated approach to observability. By combining Bunyan with an OpenTelemetry-native observability platform, you can transform isolated logs into components of a unified monitoring strategy.

This powerful integration enables:

  • Trace Context Enrichment: Automatically add trace and span IDs to your log entries
  • Log-Trace Correlation: Connect logs directly to distributed traces for context-rich debugging
  • Unified Data Management: Handle logs, metrics, and traces through a single platform
  • Advanced Search and Analysis: Query across all telemetry types simultaneously
  • Cross-Service Visibility: Track requests across service boundaries with correlated logs

Implementing Bunyan with OpenTelemetry

Integration requires minimal configuration:

JavaScript
12356791012131516171819202223
const opentelemetry = require('@opentelemetry/api');
const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
const { BunyanInstrumentation } = require('@opentelemetry/instrumentation-bunyan');
// Set up OpenTelemetry
const provider = new NodeTracerProvider();
provider.register();
// Configure Bunyan instrumentation
const bunyanInstrumentation = new BunyanInstrumentation({
// Configuration options
});
// Your existing Bunyan logger will now include trace context automatically
const bunyan = require('bunyan');
const log = bunyan.createLogger({
name: 'myapp',
level: 'info'
});
// This log will automatically include OpenTelemetry trace context
log.info('This log is now trace-aware');

Analyzing OpenTelemetry Logs in Dash0

Logs can be directly routed into Dash0. Dash0 with OpenTelemetry provides the ability to filter, search, group, and triage within a simple user interface, with full keyboard support. Dash0 also gives full log context by showing trace context, the call and resource that created the log - including details like the Kubernetes Pod, server, and cloud environment.

Dash0 Log Management

Log AI also enhanced the logs with more semantical metadata and structure without any manual pattern declaration.

Conclusion

In 2025, Bunyan continues to be the top choice for developers seeking structured, JSON-based logging in Node.js applications. Its combination of powerful features and developer-friendly tools makes it ideal for applications where log data needs to be easily searchable and analyzable.

By enhancing Bunyan with OpenTelemetry integration, developers can maintain the benefits of structured JSON logging while gaining the advantages of unified observability. This combination delivers powerful insights by connecting logs with traces and metrics, enabling faster problem resolution and better application understanding.

For Node.js applications that demand both structured logging and comprehensive observability, Bunyan with OpenTelemetry integration provides an ideal solution that scales with your application's complexity.