@arquivei/apollo-prometheus
v1.2.0
Published
Export Apollo server request information to Prometheus through prom-client
Downloads
276
Maintainers
Readme
@arquivei/apollo-prometheus
The @arquivei/apollo-prometheus package aims to provide a tool so that we can follow the GraphQL processing using Prometheus.
Usage
Check below step by step to use this package:
:one: Install package in dependencies
❯ yarn add -D @arquivei/apollo-prometheus prom-client @sentry/node
:two: Add the plugin in Apollo Server settings
In order to obtain all metrics in an easy way, it is recommended to add a prefix to the metrics of this plugin, due to the way we organize our BFFs, we recommend that the Apollo Server settings be a function where we can receive parameters through it, being something like the following example
import ApolloPrometheus from '@arquivei/apollo-prometheus';
[...]
interface GraphQLServerOptions {
prometheusPrefix?: string;
sentryEnabled?: boolean;
sentryDsn?: string;
}
export function createGraphQLServerOptions(options: GraphQLServerOptions): Config {
return {
plugins: [
ApolloPrometheus({
prefix: options.prometheusPrefix,
sentry: {
enabled: options.sentryEnabled,
dsn: options.sentryDsn,
},
}),
],
};
}
export default createGraphQLServerOptions;
:three: Adjust the file that takes care of the server startup so that it is possible to return the Apollo Server settings with the proper prefix filled in the metrics
import { createGraphQLServerOptions } from './config';
(async () => {
const IS_PRODUCTION = process.env.NODE_ENV === 'production';
const PROMETHEUS_PREFIX = process.env.PROMETHEUS_PREFIX;
const SENTRY_DSN = process.env.SENTRY_DSN;
[...]
const options = createGraphQLServerOptions({
prometheusPrefix: PROMETHEUS_PREFIX,
sentryEnabled: IS_PRODUCTION,
sentryDsn: SENTRY_DSN,
});
const server = new ApolloServer(options);
[...]
})()