import type { ASTNode, DocumentNode, GraphQLError, GraphQLResolveInfo, OperationDefinitionNode, TypeInfo } from 'graphql'; import { Counter, Histogram, Summary, type CounterConfiguration, type HistogramConfiguration, type Registry, type SummaryConfiguration } from 'prom-client'; import type { AfterParseEventPayload } from '@envelop/core'; import type { PrometheusTracingPluginConfig } from './config.js'; 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['result'], context: any, filterParams: (params: FillLabelsFnParams) => FillLabelsFnParams | null): FillLabelsFnParams | null; export type FillLabelsFn> = (params: Params, rawContext: any) => Record; export type ShouldObservePredicate> = (params: Params, rawContext: any) => boolean; export type HistogramAndLabels> = { histogram: Histogram; fillLabelsFn: FillLabelsFn; phases?: AtLeastOne; shouldObserve?: ShouldObservePredicate; }; export declare function registerHistogram(registry: Registry, conf: Omit, 'registers'>): Histogram; /** * Histogram metric factory allowing to define custom metrics with advanced configuration. * @param options * @returns */ export declare function createHistogram = FillLabelsFnParams>(options: { /** * The registry to be used by the plugin. If you don't have a custom registry, * use `register` exported variable from `prom-client`. */ registry: Registry; /** * The configuration of the histogram, as expected by the `prom-client` library. */ histogram: Omit, 'registers'>; /** * A function called when an event is observed to extract labels values from the context. */ fillLabelsFn: FillLabelsFn; /** * A list of GraphQL pipeline phases which will be observed by this metric. * * The possible values accepted in this list depends on the metric, * please refer to metric type or documentation to know which phases ar available. * * By default, all available phases are observed */ phases?: AtLeastOne; /** * A function called for each event that can be observed. * If it is provided, an event will be observed only if it returns true. * * By default, all events are observed. */ shouldObserve?: ShouldObservePredicate; }): HistogramAndLabels; export type SummaryAndLabels> = { summary: Summary; fillLabelsFn: FillLabelsFn; phases?: AtLeastOne; shouldObserve?: ShouldObservePredicate; }; export declare function registerSummary(registry: Registry, conf: Omit, 'registers'>): Summary; /** * Summary metric factory allowing to define custom metrics with advanced configuration. * @param options * @returns */ export declare function createSummary = FillLabelsFnParams>(options: { /** * The registry to be used by the plugin. If you don't have a custom registry, * use `register` exported variable from `prom-client`. */ registry: Registry; /** * The configuration of the summary, as expected by the `prom-client` library. */ summary: Omit, 'registers'>; /** * A function called when an event is observed to extract labels values from the context. */ fillLabelsFn: FillLabelsFn; /** * A list of GraphQL pipeline phases which will be observed by this metric. * * The possible values accepted in this list depends on the metric, * please refer to metric type or documentation to know which phases ar available. * * By default, all available phases are observed */ phases?: AtLeastOne; /** * A function called for each event that can be observed. * If it is provided, an event will be observed only if it returns true. * * By default, all events are observed. */ shouldObserve?: ShouldObservePredicate; }): SummaryAndLabels; export type CounterAndLabels> = { counter: Counter; fillLabelsFn: FillLabelsFn; phases?: AtLeastOne; shouldObserve?: ShouldObservePredicate; }; /** * Counter metric factory allowing to define custom metrics with advanced configuration. * @param options * @returns */ export declare function registerCounter(registry: Registry, conf: Omit, 'registers'>): Counter; export declare function createCounter = FillLabelsFnParams>(options: { /** * The registry to be used by the plugin. If you don't have a custom registry, * use `register` exported variable from `prom-client`. */ registry: Registry; /** * The configuration of the counter, as expected by the `prom-client` library. */ counter: Omit, 'registers'>; /** * A function called when an event is observed to extract labels values from the context. */ fillLabelsFn: FillLabelsFn; /** * A list of GraphQL pipeline phases which will be observed by this metric. * * The possible values accepted in this list depends on the metric, * please refer to metric type or documentation to know which phases ar available. * * By default, all available phases are observed */ phases?: AtLeastOne; /** * A function called for each event that can be observed. * If it is provided, an event will be observed only if it returns true. * * By default, all events are observed. */ shouldObserve?: ShouldObservePredicate; }): CounterAndLabels; export declare function getHistogramFromConfig = FillLabelsFnParams>(config: PrometheusTracingPluginConfig, phase: keyof MetricOptions, availablePhases: AtLeastOne, histogram: Omit, 'registers' | 'name'>, fillLabelsFn?: FillLabelsFn): Required> | undefined; export declare function getSummaryFromConfig = FillLabelsFnParams>(config: PrometheusTracingPluginConfig, phase: keyof MetricOptions, availablePhases: AtLeastOne, summary: Omit, 'registers' | 'name'>, fillLabelsFn?: FillLabelsFn): Required> | undefined; export declare function getCounterFromConfig = FillLabelsFnParams>(config: PrometheusTracingPluginConfig, phase: keyof MetricOptions, availablePhases: AtLeastOne, counter: Omit, 'registers' | 'name'>, fillLabelsFn?: FillLabelsFn): Required> | undefined; export declare function extractDeprecatedFields(node: ASTNode, typeInfo: TypeInfo): DeprecatedFieldInfo[]; export declare function labelExists(config: { labels?: Record; }, label: string): boolean; export declare function filterFillParamsFnParams(config: PrometheusTracingPluginConfig, params: Partial>): Record; export declare function instrumentRegistry(registry: Registry): Registry<"text/plain; version=0.0.4; charset=utf-8">; export type AtLeastOne = [T, ...T[]];