Typescript Metrics

Learn how to setup metrics in your Typescript application.

Setup

Open the Vigilant dashboard and generate an API key.

Install

Install the Vigilant SDK in your Typescript application.

npm install vigilant-js

Initialize

Initialize the Vigilant SDK in your Typescript application.

import { initVigilant } from 'vigilant-js'

initVigilant({
  name: 'backend',
  token: 'tk_1234567890', // Use your API key from the dashboard
})

Metrics Functions

The Vigilant SDK provides several functions to emit metrics.

import { metricCounter, metricGauge, metricHistogram, GaugeMode } from 'vigilant-js'

// Create a counter metric
metricCounter('user_login_count', 1)

// Create a counter metric with a custom tag
metricCounter('user_login_count', 1, { "env": "prod" })

// Create a gauge metric
metricGauge('active_users', 1, GaugeMode.Set)

// Create a gauge metric with a custom tag
metricGauge('active_users', 1, GaugeMode.Set, { "env": "prod" })

// Create a histogram metric
metricHistogram('http_request_duration', 123.4)

// Create a histogram metric with a custom tag
metricHistogram('http_request_duration', 123.4, { "env": "prod" })

Optional Setup

The Vigilant SDK exposes a few setup options when you initialize it.

import { initVigilant } from 'vigilant-js'

initVigilant({
  // Disable all functionality
  noop: true,

  // Disable automatic capture of logs, only direct logs are captured
  autocapture: false,

  // Disables logging all logs to the console
  passthrough: false,
})