Skip to main content
Version: 6.1.0

Use OpenTelemetry

In this How To section, we'll discuss OpenTelemetry and how to use it to locate IO bottlenecks in your application.


HTTP Tracing

NodeSource has introduced Tracing support, a facility to gather information throughout the lifecycle of an HTTP/DNS/Other request. The collected information can be used for debugging latency issues, service monitoring, and more. This is a valuable addition for users interested in debugging request latency. Tracing traces user requests through a Node application, collecting data that can help find the cause of latency issues, errors, and other problems.

Enabling Tracing via N|S Console UI

  1. Enter your process.
  2. Click on Process configuration.
  3. Activate the toggle for Tracing.

Process Configuration

Dynamic Configuration

Distributed Tracing UI

In the N|Solid Console, select Tracing from the global filter menu bar.

Applications Tab

The view will be shown as below:

Tracing View

Tracing consists of three key components:

Tracing Components

  • Timeline Graph: a timeline graph of tracing data showing the density of the number of tracing spans.
  • Filter: a filter input area to filter the results by attributes of the span.
  • Spans (Results): a span is the building block of a trace and is a named, timed operation that represents a piece of the workflow in the distributed system. Multiple spans are pieced together to create a trace.

Timeline Graph

A timeline graph displays the density of the number of tracing spans. Below is the description of the color of a slot on the timeline graph:

ColorDescription
greeneverything is ok
yellowmaybe you should look at this
reddefinitely you should look at this

Assume that a simple request was made to the “console” service to monitor traces: Tracing Example

As a result, the Console displays the whole “span” information.

Span

A span is the building block of a trace and is a named, timed operation that represents a piece of the workflow in the distributed system. Multiple spans are pieced together to create a trace.

Traces are often viewed as a tree of spans that reflects the time that each span started and completed. It also shows you the relationship between spans. A trace starts with a root span where the request starts. This root span can have one or more child spans, and each one of those child spans can have child spans.

Inspecting Span Details

To inspect the span details of a span, click on the title Service & Operation:

Span Details

Below are the attributes of the span:

AttributeDescription
idthe id of the application
appthe name of application
hostnamethe name of the host machine
tagsthe tags of the application
span_attributes_http_methodthe http method of span attributes
durationthe duration of the span
span_attributes_http_status_codethe http status code of the span attributes
span_attributes_http_status_textthe http status text of the span attributes
span_attributes_http_urlthe http url of the span attributes
span_endthe end time of the span
span_idthe id of the span
span_namethe name of the span
span_parentIdthe parent ID of the span
span_startthe start time of the span
span_status_codethe status code of the span
span_threadIdthe thread ID of the span
span_traceIdthe trace ID of the span
span_typethe type of the span

Let's authenticate using the console service, which is going to perform a request to the google-auth-service to authenticate the user.

The graph below represents a “path”, from the console service to the authentication service, N|Solid will monitor the HTTP traces in this distributed system.

Tracing Path

As such, the graph shows the whole “path”, starting from the console and finishing with the SMS service. This is how distributed tracing works using N|Solid managed systems.

The collected information can be used for debugging latency issues, service monitoring, and more. This is a valuable addition for users interested in debugging request latency. Tracing traces user requests through multiple Node applications, collecting data that can help find the cause of latency issues, errors, and other problems in a distributed system.

Changing Update Settings

You can configure the update settings for distributed tracing at the top of the Distributed Tracing view:

Distributed Tracing Settings

You can turn on or off Real Time Update and change the update interval. The default update interval is 10 seconds. Available options are 10, 15, 30, or 60 seconds.

Changing Time Range

To change the time range of tracing, click the calendar icon below the timeline graph:

Time Range Calendar

It will show a calendar for selecting a time range. The timeline graph range is updated every 1 minute, with an interval of 1 minute for the date range to move.

Filtering Results

Filtering the results by attributes of the span is easy for users. Just tap the Filter input area and select the attribute(s) you want to filter by:

Filtering Results

HTTP Tracing

Enabling Tracing via N|Solid

To enable Tracing using N|Solid, set the environment variable NSOLID_TRACING_ENABLED=1. By enabling this feature, you can troubleshoot HTTP, DNS, and other network request problems that you might encounter using the N|Solid Console.

Using Distributed Tracing

Distributed tracing in the N|Solid Console is an extension of HTTP tracing in N|Solid. This documentation will use the following examples to cover how it works on the Console side under the following conditions:

  1. An application handling the authentication process:
  // console.js
const http = require('http')
const PORT = process.env.PORT || 3000
http.createServer((req, res) => {
if (req.url === '/auth') {
console.log('AUTH handler')
const authURL = 'http://localhost:4000'
const gReq = http.request(authURL)
gReq.end()
gReq.on('close', () => res.writeHead(200).end('Google made it'))
} else if (req.url === '/auth-2fa') {
const authURL = 'http://localhost:4000/2fa'
const twoFactor = http.request(authURL)
twoFactor.end()
twoFactor.on('close', () => res.writeHead(200).end('Auth made it with sms'))
} else {
res.end('ok')
}
}).listen(PORT)
  1. Another application doing the two-factor authentication process (google-auth):
  // google-auth.js
const http = require('http')
const PORT = process.env.PORT || 4000
http.createServer((req, res) => {
if (req.url === '/2fa') {
const smsServiceURL = 'http://localhost:5000'
const smsService = http.request(smsServiceURL)
res.writeHead(200).end('Auth made it')
smsService.end()
} else {
console.log('Auth root handler')
res.writeHead(200).end('ok')
}
}).listen(PORT)
  1. The authentication requires a two-factor authentication
  2. The two-factor authentication service uses an SMS service to send a message (twilio):
  // twilio.js
const http = require('http')
const PORT = process.env.PORT || 5000
http.createServer((req, res) => {
res.writeHead(200).end('ok')
}).listen(PORT)
  1. The N|Solid Console receives traces from all services involved in the distributed system.