Socket
Socket
Sign inDemoInstall

@opentelemetry/sdk-metrics

Package Overview
Dependencies
Maintainers
3
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opentelemetry/sdk-metrics

OpenTelemetry metrics SDK


Version published
Weekly downloads
5.4M
decreased by-0.35%
Maintainers
3
Weekly downloads
 
Created

What is @opentelemetry/sdk-metrics?

The @opentelemetry/sdk-metrics package is part of the OpenTelemetry JavaScript SDK, which provides tools for collecting and exporting metrics data from your applications. It allows you to create and manage various types of metrics such as counters, observers, and histograms, and to export this data to different backends for analysis and monitoring.

What are @opentelemetry/sdk-metrics's main functionalities?

Creating a Meter

This feature allows you to create a Meter instance from the MeterProvider. The Meter is used to create and manage metrics.

{"const { MeterProvider } = require('@opentelemetry/sdk-metrics');
const meterProvider = new MeterProvider();
const meter = meterProvider.getMeter('your-meter-name');"}

Creating a Counter Metric

This feature allows you to create a Counter metric, which can be used to record the number of times an event occurs.

{"const { MeterProvider } = require('@opentelemetry/sdk-metrics');
const meterProvider = new MeterProvider();
const meter = meterProvider.getMeter('your-meter-name');
const counter = meter.createCounter('requests', {
  description: 'Count of requests received'
});"}

Recording Metrics

This feature allows you to record metrics data. In this example, we increment the counter by 1 for the '/home' route.

{"const { MeterProvider } = require('@opentelemetry/sdk-metrics');
const meterProvider = new MeterProvider();
const meter = meterProvider.getMeter('your-meter-name');
const counter = meter.createCounter('requests');
counter.add(1, { route: '/home' });"}

Exporting Metrics

This feature allows you to export the collected metrics data. Here, we use the ConsoleMetricExporter to print metrics to the console at a regular interval.

{"const { MeterProvider } = require('@opentelemetry/sdk-metrics');
const { ConsoleMetricExporter } = require('@opentelemetry/exporter-metrics-console');
const meterProvider = new MeterProvider({
  exporter: new ConsoleMetricExporter(),
  interval: 1000
});
const meter = meterProvider.getMeter('your-meter-name');"}

Other packages similar to @opentelemetry/sdk-metrics

Keywords

FAQs

Package last updated on 07 May 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc