npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

graphql-dog

v0.1.0

Published

graphQL-js agent for Datadog (forked from Apollo Optics agent)

Readme

graphql-dog

A tracking agent for apollo GraphQL servers, for logging to Datadog. Forked from Apollo Optics agent, and uses datadog-metrics.

Unlike the original, this fork simply tracks request_times (in ms), with datadog tags specifying the graphql type, field and 'type.field'. There is no special error logging, or tracking of number of which fields are used etc.

THIS IS NOT HEAVILY TESTED YET

Here are the steps to enable Graphql-dog in your app. See below for details on each step:

  • Install the NPM package in your app: npm install ??? --save
  • Import the package in your main js file: import GraphQLDog from 'graphql-dog';
  • Get an API key from the Optics web interface and configure the agent. Either:
    • Set the DATADOG_API_KEY environment variable to your API key
    • Set the datadog options using the datadogOpts field in GraphQLDog.configureAgent({ options });
  • Instrument your app. In any order:
    • Instrument your schema: GraphQLDog.instrumentSchema(executableSchema);
    • Add the middleware: expressServer.use(GraphQLDog.middleware());
    • Add to your GraphQL context object: context.datadogContext = GraphQLDog.context(req);

Version requirements

Install

First, install the package

npm install ?? --save

Configure

Next, set up the agent in your main server file.

Import the package

var GraphQLDog = require('graphql-dog');

or in ES2015+

import GraphQLDog from 'graphql-dog';

[optional] Configure the Agent

GraphQLDog.configureAgent({ configOptions })

Normally you do not need to call this function -- just set the DATADOG_API_KEY environment variable. Call this function if you set the API key in code instead of through the environment variable, or if you need to set specific non-default values for other options. Call this before any calls to instrumentation functions below.

Options include:

  • apiKey: String. Your API key for the Datadog service. This defaults to the DATADOG_API_KEY environment variable, but can be overridden here.

  • normalizeQuery: Function(GraphQLResolveInfo)⇒String. Called to determine the query shape for for a GraphQL query. You shouldn't need to set this unless you are debugging.

  • reportIntervalMs: Number. How often to send reports in milliseconds. ..see datadog-metrics package for details.

Instrument your schema

Call instrumentSchema on the same executable schema object you pass to the graphql function from graphql-js:

GraphQLDog.instrumentSchema(executableSchema);

You should only call this once per agent. If you have multiple or dynamic schemas, create a separate agent per schema (see below).

Add the middleware

Set up middleware:

Express

Tell your server to run the Optics Agent middleware:

expressServer.use(GraphQLDog.middleware());

This must run before the handler that actually executes your GraphQL queries. For the most accurate timings, avoid inserting unnecessary middleware between the Optics Agent middleware and your GraphQL middleware.

HAPI

Unlike Express (above) this has not been tested in this fork from optics-agent.

GraphQLDog.instrumentHapiServer(hapiServer);

Koa

Unlike Express (above) this has not been tested in this fork of optics-agent - and indeed the original already carried a warning that Koa is not officially supported.

const schema = OpticsAgent.instrumentSchema(executableSchema);
app.use(OpticsAgent.koaMiddleware());
router.post(
  '/graphql',
  graphqlKoa(async ctx => {
    // create an optic context
    const datadogContext = GraphQLDog.context(ctx.request);
    // create a context for each request
    const context = { datadogContext };
    return {
      schema,
      context,
    };
  })
);

Add a context to each graphql request

Inside your request handler, if you are calling graphql directly, add a new field to the context object sent to graphql:

{ datadogContext: GraphQLDog.context(req) }

If you are using apolloExpress, this will be a field on the context object on the ApolloOptions value that you return.

If you are using HAPI you must explicitly use the raw request object:

{ datadogContext: GraphQLDog.context(request.raw.req) }

Advanced Usage

(Not tested in this fork.) If you need to have more than one Agent per process, you can manually construct an Agent object instead of using the default global Agent. Call new GraphQLDog.Agent(options) to instantiate the object, and then call methods directly on the object instead of on GraphQLDog. Here is an example:

var GraphQLDog = require('graphql-dog');
var agent = new GraphQLDog.Agent({ apiKey: '1234' });
agent.instrumentSchema(schema);

Troubleshooting

The agent is designed to allow your application to continue working, even if the agent is not configured properly.