Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
@opentelemetry/metrics
Advanced tools
OpenTelemetry metrics allow a user to collect data and export it to a metrics backend like Prometheus.
npm install --save @opentelemetry/metrics
Choose this kind of metric when the value is a quantity, the sum is of primary interest, and the event count and value distribution are not of primary interest. It is restricted to non-negative increments. Example uses for Counter:
const { MeterProvider } = require('@opentelemetry/metrics');
// Initialize the Meter to capture measurements in various ways.
const meter = new MeterProvider().getMeter('your-meter-name');
const counter = meter.createCounter('metric_name', {
description: 'Example of a counter'
});
const labels = { pid: process.pid };
// Create a BoundInstrument associated with specified label values.
const boundCounter = counter.bind(labels);
boundCounter.add(10);
UpDownCounter
is similar to Counter
except that it supports negative increments. It is generally useful for capturing changes in an amount of resources used, or any quantity that rises and falls during a request.
Example uses for UpDownCounter:
const { MeterProvider } = require('@opentelemetry/metrics');
// Initialize the Meter to capture measurements in various ways.
const meter = new MeterProvider().getMeter('your-meter-name');
const counter = meter.createUpDownCounter('metric_name', {
description: 'Example of a UpDownCounter'
});
const labels = { pid: process.pid };
// Create a BoundInstrument associated with specified label values.
const boundCounter = counter.bind(labels);
boundCounter.add(Math.random() > 0.5 ? 1 : -1);
Choose this kind of metric when only last value is important without worry about aggregation. The callback can be sync or async.
const { MeterProvider } = require('@opentelemetry/metrics');
const meter = new MeterProvider().getMeter('your-meter-name');
// async callback - for operation that needs to wait for value
meter.createValueObserver('your_metric_name', {
description: 'Example of an async observer with callback',
}, async (observerResult) => {
const value = await getAsyncValue();
observerResult.observe(value, { label: '1' });
});
function getAsyncValue() {
return new Promise((resolve) => {
setTimeout(()=> {
resolve(Math.random());
}, 100);
});
}
// sync callback in case you don't need to wait for value
meter.createValueObserver('your_metric_name', {
description: 'Example of a sync observer with callback',
}, (observerResult) => {
observerResult.observe(getRandomValue(), { label: '1' });
observerResult.observe(getRandomValue(), { label: '2' });
});
function getRandomValue() {
return Math.random();
}
Choose this kind of metric when sum is important and you want to capture any value that starts at zero and rises or falls throughout the process lifetime. The callback can be sync or async.
const { MeterProvider } = require('@opentelemetry/metrics');
const meter = new MeterProvider().getMeter('your-meter-name');
// async callback - for operation that needs to wait for value
meter.createUpDownSumObserver('your_metric_name', {
description: 'Example of an async observer with callback',
}, async (observerResult) => {
const value = await getAsyncValue();
observerResult.observe(value, { label: '1' });
});
function getAsyncValue() {
return new Promise((resolve) => {
setTimeout(()=> {
resolve(Math.random());
}, 100);
});
}
// sync callback in case you don't need to wait for value
meter.createUpDownSumObserver('your_metric_name', {
description: 'Example of a sync observer with callback',
}, (observerResult) => {
observerResult.observe(getRandomValue(), { label: '1' });
});
function getRandomValue() {
return Math.random();
}
Choose this kind of metric when collecting a sum that never decreases. The callback can be sync or async.
const { MeterProvider } = require('@opentelemetry/metrics');
const meter = new MeterProvider().getMeter('your-meter-name');
// async callback in case you need to wait for values
meter.createSumObserver('example_metric', {
description: 'Example of an async sum observer with callback',
}, async (observerResult) => {
const value = await getAsyncValue();
observerResult.observe(value, { label: '1' });
});
function getAsyncValue() {
return new Promise((resolve) => {
setTimeout(() => {
resolve(Math.random());
}, 100)
});
}
// sync callback in case you don't need to wait for values
meter.createSumObserver('example_metric', {
description: 'Example of a sync sum observer with callback',
}, (observerResult) => {
const value = getRandomValue();
observerResult.observe(value, { label: '1' });
});
function getRandomValue() {
return Math.random();
}
Choose this kind of metric when you need to update multiple observers with the results of a single async calculation.
const { MeterProvider } = require('@opentelemetry/metrics');
const { PrometheusExporter } = require('@opentelemetry/exporter-prometheus');
const exporter = new PrometheusExporter(
{
startServer: true,
},
() => {
console.log('prometheus scrape endpoint: http://localhost:9464/metrics');
},
);
const meter = new MeterProvider({
exporter,
interval: 3000,
}).getMeter('example-observer');
const cpuUsageMetric = meter.createValueObserver('cpu_usage_per_app', {
description: 'CPU',
});
const MemUsageMetric = meter.createValueObserver('mem_usage_per_app', {
description: 'Memory',
});
meter.createBatchObserver((observerBatchResult) => {
getSomeAsyncMetrics().then(metrics => {
observerBatchResult.observe({ app: 'myApp' }, [
cpuUsageMetric.observation(metrics.value1),
MemUsageMetric.observation(metrics.value2)
]);
});
});
function getSomeAsyncMetrics() {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve({
value1: Math.random(),
value2: Math.random(),
});
}, 100)
});
}
See examples/prometheus for a short example.
ValueRecorder
is a non-additive synchronous instrument useful for recording any non-additive number, positive or negative.
Values captured by ValueRecorder.record(value)
are treated as individual events belonging to a distribution that is being summarized.
ValueRecorder
should be chosen either when capturing measurements that do not contribute meaningfully to a sum, or when capturing numbers that are additive in nature, but where the distribution of individual increments is considered interesting.
Apache 2.0 - See LICENSE for more information.
0.24.0
opentelemetry-core
, opentelemetry-exporter-jaeger
, opentelemetry-exporter-zipkin
, opentelemetry-node
, opentelemetry-resource-detector-aws
, opentelemetry-resource-detector-gcp
, opentelemetry-resources
, opentelemetry-semantic-conventions
, opentelemetry-web
opentelemetry-exporter-collector-proto
, opentelemetry-exporter-collector
opentelemetry-instrumentation-http
opentelemetry-web
opentelemetry-instrumentation
opentelemetry-exporter-collector
opentelemetry-exporter-collector-grpc
opentelemetry-exporter-collector-proto
opentelemetry-resource-detector-aws
opentelemetry-propagator-b3
opentelemetry-exporter-collector-grpc
opentelemetry-exporter-collector-grpc
, opentelemetry-exporter-jaeger
, opentelemetry-instrumentation
, opentelemetry-node
, opentelemetry-sdk-node
, opentelemetry-shim-opentracing
, opentelemetry-tracing
, opentelemetry-web
template
FAQs
OpenTelemetry metrics SDK
The npm package @opentelemetry/metrics receives a total of 5,209 weekly downloads. As such, @opentelemetry/metrics popularity was classified as popular.
We found that @opentelemetry/metrics demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
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.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.