diff --git a/CHANGELOG.md b/CHANGELOG.md index bfdc0edc..3f947b5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ project adheres to [Semantic Versioning](http://semver.org/). ### Changed - Add `Registry.PROMETHEUS_CONTENT_TYPE` and `Registry.OPENMETRICS_CONTENT_TYPE` constants to the TypeScript types +- Correctly read and set `contentType` top level export ### Added diff --git a/index.d.ts b/index.d.ts index 61439abc..99d12677 100644 --- a/index.d.ts +++ b/index.d.ts @@ -81,7 +81,7 @@ export class Registry { /** * Gets the Content-Type of the metrics for use in the response headers. */ - contentType: RegistryContentType; + readonly contentType: RegistryContentType; /** * Set the content type of a registry. Used to change between Prometheus and @@ -114,8 +114,8 @@ export type Collector = () => void; export const register: Registry; /** - * HTTP Content-Type for metrics response headers, defaults to Prometheus text - * format. + * HTTP Content-Type for metrics response headers for the default registry, + * defaults to Prometheus text format. */ export const contentType: RegistryContentType; diff --git a/index.js b/index.js index 7f6e167a..f78105fc 100644 --- a/index.js +++ b/index.js @@ -7,11 +7,18 @@ exports.register = require('./lib/registry').globalRegistry; exports.Registry = require('./lib/registry'); -exports.contentType = require('./lib/registry').globalRegistry.contentType; -exports.prometheusContentType = - require('./lib/registry').PROMETHEUS_CONTENT_TYPE; -exports.openMetricsContentType = - require('./lib/registry').OPENMETRICS_CONTENT_TYPE; +Object.defineProperty(exports, 'contentType', { + configurable: false, + enumerable: true, + get() { + return exports.register.contentType; + }, + set(value) { + exports.register.setContentType(value); + }, +}); +exports.prometheusContentType = exports.Registry.PROMETHEUS_CONTENT_TYPE; +exports.openMetricsContentType = exports.Registry.OPENMETRICS_CONTENT_TYPE; exports.validateMetricName = require('./lib/validation').validateMetricName; exports.Counter = require('./lib/counter');