apollo-metrics
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i apollo-metrics

Weekly Downloads

2,224

Version

1.0.1

License

MIT

Unpacked Size

14.9 kB

Total Files

7

Last publish

Collaborators

  • dotellie