Skip to content
Open
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ For a complete working example, please have a look over the `example` project in
| `hostnameLabelName` | The name of the `hostname` label. | `String` | `hostname` |
| `metricsEndpoint` | Flag to enable/disable the metrics endpoint. If you disable this, you can use the `registerPrometheusMetricsEndpoint` method to enable the metrics endpoint. | `Boolean` | `true` |
| `metricsEndpointPath` | HTTP path where the metrics will be published. | `String` | `"/metrics"` |
| `prefix` | An optional prefix for metric names. | `String` | `""` |
| `register` | Prometheus client registry to be used by Apollo Metrics. By default, it is also used by the default metrics. | `Registry` | `register` |
| `skipMetrics` | A key-value map that controls if a metric is enabled or disabled. | `SkipMetricsMap` | `{}` |

Expand Down
2 changes: 2 additions & 0 deletions lib/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export interface Context<C = AppContext, S = Source, A = Args> {
hostnameLabelName: string;
metricsEndpoint: boolean;
metricsEndpointPath: string;
prefix: string;
register: Registry;
skipMetrics: SkipMetricsMap<C, S, A>;
}
Expand All @@ -83,6 +84,7 @@ export function generateContext<C = BaseContext, S = Source, A = Args>(
hostnameLabelName: 'hostname',
metricsEndpoint: true,
metricsEndpointPath: '/metrics',
prefix: '',
register,
...options,
skipMetrics: {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export type Metrics = {

export function generateMetrics<C = AppContext, S = Source, A = Args>(
register: Registry,
{ durationHistogramsBuckets, skipMetrics }: Context<C, S, A>
{ durationHistogramsBuckets, skipMetrics, prefix }: Context<C, S, A>
): Metrics {
return metricsConfig.reduce((acc, metric) => {
acc[metric.name] = {
Expand All @@ -200,7 +200,7 @@ export function generateMetrics<C = AppContext, S = Source, A = Args>(
};

const commonConfig = {
name: metric.name,
name: prefix + metric.name,
help: metric.help,
labelNames: metric.labelNames,
registers: [register]
Expand Down