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:
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:
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.
Installation:
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
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)
span.finish()
})
}
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:
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.
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.
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.
Splunk Outlier Analyzer™simplifies the troubleshooting process by automatically uncovering patterns in anomalous traces, thereby enabling SRE teams with prescriptive troubleshooting to reduce MTTR
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.
Installation:
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
client.send({
cumulative_counters:[
{ 'metric': 'widget.orders_shipped',
'value': order.quantity,
'dimensions': {'userID': user.ID, ‘userSegment’: user.segment,
‘geo’: user.country}}];
})
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.
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.
----------------------------------------------------
Thanks!
Amit Sharma
The Splunk platform removes the barriers between data and action, empowering observability, IT and security teams to ensure their organizations are secure, resilient and innovative.
Founded in 2003, Splunk is a global company — with over 7,500 employees, Splunkers have received over 1,020 patents to date and availability in 21 regions around the world — and offers an open, extensible data platform that supports shared data across any environment so that all teams in an organization can get end-to-end visibility, with context, for every interaction and business process. Build a strong data foundation with Splunk.