Skip to content

Commit 61be53c

Browse files
authored
fix: correctly get and set top level contentType property (#625)
1 parent 8921952 commit 61be53c

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ project adheres to [Semantic Versioning](http://semver.org/).
1212
### Changed
1313

1414
- Add `Registry.PROMETHEUS_CONTENT_TYPE` and `Registry.OPENMETRICS_CONTENT_TYPE` constants to the TypeScript types
15+
- Correctly read and set `contentType` top level export
1516

1617
### Added
1718

index.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export class Registry<RegistryContentType = PrometheusContentType> {
8181
/**
8282
* Gets the Content-Type of the metrics for use in the response headers.
8383
*/
84-
contentType: RegistryContentType;
84+
readonly contentType: RegistryContentType;
8585

8686
/**
8787
* Set the content type of a registry. Used to change between Prometheus and
@@ -114,8 +114,8 @@ export type Collector = () => void;
114114
export const register: Registry;
115115

116116
/**
117-
* HTTP Content-Type for metrics response headers, defaults to Prometheus text
118-
* format.
117+
* HTTP Content-Type for metrics response headers for the default registry,
118+
* defaults to Prometheus text format.
119119
*/
120120
export const contentType: RegistryContentType;
121121

index.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,18 @@
77

88
exports.register = require('./lib/registry').globalRegistry;
99
exports.Registry = require('./lib/registry');
10-
exports.contentType = require('./lib/registry').globalRegistry.contentType;
11-
exports.prometheusContentType =
12-
require('./lib/registry').PROMETHEUS_CONTENT_TYPE;
13-
exports.openMetricsContentType =
14-
require('./lib/registry').OPENMETRICS_CONTENT_TYPE;
10+
Object.defineProperty(exports, 'contentType', {
11+
configurable: false,
12+
enumerable: true,
13+
get() {
14+
return exports.register.contentType;
15+
},
16+
set(value) {
17+
exports.register.setContentType(value);
18+
},
19+
});
20+
exports.prometheusContentType = exports.Registry.PROMETHEUS_CONTENT_TYPE;
21+
exports.openMetricsContentType = exports.Registry.OPENMETRICS_CONTENT_TYPE;
1522
exports.validateMetricName = require('./lib/validation').validateMetricName;
1623

1724
exports.Counter = require('./lib/counter');

0 commit comments

Comments
 (0)