JY Tan
12/26/2024, 10:11 PMimport { NodeSDK } from "@opentelemetry/sdk-node";
import { OTLPMetricExporter } from "@opentelemetry/exporter-metrics-otlp-proto";
import { PeriodicExportingMetricReader } from "@opentelemetry/sdk-metrics";
import { metrics, Counter, Gauge, Histogram } from "@opentelemetry/api";
// Configure the OTLP exporter
const metricExporter = new OTLPMetricExporter({
url: "<http://0.0.0.0:4318/v1/metrics>", // Signoz OTLP HTTP endpoint
});
const metricReader = new PeriodicExportingMetricReader({
exporter: metricExporter,
exportIntervalMillis: 1000,
});
// Initialize the SDK
const sdk = new NodeSDK({
metricReader,
});
sdk.start();
const meter = metrics.getMeter("app");
// Create metrics
const testCounter: Counter = meter.createCounter("test_abc", {
description: "Total number of HTTP requests",
unit: "1",
});
const testGauge: Gauge = meter.createGauge("test_gauge", {
description: "Total number of HTTP requests",
});
const testHistogram: Histogram = meter.createHistogram("test_time_taken", {
description: "Total time taken for HTTP requests",
unit: "ms",
});
// Call the metrics
testCounter.add(25);
testCounter.add(10);
testGauge.record(10);
testHistogram.record(10);
testHistogram.record(15);
i'm trying to plot these on a dashboard. strangely, for the counter and histogram, i do see the names of the metrics being registered but there's no data when i try to query (see screenshot below, i've sent the request multiple times), but for the gauge i am able to query and plot the data.
probably missing something obvious, appreciate if someone can point me in the right direction!