GraphQL Envelop Metrics Plugin

The Stellate Envelop Metrics Plugin enables the integration of Stellate with The Guild's GraphQL Envelop, a lightweight JavaScript library for customizing the GraphQL execution layer. Our Envelop Metrics Plugin facilitates metrics logging, establishing a seamless connection with the Stellate service for performance analysis and insights.

Envelop provides a low-level hook-based plugin API for developers. By combining plugins, you can compose your own GraphQL framework. For more information about the Stellate Edge proxy metrics, read Stellate Edge Proxy Metrics.

Benefits of the Envelop Metrics Plugin

The Stellate Envelop Metrics Plugin lets yo collect metrics without setting up the Stellate Edge proxy. For more information, read Stellate Edge proxy. In addition, the Metrics Plugin features:

  • Simple setup and integration, with just a few lines of code.
  • Ability to log metrics, which are useful for monitoring and analyzing API usage.
  • The envelop plugin, as do all of the plugins for JavaScript-based servers, takes a fetch function as an argument. This enables using the plugin in any JavaScript environment. If you are running NodeJS you can use the node-fetch package, and in an edge environment (such as Cloudflare Workers) you can pass the global fetch function.

Before you Begin

Before you install and use the Stellate Envelop Metrics Plugin, you need to install and set up Envelop. For information, read the Guild GraphQL Envelop First Steps. Additionally, you need to:

  • Set Up a Stellate Service: You must have an active Stellate service set up. Our GraphQL Envelop Metrics Plugin is designed to work with your Stellate service.

  • Create a Logging Token: To implement this plugin, you need to create a logging token specific to your Stellate service. You can get your logging token by going to your Stellate Dashboard > Services > Your Service > Config > Token. This token is used to authenticate and log metrics data from your GraphQL API to your Stellate dashboard.

Install the Envelop Metrics Plugin

To install and use our metrics plugin for GraphQL Envelop:

  1. Have a Stellate service and create a logging token. See the prior Before You Begin section, for more information.
  2. Copy and paste the following JavaScript plugin code to your server:
import { createStellateLoggerPlugin } from 'stellate/envelop'
import { envelop } from '@envelop/core'

export const getEnveloped = envelop({
  plugins: [
    // ... other plugins
      serviceName: '${serviceName}',
      token: '${loggingToken}',
      // a fetch compliant function, can be from `node-fetch` if you are running in NodeJS,
      // or the global fetch function if running in a v8 environment (e.g. Cloudflare Workers)
      fetch: fetch,

server.on('req', async (req, res) => {
  // The request entry is important here so the stellage plugin has the request context
  getEnveloped({ request: req })
  1. Start the server to begin handling requests.
  2. Refresh your dashboard to show the incoming requests and metrics, highlighting the plugin's capability to track Envelop GraphQL API usage.

Discover more

JavaScript Server Plugins

Other Language Plugins