diff --git a/README.md b/README.md index ef88010..f6e547c 100644 --- a/README.md +++ b/README.md @@ -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` | `{}` | diff --git a/lib/src/context.ts b/lib/src/context.ts index 2ff2c74..19ed15e 100644 --- a/lib/src/context.ts +++ b/lib/src/context.ts @@ -66,6 +66,7 @@ export interface Context { hostnameLabelName: string; metricsEndpoint: boolean; metricsEndpointPath: string; + prefix: string; register: Registry; skipMetrics: SkipMetricsMap; } @@ -83,6 +84,7 @@ export function generateContext( hostnameLabelName: 'hostname', metricsEndpoint: true, metricsEndpointPath: '/metrics', + prefix: '', register, ...options, skipMetrics: { diff --git a/lib/src/metrics.ts b/lib/src/metrics.ts index 7e4a16b..d70982a 100644 --- a/lib/src/metrics.ts +++ b/lib/src/metrics.ts @@ -190,7 +190,7 @@ export type Metrics = { export function generateMetrics( register: Registry, - { durationHistogramsBuckets, skipMetrics }: Context + { durationHistogramsBuckets, skipMetrics, prefix }: Context ): Metrics { return metricsConfig.reduce((acc, metric) => { acc[metric.name] = { @@ -200,7 +200,7 @@ export function generateMetrics( }; const commonConfig = { - name: metric.name, + name: prefix + metric.name, help: metric.help, labelNames: metric.labelNames, registers: [register]