Deploy this integration to send custom metrics from your Node.js application to

The provided example uses the OpenTelemetry JS SDK and is based on OpenTelemetry exporter collector proto.

Before you begin, you’ll need: Node 8 or higher

We advise to use this integration with the Metrics backend. However, the integration is compatible with all backends that support metrics in prometheuesrmotewrite format.

Configuring your Node.js applicatin to send custom metrics to

Install the SDK package
npm install logzio-nodejs-metrics-sdk@0.2.1
Initialize the exporter and meter provider

Add the following code to your application:

const MeterProvider = require('@opentelemetry/sdk-metrics-base');
const sdk =  require('logzio-nodejs-metrics-sdk');

const collectorOptions = {
    url: '<<LISTENER-HOST>>',
    headers: {
        "Authorization":"Bearer <<PROMETHEUS-METRICS-SHIPPING-TOKEN>>"
// Initialize the exporter
const metricExporter = new sdk.RemoteWriteExporter(collectorOptions);

// Initialize the meter provider
const meter = new MeterProvider.MeterProvider({
    exporter: metricExporter,
    interval: 15000, // Push interval in milliseconds

Replace the placeholders to match your specifics. (They are indicated by the double angle brackets << >>):

  • Replace <<PROMETHEUS-METRICS-SHIPPING-TOKEN>> with a token for the Metrics account you want to ship to.
    Here’s how to look up your Metrics token.
  • Replace <<LISTENER-HOST>> with the Listener URL for your region, configured to use port 8052 for http traffic, or port 8053 for https traffic. For example, if your account is hosted on AWS US East, or if hosted on Azure West Europe.
Add required metrics to the code

This integration allows you to use the following metrics:

Name Behavior
Counter Metric value can only go up or be reset to 0, calculated per counter.Add(context,value,labels) request.
UpDownCounter Metric value can arbitrarily increment or decrement, calculated per updowncounter.Add(context,value,labels) request.
Histogram Metric values captured by the histogram.Record(context,value,labels) function, calculated per request.

For more information on each of these metrics, see the OpenTelemetry documentation.

To add a required metric to your code, copy and paste the required metric code to your application, placing it after the initialization code:

// Create your first counter metric
const requestCounter = meter.createCounter('Counter', {
    description: 'Example of a Counter', 
// Define some labels for your metrics
const labels = { environment: 'prod' };
// Record some value
// In logzio Metrics you will see the following metric:
// Counter_total{environment: 'prod'} 1.0
// Create UpDownCounter metric
const upDownCounter = meter.createUpDownCounter('UpDownCounter', {
    description: 'Example of a UpDownCounter',
// Define some labels for your metrics
const labels = { environment: 'prod' };
// Record some values
// In logzio you will see the following metric:
// UpDownCounter{environment: 'prod'} 4.0
// Create ValueRecorder metric
const histogram = meter.createHistogram('test_histogram', {
    description: 'Example of a histogram',
// Define some labels for your metrics
const labels = { environment: 'prod' };
// Record some values
// In logzio you will see the following metrics:
// test_histogram_sum{environment: 'prod'} 50.0
// test_histogram_count{environment: 'prod'} 2.0
// test_histogram_avg{environment: 'prod'} 25.0
Run your application

Run your application to start sending metrics to

Check for your metrics

Give your metrics some time to get from your system to ours, and then open Metrics dashboard.