UNPKG

@envelop/prometheus

Version:

This plugin tracks the complete execution flow, and reports metrics using Prometheus tracing (based on `prom-client`).

58 lines (57 loc) 4.88 kB
import { ASTNode, DocumentNode, GraphQLError, GraphQLResolveInfo, OperationDefinitionNode, TypeInfo } from 'graphql'; import { Counter, Histogram, Summary, type CounterConfiguration, type HistogramConfiguration, type Registry, type SummaryConfiguration } from 'prom-client'; import { AfterParseEventPayload } from '@envelop/core'; import { PrometheusTracingPluginConfig } from './config.cjs'; export type DeprecatedFieldInfo = { fieldName: string; typeName: string; }; export type FillLabelsFnParams = { document?: DocumentNode; operationName?: string; operationType?: OperationDefinitionNode['operation']; info?: GraphQLResolveInfo; errorPhase?: string; error?: GraphQLError; deprecationInfo?: DeprecatedFieldInfo; }; export declare function shouldTraceFieldResolver(info: GraphQLResolveInfo, whitelist: string[] | undefined): boolean; export declare function createFillLabelFnParams(parseResult: AfterParseEventPayload<any>['result'], context: any, filterParams: (params: FillLabelsFnParams) => FillLabelsFnParams | null): FillLabelsFnParams | null; export type FillLabelsFn<LabelNames extends string, Params extends Record<string, any>> = (params: Params, rawContext: any) => Record<LabelNames, string | number>; export type HistogramAndLabels<LabelNames extends string, Params extends Record<string, any>> = { histogram: Histogram<LabelNames>; fillLabelsFn: FillLabelsFn<LabelNames, Params>; }; export declare function registerHistogram<LabelNames extends string>(registry: Registry, conf: Omit<HistogramConfiguration<LabelNames>, 'registers'>): Histogram<LabelNames>; export declare function createHistogram<LabelNames extends string, Params extends Record<string, any> = FillLabelsFnParams>(options: { registry: Registry; histogram: Omit<HistogramConfiguration<LabelNames>, 'registers'>; fillLabelsFn: FillLabelsFn<LabelNames, Params>; }): HistogramAndLabels<LabelNames, Params>; export type SummaryAndLabels<LabelNames extends string, Params extends Record<string, any>> = { summary: Summary<LabelNames>; fillLabelsFn: FillLabelsFn<LabelNames, Params>; }; export declare function registerSummary<LabelNames extends string>(registry: Registry, conf: Omit<SummaryConfiguration<LabelNames>, 'registers'>): Summary<LabelNames>; export declare function createSummary<LabelNames extends string, Params extends Record<string, any> = FillLabelsFnParams>(options: { registry: Registry; summary: Omit<SummaryConfiguration<LabelNames>, 'registers'>; fillLabelsFn: FillLabelsFn<LabelNames, Params>; }): SummaryAndLabels<LabelNames, Params>; export type CounterAndLabels<LabelNames extends string, Params extends Record<string, any>> = { counter: Counter<LabelNames>; fillLabelsFn: FillLabelsFn<LabelNames, Params>; }; export declare function registerCounter<LabelNames extends string>(registry: Registry, conf: Omit<CounterConfiguration<LabelNames>, 'registers'>): Counter<LabelNames>; export declare function createCounter<LabelNames extends string, Params extends Record<string, any> = FillLabelsFnParams>(options: { registry: Registry; counter: Omit<CounterConfiguration<LabelNames>, 'registers'>; fillLabelsFn: FillLabelsFn<LabelNames, Params>; }): CounterAndLabels<LabelNames, Params>; export declare function getHistogramFromConfig<Params extends Record<string, any> = FillLabelsFnParams>(config: PrometheusTracingPluginConfig, phase: keyof PrometheusTracingPluginConfig['metrics'], histogram: Omit<HistogramConfiguration<string>, 'registers' | 'name'>, fillLabelsFn?: FillLabelsFn<string, Params>): ReturnType<typeof createHistogram<string, Params>> | undefined; export declare function getSummaryFromConfig<Params extends Record<string, any> = FillLabelsFnParams>(config: PrometheusTracingPluginConfig, phase: keyof PrometheusTracingPluginConfig['metrics'], summary: Omit<SummaryConfiguration<string>, 'registers' | 'name'>, fillLabelsFn?: FillLabelsFn<string, Params>): ReturnType<typeof createSummary<string, Params>> | undefined; export declare function getCounterFromConfig<Params extends Record<string, any> = FillLabelsFnParams>(config: PrometheusTracingPluginConfig, phase: keyof PrometheusTracingPluginConfig['metrics'], counter: Omit<CounterConfiguration<string>, 'registers' | 'name'>, fillLabelsFn?: FillLabelsFn<string, Params>): ReturnType<typeof createCounter<string, Params>> | undefined; export declare function extractDeprecatedFields(node: ASTNode, typeInfo: TypeInfo): DeprecatedFieldInfo[]; export declare function labelExists(config: PrometheusTracingPluginConfig, label: string): any; export declare function filterFillParamsFnParams<T extends string>(config: PrometheusTracingPluginConfig, params: Partial<Record<T, any>>): Record<T, any>; export declare function instrumentRegistry(registry: Registry): Registry<"text/plain; version=0.0.4; charset=utf-8">;