Skip to content

Export Apollo server request information to Prometheus through prom-client

License

Notifications You must be signed in to change notification settings

dotellie/apollo-metrics

Repository files navigation

Apollo Server Metrics

Build Status npm

Export Apollo server request information to Prometheus through prom-client.

Usage

import { ApolloServer } from "apollo-server-express";
import express from "express";
import { register } from "prom-client";
import createMetricsPlugin from "apollo-metrics";

async function start(): Promise<void> {
  try {
    const app = express();

    app.get("/metrics", (_, res) => res.send(register.metrics()));
    const apolloMetricsPlugin = createMetricsPlugin(register);

    const server = new ApolloServer({
      plugins: [apolloMetricsPlugin],
      // IMPORTANT: tracing needs to be enabled to get resolver and request timings!
      tracing: true
    });
    server.applyMiddleware({ app, path: "/" });

    app.listen(5000, () => console.log(`🚀 Service started`));
  } catch (error) {
    console.error("Failed to start!", error);
  }
}

start();

License

MIT

About

Export Apollo server request information to Prometheus through prom-client

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •