@graphql-yoga/plugin-prometheus
Version:
Prometheus plugin for GraphQL Yoga.
64 lines (63 loc) • 2.86 kB
TypeScript
import { type DocumentNode } from 'graphql';
import { Plugin } from 'graphql-yoga';
import { createCounter, createHistogram, createSummary, getCounterFromConfig, getHistogramFromConfig, getSummaryFromConfig, type CounterAndLabels, type CounterMetricOption, type PrometheusTracingPluginConfig as EnvelopPrometheusTracingPluginConfig, type FillLabelsFnParams, type HistogramAndLabels, type HistogramMetricOption, type SummaryAndLabels, type SummaryMetricOption } from '@envelop/prometheus';
export { type CounterAndLabels, createCounter, createHistogram, createSummary, type FillLabelsFnParams, type HistogramAndLabels, type SummaryAndLabels, getHistogramFromConfig, getCounterFromConfig, getSummaryFromConfig, type HistogramMetricOption, type CounterMetricOption, type SummaryMetricOption, };
export type PrometheusTracingPluginConfig = Omit<EnvelopPrometheusTracingPluginConfig, 'metrics'> & {
/**
* The Prometheus metrics to report.
*
* By default, the following metrics are enabled:
*
* - `graphql_envelop_deprecated_field`
* - `graphql_envelop_request`
* - `graphql_envelop_request_duration`
* - `graphql_envelop_request_time_summary`
* - `graphql_envelop_phase_parse`
* - `graphql_envelop_phase_validate`
* - `graphql_envelop_phase_context`
* - `graphql_envelop_error_result`
* - `graphql_envelop_phase_execute`
* - `graphql_envelop_phase_subscribe`
* - `graphql_envelop_schema_change`
* - `graphql_yoga_http_duration`
*
*/
metrics?: EnvelopPrometheusTracingPluginConfig['metrics'] & {
/**
* Tracks the duration of HTTP requests. It reports the time spent to
* process each incoming request as an histogram.
*
* You can pass multiple type of values:
* - boolean: Disable or Enable the metric with default configuration
* - string: Enable the metric with custom name
* - number[]: Enable the metric with custom buckets
* - ReturnType<typeof createHistogram>: Enable the metric with custom configuration
*/
graphql_yoga_http_duration?: HistogramMetricOption<'request', string, HTTPFillLabelParams>;
};
labels?: {
/**
* The HTTP method of the request
*/
method?: boolean;
/**
* The status code of the response
*/
statusCode?: boolean;
/**
* The url of the HTTP request
*/
url?: boolean;
};
/**
* The endpoint to serve metrics exposed by this plugin.
* Defaults to "/metrics".
*/
endpoint?: string | boolean;
};
type HTTPFillLabelParams = FillLabelsFnParams & {
document: DocumentNode;
request: Request;
response: Response;
};
export declare function usePrometheus(options: PrometheusTracingPluginConfig): Plugin;