npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mercurius-apollo-tracing

v2.0.0

Published

Fastify plugin to be used with [Mercurius](https://mercurius.dev) to collect performance metrics from your Graphql resolvers and send them to apollo studio.

Downloads

727

Readme

mercurius-apollo-tracing

Fastify plugin to be used with Mercurius to collect performance metrics from your Graphql resolvers and send them to apollo studio.

Install

npm i mercurius-apollo-tracing

Usage

plugin can be registered like this:

const fastify = require('fastify')
const mercuriusTracing = require('mercurius-apollo-tracing')
const app = fastify()

// you need this if you want to be able to add the server to apollo studio
// they ping your server directly from the browser
app.register(require('fastify-cors'))

app.register(mercurius, {
  schema,
  resolvers,
  graphiql: true
}) // must be done before registering mercuriusTracing

app.register(mercuriusTracing, {
  apiKey: 'your:Api:Key', // replace 'your:Api:Key' with the one from apollo studio
  graphRef: 'yourGraph@ref' // replace 'yourGraph@ref'' with the one from apollo studio
})

API

Manual flush

You can flush traces manually at any time by :

app.apolloTracingStore.flushTracing()

Options

  • endpointUrl?: string
  • graphRef: string
  • apiKey: string
  • sendReportsImmediately?: boolean default: false
    • useful for lambda-like environment where the whole process exits right after serving the GQL request
  • reportIntervalMs?: number default: 10000
  • maxUncompressedReportSize?: number default: 4194304 maximum size of the payload in bytes
    • apollo studio ingress endpoint might not be able to handle bigger payloads, so we recommend tweaking this option carefully
  • checkReportSizeRequestCountInterval?: number default: 100
    • defines how often the size of the metrics payload is checked in number of GQL requests. Lower value means more frequent byte size checks are performed on the traces awaiting to be sent.

Lambda

If you are running in lambda-like environment, keep in mind to pass sendReportsImmediately: true flag to registration options to make sure the report is send before process exits.

Performance

Plugin hooks into each resolver in your schema, so performance will be negatively affected. Performance will be impacted more if you have many fast/small resolvers. If you have less resolvers and it takes more time to resolve them, perf difference is lower. We've measured it in the benchmark here and observed slow down of roughly 25 percent. This is still smaller penalty than compared to running with tracing on apollo-server-fastify. Also in real world API where resolvers actually do something the difference will be much smaller though. These were actual results:

| server | Without tracing(Requests/s) | With tracing enabled(Requests/s) | | --------------------------------- | --------------------------- | -------------------------------- | | apollo-server-fastify+graphql-jit | 4162.8 | 1478.4 | | mercurius | 9162 | 6866 |

Ran on Ubuntu 21.04, Node 16.7.0 and AMD Ryzen 5900x.

Persisted queries

Yes this plugin works fine with them.

Batched queries

Yes, this plugin supports batched queries.