Skip to content

Package for collecting metrics and sending them to a statsd service

License

Notifications You must be signed in to change notification settings

motnok/graphql-statsd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

graphql-statsd

Package for collecting metrics from an expressjs/express / apollographql/graphql-server based GraphQL server, and sending those to a statsd service.

npm install graphql-statsd

Currently it collects timings and counts for the entire requests as well as the individual resolvers in the query.

Usage

Install using NPM and include in your project together with a statsd client. In this sample we use brightcove/hot-shots - but any client implementing increment and timing methods should work.

import graphqlStatsd from 'graphql-statsd';
import statsD from 'hot-shots';

Instantiate the graphql-statsd module with the statsd client:

const graphqlStatsdModule = new graphqlStatsd(new statsD());

Decorate your GraphQL schema using the

const schema = graphqlStatsdModule.decorateSchema(importedSchema);

Add the express middleware and define the graphqlStatsdContext context from the express request property. The graphqlStatsdContext is used to inject data from the request (operation name, query hash etc.) into the resolver metrics for traceability:

graphQLApp.post(['/', '/graphql'], bodyParser.json(), graphqlStatsdModule.getExpressMiddleware(), graphqlExpress(request => ({
  schema: schema,
  context: {
    graphqlStatsdContext: request.graphqlStatsdContext
  }
})));

You should now be good to go!

Tests

Currently no tests are implemented

Thanks

About

Package for collecting metrics and sending them to a statsd service

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published