Skip to content
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 @@ -15,6 +15,7 @@ project adheres to [Semantic Versioning](http://semver.org/).

### Changed

- Add `Registry#getMetricsAsString()` to the TypeScript definitions
- Improve types for no labels
- perf: Faster stats gathering with lower memory overhead
- Simplified number format logic
Expand Down
6 changes: 6 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ export class Registry<
*/
getMetricsAsJSON(): Promise<MetricObjectWithValues<MetricValue<string>>[]>;

/**
* Get string representation for a metric
* @param metric Metric to convert to a string
*/
getMetricsAsString<T extends string>(metric: Metric<T>): Promise<string>;

/**
* Get all metrics as objects
*/
Expand Down
12 changes: 12 additions & 0 deletions test/typescript.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Counter, Registry } from '../index';

const registry = new Registry();
const counter = new Counter({
name: 'typescript_test_counter',
help: 'TypeScript test counter',
registers: [registry],
});

const metricsText: Promise<string> = registry.getMetricsAsString(counter);

void metricsText;
Loading