@envelop/prometheus
This plugin tracks the complete execution flow, and reports metrics using Prometheus tracing (based on prom-client
).
You can opt-in to collect tracing from the following phases:
- errors (categorized by
phase
) - resolvers tracing and runtime
- deprecated fields usage
parse
execution timevalidate
execution timecontextBuilding
execution timeexecute
execution time
You can also customize each phase reporter, and add custom metadata and labels to the metrics.
Getting Started
yarn add prom-client @envelop/prometheus
Usage Example
import { envelop } from '@envelop/core';
import { usePrometheus } from '@envelop/prometheus';
const getEnveloped = envelop({
plugins: [
usePrometheus({
parse: true,
validate: true,
contextBuilding: true,
execute: true,
errors: true,
resolvers: true,
resolversWhitelist: ['Mutation.*', 'Query.user'],
deprecatedFields: true,
registry: myRegistry,
}),
],
});
Custom registry
You can customize the prom-client
Registry
object if you are using a custom one, by passing it along with the configuration object:
import { Registry } from 'prom-client';
const myRegistry = new Registry();
const getEnveloped = envelop({
plugins: [
usePrometheus({
registry: myRegistry,
}),
],
});
Note: if you are using custom prom-client
instances, you need to make sure to pass your registry there as well.
Custom prom-client
instances
Each tracing field supports custom prom-client
objects, and custom labels
a metadata, you can create a custom extraction function for every Histogram
/ Summary
/ Counter
:
import { Histogram } from 'prom-client';
import { envelop } from '@envelop/core';
import { createHistogram, usePrometheus } from '@envelop/prometheus';
const getEnveloped = envelop({
plugins: [
usePrometheus({
parse: createHistogram({
histogram: new Histogram({
name: 'my_custom_name',
help: 'HELP ME',
labelNames: ['opText'] as const,
registers: [registry],
}),
fillLabelsFn: params => {
return {
opText: print(params.document),
};
},
}),
}),
],
});