Skip to content

Commit

Permalink
fix: correctly get and set top level contentType property (#625)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Apr 16, 2024
1 parent 8921952 commit 61be53c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class Registry<RegistryContentType = PrometheusContentType> {
/**
* 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
Expand Down Expand Up @@ -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;

Expand Down
17 changes: 12 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 61be53c

Please sign in to comment.