@opentelemetry/exporter-prometheus
Advanced tools
Comparing version 0.26.0 to 0.27.0
@@ -24,6 +24,6 @@ "use strict"; | ||
const PrometheusSerializer_1 = require("./PrometheusSerializer"); | ||
const PrometheusLabelsBatcher_1 = require("./PrometheusLabelsBatcher"); | ||
const PrometheusAttributesBatcher_1 = require("./PrometheusAttributesBatcher"); | ||
class PrometheusExporter { | ||
// This will be required when histogram is implemented. Leaving here so it is not forgotten | ||
// Histogram cannot have a label named 'le' | ||
// Histogram cannot have a attribute named 'le' | ||
// private static readonly RESERVED_HISTOGRAM_LABEL = 'le'; | ||
@@ -36,3 +36,3 @@ /** | ||
constructor(config = {}, callback) { | ||
this._batcher = new PrometheusLabelsBatcher_1.PrometheusLabelsBatcher(); | ||
this._batcher = new PrometheusAttributesBatcher_1.PrometheusAttributesBatcher(); | ||
/** | ||
@@ -85,3 +85,4 @@ * Request handler used by http library to respond to incoming requests | ||
: PrometheusExporter.DEFAULT_OPTIONS.appendTimestamp; | ||
this._server = http_1.createServer(this._requestHandler); | ||
// unref to prevent prometheus exporter from holding the process open on exit | ||
this._server = http_1.createServer(this._requestHandler).unref(); | ||
this._serializer = new PrometheusSerializer_1.PrometheusSerializer(this._prefix, this._appendTimestamp); | ||
@@ -88,0 +89,0 @@ this._endpoint = (config.endpoint || PrometheusExporter.DEFAULT_OPTIONS.endpoint).replace(/^([^/])/, '/$1'); |
@@ -24,3 +24,3 @@ "use strict"; | ||
} | ||
function escapeLabelValue(str) { | ||
function escapeAttributeValue(str) { | ||
if (typeof str !== 'string') { | ||
@@ -36,3 +36,3 @@ str = String(str); | ||
* | ||
* https://prometheus.io/docs/concepts/data_model/#metric-names-and-labels | ||
* https://prometheus.io/docs/concepts/data_model/#metric-names-and-attributes | ||
* | ||
@@ -90,6 +90,6 @@ * 1. Names must match `[a-zA-Z_:][a-zA-Z0-9_:]*` | ||
if (metricKind === sdk_metrics_base_1.MetricKind.COUNTER || | ||
metricKind === sdk_metrics_base_1.MetricKind.SUM_OBSERVER) { | ||
metricKind === sdk_metrics_base_1.MetricKind.OBSERVABLE_COUNTER) { | ||
return 'counter'; | ||
} | ||
/** MetricKind.UP_DOWN_COUNTER and MetricKind.UP_DOWN_SUM_OBSERVER */ | ||
/** MetricKind.UP_DOWN_COUNTER and MetricKind.OBSERVABLE_UP_DOWN_COUNTER */ | ||
return 'gauge'; | ||
@@ -104,19 +104,19 @@ case sdk_metrics_base_1.AggregatorKind.LAST_VALUE: | ||
} | ||
function stringify(metricName, labels, value, timestamp, additionalLabels) { | ||
let hasLabel = false; | ||
let labelsStr = ''; | ||
for (const [key, val] of Object.entries(labels)) { | ||
const sanitizedLabelName = sanitizePrometheusMetricName(key); | ||
hasLabel = true; | ||
labelsStr += `${labelsStr.length > 0 ? ',' : ''}${sanitizedLabelName}="${escapeLabelValue(val)}"`; | ||
function stringify(metricName, attributes, value, timestamp, additionalAttributes) { | ||
let hasAttribute = false; | ||
let attributesStr = ''; | ||
for (const [key, val] of Object.entries(attributes)) { | ||
const sanitizedAttributeName = sanitizePrometheusMetricName(key); | ||
hasAttribute = true; | ||
attributesStr += `${attributesStr.length > 0 ? ',' : ''}${sanitizedAttributeName}="${escapeAttributeValue(val)}"`; | ||
} | ||
if (additionalLabels) { | ||
for (const [key, val] of Object.entries(additionalLabels)) { | ||
const sanitizedLabelName = sanitizePrometheusMetricName(key); | ||
hasLabel = true; | ||
labelsStr += `${labelsStr.length > 0 ? ',' : ''}${sanitizedLabelName}="${escapeLabelValue(val)}"`; | ||
if (additionalAttributes) { | ||
for (const [key, val] of Object.entries(additionalAttributes)) { | ||
const sanitizedAttributeName = sanitizePrometheusMetricName(key); | ||
hasAttribute = true; | ||
attributesStr += `${attributesStr.length > 0 ? ',' : ''}${sanitizedAttributeName}="${escapeAttributeValue(val)}"`; | ||
} | ||
} | ||
if (hasLabel) { | ||
metricName += `{${labelsStr}}`; | ||
if (hasAttribute) { | ||
metricName += `{${attributesStr}}`; | ||
} | ||
@@ -160,3 +160,3 @@ return `${metricName} ${valueString(value)}${timestamp !== undefined ? ' ' + String(timestamp) : ''}\n`; | ||
const timestamp = core_1.hrTimeToMilliseconds(hrtime); | ||
results += stringify(name, record.labels, value, this._appendTimestamp ? timestamp : undefined, undefined); | ||
results += stringify(name, record.attributes, value, this._appendTimestamp ? timestamp : undefined, undefined); | ||
break; | ||
@@ -169,3 +169,3 @@ } | ||
for (const key of ['count', 'sum']) { | ||
results += stringify(name + '_' + key, record.labels, value[key], this._appendTimestamp ? timestamp : undefined, undefined); | ||
results += stringify(name + '_' + key, record.attributes, value[key], this._appendTimestamp ? timestamp : undefined, undefined); | ||
} | ||
@@ -190,3 +190,3 @@ let cumulativeSum = 0; | ||
} | ||
results += stringify(name + '_bucket', record.labels, cumulativeSum, this._appendTimestamp ? timestamp : undefined, { | ||
results += stringify(name + '_bucket', record.attributes, cumulativeSum, this._appendTimestamp ? timestamp : undefined, { | ||
le: upperBound === undefined || upperBound === Infinity | ||
@@ -193,0 +193,0 @@ ? '+Inf' |
@@ -1,2 +0,2 @@ | ||
export declare const VERSION = "0.26.0"; | ||
export declare const VERSION = "0.27.0"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -20,3 +20,3 @@ "use strict"; | ||
// this is autogenerated file, see scripts/version-update.js | ||
exports.VERSION = '0.26.0'; | ||
exports.VERSION = '0.27.0'; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "@opentelemetry/exporter-prometheus", | ||
"version": "0.26.0", | ||
"version": "0.27.0", | ||
"description": "OpenTelemetry Exporter Prometheus provides a metrics endpoint for Prometheus", | ||
@@ -44,3 +44,3 @@ "main": "build/src/index.js", | ||
"devDependencies": { | ||
"@opentelemetry/api": "^1.0.2", | ||
"@opentelemetry/api": "^1.0.3", | ||
"@types/mocha": "8.2.3", | ||
@@ -53,3 +53,3 @@ "@types/node": "14.17.11", | ||
"rimraf": "3.0.2", | ||
"sinon": "11.1.2", | ||
"sinon": "12.0.1", | ||
"ts-mocha": "8.0.0", | ||
@@ -59,10 +59,10 @@ "typescript": "4.3.5" | ||
"peerDependencies": { | ||
"@opentelemetry/api": "^1.0.2" | ||
"@opentelemetry/api": "^1.0.0" | ||
}, | ||
"dependencies": { | ||
"@opentelemetry/api-metrics": "0.26.0", | ||
"@opentelemetry/core": "1.0.0", | ||
"@opentelemetry/sdk-metrics-base": "0.26.0" | ||
"@opentelemetry/api-metrics": "0.27.0", | ||
"@opentelemetry/core": "1.0.1", | ||
"@opentelemetry/sdk-metrics-base": "0.27.0" | ||
}, | ||
"gitHead": "0f5a5bc906a2166c30a4344e460b7206c0b20bac" | ||
"gitHead": "f5e227f0cb829df1ca2dc220a3e0e8ae0e607405" | ||
} |
@@ -43,7 +43,2 @@ # OpenTelemetry Prometheus Metric Exporter | ||
// Record data using Instrument: It is recommended to keep a reference to the Bound Instrument instead of | ||
// always calling `bind()` method for every operations. | ||
const boundCounter = counter.bind({ pid: process.pid }); | ||
boundCounter.add(10); | ||
// .. some other work | ||
@@ -50,0 +45,0 @@ ``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
74687
641
70
+ Added@opentelemetry/api@1.0.4(transitive)
+ Added@opentelemetry/api-metrics@0.27.0(transitive)
+ Added@opentelemetry/core@1.0.1(transitive)
+ Added@opentelemetry/resources@1.0.1(transitive)
+ Added@opentelemetry/sdk-metrics-base@0.27.0(transitive)
+ Added@opentelemetry/semantic-conventions@1.0.1(transitive)
- Removed@opentelemetry/api-metrics@0.26.0(transitive)
- Removed@opentelemetry/core@1.0.0(transitive)
- Removed@opentelemetry/resources@1.0.0(transitive)
- Removed@opentelemetry/sdk-metrics-base@0.26.0(transitive)
- Removed@opentelemetry/semantic-conventions@1.0.0(transitive)
- Removedsemver@7.6.3(transitive)
Updated@opentelemetry/core@1.0.1