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:
1npm install bunyan
Basic setup requires minimal code:
12345689111213const 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 contextconst 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:
12356791012131516171819202223const opentelemetry = require('@opentelemetry/api');const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');const { BunyanInstrumentation } = require('@opentelemetry/instrumentation-bunyan');// Set up OpenTelemetryconst provider = new NodeTracerProvider();provider.register();// Configure Bunyan instrumentationconst bunyanInstrumentation = new BunyanInstrumentation({// Configuration options});// Your existing Bunyan logger will now include trace context automaticallyconst bunyan = require('bunyan');const log = bunyan.createLogger({name: 'myapp',level: 'info'});// This log will automatically include OpenTelemetry trace contextlog.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.
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.