Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

@platformatic/metrics

Package Overview
Dependencies
Maintainers
9
Versions
219
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@platformatic/metrics - npm Package Compare versions

Comparing version
3.37.0
to
3.38.0
+2
-6
index.js

@@ -319,10 +319,6 @@ import collectHttpMetrics from '@platformatic/http-metrics'

export function buildCustomLabelsConfig (customLabelsConfig) {
// Default: use telemetry_id from x-plt-telemetry-id header
if (!customLabelsConfig || customLabelsConfig.length === 0) {
return {
customLabels: ['telemetry_id'],
getCustomLabels: req => {
const telemetryId = req.headers?.['x-plt-telemetry-id'] ?? 'unknown'
return { telemetry_id: telemetryId }
}
customLabels: [],
getCustomLabels: () => ({})
}

@@ -329,0 +325,0 @@ }

{
"name": "@platformatic/metrics",
"version": "3.37.0",
"version": "3.38.0",
"description": "Platformatic Capability Metrics",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -81,5 +81,5 @@ import assert from 'node:assert'

histogramMetric.observe({ method: 'GET', telemetry_id: 'test' }, 0.1)
histogramMetric.observe({ method: 'GET', telemetry_id: 'test' }, 0.2)
histogramMetric.observe({ method: 'GET', telemetry_id: 'test' }, 0.3)
histogramMetric.observe({ method: 'GET' }, 0.1)
histogramMetric.observe({ method: 'GET' }, 0.2)
histogramMetric.observe({ method: 'GET' }, 0.3)

@@ -110,5 +110,5 @@ const metricsBefore = await result.registry.getMetricsAsJSON()

summaryMetric.observe({ method: 'POST', telemetry_id: 'test' }, 0.15)
summaryMetric.observe({ method: 'POST', telemetry_id: 'test' }, 0.25)
summaryMetric.observe({ method: 'POST', telemetry_id: 'test' }, 0.35)
summaryMetric.observe({ method: 'POST' }, 0.15)
summaryMetric.observe({ method: 'POST' }, 0.25)
summaryMetric.observe({ method: 'POST' }, 0.35)

@@ -133,26 +133,17 @@ const metricsBefore = await result.registry.getMetricsAsJSON()

// Tests for buildCustomLabelsConfig
test('buildCustomLabelsConfig returns default telemetry_id when no config provided', () => {
test('buildCustomLabelsConfig returns empty custom labels when no config provided', () => {
const result = buildCustomLabelsConfig(undefined)
assert.deepStrictEqual(result.customLabels, ['telemetry_id'])
assert.deepStrictEqual(result.customLabels, [])
assert.strictEqual(typeof result.getCustomLabels, 'function')
// Test default getCustomLabels function
const labels = result.getCustomLabels({ headers: { 'x-plt-telemetry-id': 'test-id' } })
assert.deepStrictEqual(labels, { telemetry_id: 'test-id' })
assert.deepStrictEqual(result.getCustomLabels({}), {})
})
test('buildCustomLabelsConfig returns default telemetry_id when empty array provided', () => {
test('buildCustomLabelsConfig returns empty custom labels when empty array provided', () => {
const result = buildCustomLabelsConfig([])
assert.deepStrictEqual(result.customLabels, ['telemetry_id'])
assert.deepStrictEqual(result.customLabels, [])
assert.deepStrictEqual(result.getCustomLabels({}), {})
})
test('buildCustomLabelsConfig uses unknown as default when header is missing', () => {
const result = buildCustomLabelsConfig(undefined)
const labels = result.getCustomLabels({ headers: {} })
assert.deepStrictEqual(labels, { telemetry_id: 'unknown' })
})
test('buildCustomLabelsConfig builds custom labels from configuration', () => {

@@ -244,1 +235,17 @@ const config = [

})
test('httpMetrics does not include telemetry_id label by default', async () => {
const result = await collectMetrics('test-service', 1, { httpMetrics: true })
const histogramMetric = result.registry.getSingleMetric('http_request_all_duration_seconds')
assert.ok(histogramMetric, 'histogram metric should exist')
histogramMetric.observe({ method: 'GET' }, 0.1)
const metrics = await result.registry.getMetricsAsJSON()
const histogram = metrics.find(m => m.name === 'http_request_all_duration_seconds')
const value = histogram.values.find(v => v.labels.method === 'GET')
assert.ok(value, 'should have a value with method=GET')
assert.strictEqual(value.labels.telemetry_id, undefined)
})