AppSignal Now Automatically Instruments Apollo for Node.js Applications

Adam Adam Yeats, Milica Maksimović on

We’re happy to announce a new version of AppSignal for Node.js, and support for instrumenting Apollo Server v2+. This means that we’ll save you more some time, and perform more automatic instrumentation for you.

What Automated Instrumentation Means

In order to understand which pieces of your code are causing performance problems, you’ll need to add instrumentation to it. That way, you can break down all the actions and measure which ones are the slowest.

With AppSignal’s automatic instrumentation, you don’t need to do any manual work. Our agent detects parts of your infrastructure and automatically instruments it. We strive to provide you with as much out-of-the box functionality as possible, and spare you from doing any tedious manual tasks.

Since we use AppSignal to monitor AppSignal, we know exactly how it feels to be an AppSignal user, and which things usually get in our way. Customizing is amazing when you’re an advanced user, but we also strive to amaze anyone who gives us a shot with a lot of out-of-the-box support.

What’s in This Integration?

The new integration for Apollo Server comes in the form of an Apollo Server plugin, that requires a little setup to get going. Here’s how to get started:

Installation

First, [sign up for an AppSignal account][appsignal-sign-up] and add both the @appsignal/nodejs and @appsignal/apollo-server packages to your package.json. Then, run yarn install/npm install.

You can also add these packages to your package.json on the command line:

1
2
yarn add @appsignal/nodejs @appsignal/apollo-server
npm install --save @appsignal/nodejs @appsignal/apollo-server

You can then import and use the package in your app.

Usage

The module includes an Apollo Server plugin for automatically instrumenting the resolvers of your application.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// ENSURE APPSIGNAL IS THE FIRST THING TO BE REQUIRED/IMPORTED
// INTO YOUR APP!
const { Appsignal } = require("@appsignal/nodejs");
const { createApolloPlugin } = require("@appsignal/apollo-server");

// You can also use one of the apollo-server integrations here,
// e.g. `apollo-server-<integration>`. Note that you will also need to require
// the AppSignal integration seperately.
const { ApolloServer } = require("apollo-server");

const appsignal = new Appsignal({
  active: true,
  name: "<YOUR APPLICATION NAME>",
  apiKey: "<YOUR API KEY>",
});

// The GraphQL schema
const typeDefs = gql`
  type Query {
    "A simple type for getting started!"
    hello: String
  }
`;

// A map of functions which return data for the schema.
const resolvers = {
  Query: {
    hello: () => "world",
  },
};

const server = new ApolloServer({
  typeDefs,
  resolvers,
  plugins: [createApolloPlugin(appsignal)],
});

server.listen().then(({ url }) => {
  console.log(`🚀 Server ready at ${url}`);
});

NOTE: You must define an operation name for your query to get an action name in the Performance view of AppSignal.com. For example, query FetchData {} would get the action name FetchData on AppSignal.com. If no operation name is set, the query will be grouped under the action name [unknown graphql query].

Ok, then what happens?

Once updated, you’ll see your resolvers appear in the Event Timeline. You’ll be able to see a breakdown of the time it took to parse, validate and execute your resolver:

Screenshot of event timeline

You’ll also be able to see the name and body of the operation when you hover over the resolvers execution phase:

Screenshot of event timeline flyout

This is great for those who wish to debug GraphQL queries that seem to take a long time, and you’re not sure where the slowdown could be occurring. Don’t forget about our anomaly triggers here also - these can be very useful for alerting when the query time reaches a certain threshold.

Try Out AppSignal and Get a Box of Stroopwafels 🍪

Hope we made you interested in getting more information about the performance of your app now! You can find more details about our support for Node.js here.

FYI, AppSignal is free for open source apps! For commercial apps, we suggest to hop on a trial, start pushing some data, and send us a message that you want some stroopwafels. We’re shipping 🍪 worldwide 🌍

10 latest articles

Go back
Ruby magic icon

Subscribe to

Ruby Magic

Magicians never share their secrets. But we do. Sign up for our Ruby Magic email series and receive deep insights about garbage collection, memory allocation, concurrency and much more.

We'd like to set cookies, read why.