Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correctly get and set top level contentType property #625

Merged
merged 6 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this into getter/setter is the fix (first commit of PR)

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
Loading