Metrics Logging API

You can get analytics and observability metrics through the Stellate dashboard, through our plugins, or through our Metrics Logging API. This Metrics Request Logging API allows you to identify your cacheable traffic using any of the following options:

  • Create requests to the logging API from the Dashboard UI using a convenient fetch call that you can copy and paste into your GraphQL environment.
  • Build your own manual fetch call using the information in this topic.
  • Use any of the convienient Stellate plugins for your server or framework or specific language. Read Metrics Plugins for more information.

The Request Logging API allows you to identify your cacheable traffic using plugins or through the aforementioned manual fetch call.

Before you begin

In addition to using the Metrics Logging API, Stellate also provides an number of convenient plugins to help collect metrics for specific servers or languages. Before you construct your own 'fetch' call or create your own plugin, check out the following resources to see if we have you covered.

We provide plugins for multiple servers and frameworks, such as:

We also provide language specific plugins, such as: Java, Ruby, and Strawberry.

Logging Requests to GraphQL Metrics

You can easily use Stellate GraphQL Metrics without proxying all your requests through Stellate. To achieve that you can push data about your GraphQL requests to our logging endpoint directly from your origin server. Stellate provides two options for collecting GraphQL metrics, a convenient fetch call that you can copy and paste into your GraphQL environment or you can build your own fetch call.

Build a Manual fetch Call for Metrics

An alternate method for getting Stellate GraphQL Metrics is to do a manual request. You can manually construct your own fetch call to use the Stellate API for logging requests to collect and send metrics. To create a manual logging request to get Stellate GraphQL Metrics, you need to do some preliminary set up as described in the following sections.

Obtain a Token to Authorize

To authorize the logging request, you need to send a token with the request using the Stellate-Logging-Token header. You can generate these tokens in the service-settings.

To generate and include the logging-token in the Stellate-Logging-Token header:

  1. Navigate to Stellate > Services and click your service.
  2. Click Config > Tokens > Create a Token > Logging API.
  3. Click Create Token and copy the token to a secure location.
  4. Include this token in your Stellate-Logging-Token header. For example: token: '${loggingToken}',

You then need to specify the endpoint with the properties that you want to be part of your request.

Specify the Endpoint

Send a POST request to https://<service-name>.stellate.sh/log. The following properties can be sent in the request body.

PropertyExpected typeIs requiredDescription
operationstringtrueThe GraphQL query handled by the origin
methodstringtrueThe HTTP method used to send the GraphQL request
responseSizenumbertrueThe length of the stringified response body
responseHashnumbertrueA blake3 hash of the JSON-stringified execution result
elapsednumbertrueThe time (in ms) it took to handle the GraphQL request
operationNamestringfalseThe name of the operation that has been executed
variablesobjectfalseThe variables sent with the GraphQL requests (stored as hash to count distinct variables for the given GraphQL operation)
variablesHashnumberfalseA blake3 hash of the JSON-stringified variables object (takes precendence over the variables property)
ipstringfalseThe IP that send the GraphQL request (will be hashed with SHA-256 before storing it)
errorsobject[]falseThe list of GraphQL errors that are part of the execution result
statusCodenumbertrueThe HTTP status code of the response
statusTextstringfalseThe text sent with the above HTTP status code (by default we use the standardized status texts)
userAgentstringfalseThe value of the user-agent header sent with the HTTP request
refererstringfalseThe value of the referer header sent with the HTTP request
hasSetCookiebooleanfalseThe value of the set-cookie header sent with the HTTP response

Response

For a successful log intake, the above endpoint will respond with a 204 status code. If there was an error, it'll respond with a 400 status code.

How to hash values

When generating an integer hash you can do so with the following function, this is needed for the responseBodyHash

function createIntHash(str) {
  let val = 0
  const strlen = str.length

  if (strlen === 0) {
    return val
  }

  for (let i = 0; i < strlen; ++i) {
    const code = str.charCodeAt(i)
    val = (val << 5) - val + code
    val &= val // Int32
  }
  return val >>> 0 // uInt32
}

Metrics Plugins

All of the Stellate server and framework plugins take a fetch function as an argument, this enables using these plugins in any JavaScript environment. If you are running NodeJS you can use the node-fetch package, and in an edge environment (e.g. Cloudflare Workers) pass the global fetch function.

List of Metrics Plugins

For full documentation on each specific plugin see the Integrations topics on:

Discover more

About GraphQL Metrics

Get Started with GraphQL Metrics

Metrics Plugins

Use the Edge Proxy for GraphQL Metrics