
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
graphql-dog
Advanced tools
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:
npm install ??? --saveimport GraphQLDog from 'graphql-dog';DATADOG_API_KEY environment variable to your API keydatadogOpts field in GraphQLDog.configureAgent({ options });GraphQLDog.instrumentSchema(executableSchema);expressServer.use(GraphQLDog.middleware());context.datadogContext = GraphQLDog.context(req);First, install the package
npm install ?? --save
Next, set up the agent in your main server file.
var GraphQLDog = require('graphql-dog');
or in ES2015+
import GraphQLDog from 'graphql-dog';
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.
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).
Set up middleware:
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.
Unlike Express (above) this has not been tested in this fork from optics-agent.
GraphQLDog.instrumentHapiServer(hapiServer);
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,
};
})
);
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) }
(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);
The agent is designed to allow your application to continue working, even if the agent is not configured properly.
FAQs
graphQL-js agent for Datadog (forked from Apollo Optics agent)
The npm package graphql-dog receives a total of 2 weekly downloads. As such, graphql-dog popularity was classified as not popular.
We found that graphql-dog demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.