🚀 DAY 4 OF LAUNCH WEEK:Introducing Socket Scanning for OpenVSX Extensions.Learn more →
Socket
Book a DemoInstallSign in
Socket

@voiceflow/metrics

Package Overview
Dependencies
Maintainers
26
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@voiceflow/metrics

Helpers for exposing server-side metrics

latest
Source
npmnpm
Version
1.5.0
Version published
Maintainers
26
Created
Source

metrics

Helpers for exposing server-side metrics

Usage

Client

Client.Metrics

import { Counter } from '@opentelemetry/api-metrics';
import * as VFMetrics from '@voiceflow/metrics';

import log from '@/logger';
import { Config } from '@/types';

export class Metrics extends VFMetrics.Client.Metrics {
  protected counters: {
    foo: {
      bar: Counter;
    };
  };

  constructor(config: Config) {
    super({ ...config, SERVICE_NAME: 'example-service' });

    super.once('ready', ({ port, path }: VFMetrics.Client.Events['ready']) => {
      log.info(`[metrics] exporter ready ${log.vars({ port, path })}`);
    });

    this.counters = {
      foo: {
        bar: this.meter.createCounter('foo_bar', { description: 'Example description' }),
      },
    };
  }

  fooBar(): void {
    this.counters.foo.bar.add(1);
  }
}

const MetricsClient = (config: Config) => new Metrics(config);

export type MetricsType = Metrics;

export default MetricsClient;

Testing

Testing.createBaseConfig

import * as VFMetrics from '@voiceflow/metrics';

const baseConfig = await VFMetrics.Testing.createBaseConfig();

Testing.MetricsAsserter

import * as VFMetrics from '@voiceflow/metrics';

import MetricsClient from '@/lib/clients/metrics';

const metricsAsserter = new VFMetrics.Testing.MetricsAsserter(MetricsClient);

describe('metrics client unit tests', () => {
  it('fooBar', async () => {
    const fixture = await metricsAsserter.assertMetric({ expected: /^foo_bar_total 1 \d+$/m });

    fixture.metrics.fooBar();

    await fixture.assert();
  });
});

Keywords

metrics

FAQs

Package last updated on 24 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts