Monitoring Node.js Applications with Splunk Infrastructure Monitoring

Over the last decade, JavaScript has evolved from a browser-centric scripting language to a great general-purpose programming language suitable for server-side execution. Managed and supported by the Node.js foundation, an industry consortium with an open governance model, Node.js is an asynchronous, event-driven JavaScript runtime.

Modern Node applications are modular and distributed, with requests flowing through a series of distributed services, web frameworks, caches, queues, and databases. When the performance of such requests breach Service Level Objectives (SLOs), SREs and service owners must understand a number of underlying issues to determine the root cause and restore the Service Level Indicators (SLIs), such as:

  • Which services did requests go through?
  • Which operations were executed?
  • Which service caused performance degradation?
  • What was different in the execution path for the outlier traces?
  • Did the performance degradation happen due to the code execution, edge condition, runtime event, i.e. garbage collection or infrastructure issue, i.e. container running hot or disk space reaching the limit?

In previous blogs, we showed how traditional APM approaches no longer provide reliable visibility into modern distributed environments. You need to rethink how to monitor and troubleshoot microservices performance. In the following sections, we will cover various instrumentation approaches to building a robust observability strategy for your Node applications:

  1. Auto-instrumentation for most popular frameworks, and packages
  2. OpenTracing compliant custom instrumentation
  3. Custom metrics to record and analyze infrastructure, application or business KPIs

Introducing the Splunk Tracing Library for JavaScript: Auto-Instrumentation for Node.js Applications

To accelerate the adoption of distributed tracing for our customers, we are now making the Splunk JavaScript Tracing Library available in beta. This library provides an OpenTracing-compatible tracer and automatically configurable instrumentations for many popular JavaScript server-side libraries and frameworks.

Modern Node applications leverage dozens of modules as transactions pass through distributed services, caches, queues, or databases. Manual instrumentation is burdensome and impractical when you need real-time visibility into how these frameworks are impacting the performance of the service. The Splunk library for Node.js can automatically instrument many popular modules such as Express, MySQL or Redis etc. For a complete list of supported modules, refer to the documentation.

Splunk tracing library for JavaScript can be installed in one step using package manager:

$ npm install signalfx-tracing

Using Auto-Instrumentation:
To start using auto-instrumentation, the Tracer needs to be initialized before any target package is imported:

const tracer = require('signalfx-tracing').init(
  service: ‘my-node-app’,
  url: 'http://my_gateway:9080/v1/trace',
  accessToken: 'myOrganizationAccessToken')

// auto-instrument Express application
const express = require('express') 
const app = express()

Complete examples on how to leverage auto-instrumentation for express and Mongo DB in your Node applications are available on our Github repository

OpenTracing-Compliant Custom Instrumentation

Splunk auto-instrumentation library will automatically instrument key modules in your application. Additionally, you can custom instrument your business logic. Not only can you capture span tags, you can also capture error events and descriptions. OpenTracing specification lists all the standard span tags and log events. The code snippet below shows how to start a span and send span tags:

function myApplicationLogic() {
  const globalTracer =  opentracing.globalTracer()
  const span = globalTracer.startSpan('myApplicationLogic') 
  span.setTag('MyTag', 'MyTagValue')
  span.log({ event: 'Event Information' })

  return myAdditionalApplicationLogic(result => {
    span.setTag('MyResult', result)

Customers leverage the auto-instrumentation library as well as use manual instrumentation to get end-to-end visibility. Once the services are instrumented and Splunk Application Performance Monitoring (APM) is deployed, you start to get the following benefits:

Out-of-the-Box Service Monitoring

Splunk provides pre-built service dashboards with performance characteristics such as rate, error, and duration (RED) metrics. Splunk NoSample™ Distributed Tracing analyzes every transaction, so the performance characteristics are always accurate.

Trace and Span Visualization

Now you can visualize traces with thousands of spans using a Google maps-like experience to quickly zoom-in and zoom-out and display only the inter-service spans to isolate the right traces. The level of auto instrumentation surfaces granular information from instrumented modules such as MySQL queries, errors, Redis connected_clients, etc.

Accurately understand top contributing function calls to latency and errors. With a quick glance, you can validate every node code release whether the performance has improved, stayed the same or degraded by comparing with historical benchmarks.

Infrastructure and application correlation

Splunk provides a unified, single-pane-of-glass view of infrastructure and application monitoring – all contextualized and fully correlated. By quickly visualizing the host metrics such as CPU, memory, network and disk usage alongside application RED metrics as shown in the dashboard above, DevOps teams can quickly determine how the infrastructure performance is impacting the application performance.

Guided Troubleshooting

Splunk Outlier Analyzer™simplifies the troubleshooting process by automatically uncovering patterns in anomalous traces, thereby enabling SRE teams with prescriptive troubleshooting to reduce MTTR

Leverage Splunk Client Library for Node.js to Capture Custom Metrics

Splunk Client Library for Node.js is a programmable interface that allows you to access Splunk metadata and ingest APIs. You can leverage the Node.js client library to capture application or business metrics such as orders placed, logins from a particular location, carts abandoned, etc. for analysis and visualization in Splunk.

Splunk Client Library for Node.js can be installed by one-step npm installer:

$ npm install signalfx

Using Client Library:

const signalfx = require('signalfx');
const client = new signalfx.SignalFx('MY_SIGNALFX_TOKEN');
function fulfillOrder(){  
// business logic to update order shipments
// capture the order with multiple dimensions
            { 'metric': 'widget.orders_shipped',
              'value': order.quantity,
              'dimensions': {'userID': user.ID, ‘userSegment’: user.segment, 

Collecting relevant data using custom metrics enables you to conduct high-cardinality analytics and create custom dashboards to get real-time insights on business KPIs.

You can link the Business KPI dashboard from the service maps so you have the real-time correlation into how application performance is impacting business performance. More details on how to ingest custom metrics types ar available on Splunk Client Library for Node.js documentation site and Github repository.

Get Started with Splunk

Splunk is the only solution which analyzes every transaction across distributed services and provides directed troubleshooting to significantly reduce MTTR while giving complete flexibility for instrumentation so our customers can remain vendor-neutral. Get started by signing up for a free trial of Splunk Infrastructure Monitoring.

Amit Sharma

Posted by