appsignal

AppSignal Now Automatically Instruments Apollo for Node.js Applications

Adam Yeats
Milica Maksimović

Adam Yeats and Milica Maksimović on

AppSignal Now Automatically Instruments Apollo for Node.js Applications

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:

Shell
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.

JavaScript
// 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 🌍

Become our next author!

Find out more

AppSignal monitors your apps

AppSignal provides insights for Ruby, Rails, Elixir, Phoenix, Node.js, Express and many other frameworks and libraries. We are located in beautiful Amsterdam. We love stroopwafels. If you do too, let us know. We might send you some!

Discover AppSignal
AppSignal monitors your apps