All Projects → DanielMSchmidt → Apollo Opentracing

DanielMSchmidt / Apollo Opentracing

Licence: mit
Performance trace your Apollo GraphQL server with Opentracing

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Apollo Opentracing

Apollo2 Subscriptions How To
Apollo Server 2 how to setup subscriptions
Stars: ✭ 125 (-18.83%)
Mutual labels:  graphql, apollographql, apollo-server
zipkin-javascript-opentracing
Opentracing implementation for Zipkin in Javascript
Stars: ✭ 19 (-87.66%)
Mutual labels:  opentracing, performance-monitoring, zipkin
Api
🚀 GraphQL & REST APIs to explore all the rockets, launches & other SpaceX's data
Stars: ✭ 123 (-20.13%)
Mutual labels:  graphql, apollo-server
Loki
Loki: Simple, Distributed Tracing
Stars: ✭ 127 (-17.53%)
Mutual labels:  zipkin, opentracing
Graphql Kafka Subscriptions
Apollo graphql subscriptions over Kafka protocol
Stars: ✭ 154 (+0%)
Mutual labels:  graphql, apollographql
Sapper Firebase Typescript Graphql Tailwindcss Actions Template
A template that includes Sapper for Svelte, Firebase functions and hosting, TypeScript and TypeGraphQL, Tailwind CSS, ESLint, and automatic building and deployment with GitHub Actions
Stars: ✭ 111 (-27.92%)
Mutual labels:  graphql, apollo-server
Graphql Codegen Hasura
code-generator plugins for hasura/apollo-gql/typescript development
Stars: ✭ 113 (-26.62%)
Mutual labels:  graphql, apollographql
Awesome Apollo Graphql
A curated list of amazingly awesome things regarding Apollo GraphQL ecosystem 🌟
Stars: ✭ 126 (-18.18%)
Mutual labels:  graphql, apollo-server
Fullstack Apollo React Boilerplate
💥A sophisticated Apollo in React boilerplate project.
Stars: ✭ 136 (-11.69%)
Mutual labels:  apollographql, apollo-server
Fakerql
Hosted faker GraphQL endpoint for frontend developers
Stars: ✭ 152 (-1.3%)
Mutual labels:  graphql, apollo-server
Micro Medium Api
Microservice for fetching the latest posts of Medium with GraphQL.
Stars: ✭ 138 (-10.39%)
Mutual labels:  graphql, apollo-server
React Fullstack Graphql
Starter projects for fullstack applications based on React & GraphQL.
Stars: ✭ 1,352 (+777.92%)
Mutual labels:  graphql, apollographql
Otter
Support for OpenTracing in Erlang
Stars: ✭ 96 (-37.66%)
Mutual labels:  zipkin, opentracing
React Graphql Github Apollo
🚀 A React + Apollo + GraphQL GitHub Client. Your opportunity to learn about these technologies in a real world application.
Stars: ✭ 1,563 (+914.94%)
Mutual labels:  graphql, apollographql
Booben
Web app constructor based on React, with GraphQL bindings
Stars: ✭ 96 (-37.66%)
Mutual labels:  graphql, apollographql
Graphql Log
Add logging to your GraphQL resolvers so you know what's going on in your app.
Stars: ✭ 94 (-38.96%)
Mutual labels:  graphql, apollographql
Nest User Auth
A starter build for a back end which implements managing users with MongoDB, Mongoose, NestJS, Passport-JWT, and GraphQL.
Stars: ✭ 145 (-5.84%)
Mutual labels:  graphql, apollo-server
Sapper Typescript Graphql Template
A template that includes Sapper for Svelte, TypeScript preprocessing, and a GraphQL server through TypeGraphQL
Stars: ✭ 84 (-45.45%)
Mutual labels:  graphql, apollo-server
Angular Fullstack Graphql
🚀 Starter projects for fullstack applications based on Angular & GraphQL.
Stars: ✭ 92 (-40.26%)
Mutual labels:  graphql, apollographql
Apollo Federation Ruby
A Ruby implementation of Apollo Federation
Stars: ✭ 131 (-14.94%)
Mutual labels:  graphql, apollographql

Apollo Opentracing npm version Build Status semantic-release All Contributors

Apollo Opentracing allows you to integrate open source baked performance tracing to your Apollo server based on industry standards for tracing.

  • 🚀 Request & Field level resolvers are traced out of the box
  • 🔍 Queries and results are logged, to make debugging easier
  • ⚙️ Select which requests you want to trace
  • 🔗 Spans transmitted through the HTTP Headers are picked up
  • 🔧 Use the opentracing compatible tracer you like, e.g.
  • 🦖 Support from node 6 on

Installation

Run npm install --save apollo-opentracing given that you already setup an opentracing tracer accordingly.

Setup

We need two types of tracer (which could be identical if you like):

  • server: Only used for the root (the first span we will start)
  • local: Used to start every other span
const { graphqlExpress } = require("apollo-server-express");
const {serverTracer, localTracer} = require("./tracer");
+const OpentracingPlugin = require("apollo-opentracing").default;

app.use(
  "/graphql",
  bodyParser.json(),
  graphqlExpress({
    schema,
+   plugins: [OpentracingPlugin({
+     server: serverTracer,
+     local: localTracer,
+   })]
  })
)

Connecting Services

example image

To connect other services you need to use the opentracing inject function of your tracer. We pass the current span down to your resolvers as info.span, so you should use it.

You can also make use of it and add new logs or tags on the fly if you like. This may look something like this:

myFieldResolver(source, args, context, info) {
  const headers = {...};

  const parentSpan = info.span;
  // please use the same tracer you passed down to the extension
  const networkSpan = tracer.startSpan("NetworkRequest:" + endpoint, {
    childOf: parentSpan
  });

  // Let's transfer the span information to the headers
  tracer.inject(
    networkSpan,
    YourOpentracingImplementation.FORMAT_HTTP_HEADERS,
    headers
  );

  return doNetworkRequest(endpoint, headers).then(result => {
    networkSpan.finish()
    return result;
  }, err => {
    networkSpan.log({
      error: true,
      errorMessage: err
    });

    networkSpan.finish();
    return err;
  });
}

Selective Tracing

Sometimes you don't want to trace everything, so we provide ways to select if you want to start a span right now or not.

By Request

If you construct the extension with shouldTraceRequest you get the option to opt-in or out on a request basis. When you don't start the span for the request the field resolvers will also not be used.

The function is called with the same arguments as the requestDidStart function extensions can provide, which is documented here.

When the request is not traced there will also be no traces of the field resolvers.

By Field

There might be certain field resolvers that are not worth the tracing, e.g. when they get a value out of an object and need no further tracing. To control if you want a field resolver to be traced you can pass the shouldTraceFieldResolver option to the constructor. The function is called with the same arguments as your field resolver and you can get the name of the field by info.fieldName. When you return false no traces will be made of this field resolvers and all underlying ones.

Modifying span metadata

If you'd like to add custom tags or logs to span you can construct the extension with onRequestResolve. The function is called with two arguments: span and infos onRequestResolve?: (span: Span, info: RequestStart)

Using your own request span

If you need to take control of initializing the request span (e.g because you need to use it during context initialization) you can do so by having creating it as context.requestSpan.

Options

  • server: Opentracing Tracer for the incoming request
  • local: Opentracing Tracer for the local and outgoing requests
  • onFieldResolve(source: any, args: { [argName: string]: any }, context: SpanContext, info: GraphQLResolveInfo): Allow users to add extra information to the span
  • onFieldResolveFinish(error: Error | null, result: any, span: Span): Callback after a field was resolved
  • shouldTraceRequest & shouldTraceFieldResolver: See Selective Tracing
  • onRequestResolve(span: Span, info: GraphQLRequestContext): Add extra information to the request span
  • createCustomSpanName(name: String, info: GraphQLResolveInfo): Allow users to provide customized span name

Contributing

Please feel free to add issues with new ideas, bugs and anything that might come up. Let's make performance measurement to everyone <3

Contributors

Thanks goes to these wonderful people (emoji key):


Daniel Schmidt

💻 🤔

Ciaran Liedeman

🐛 💻 ⚠️

Jens Ulrich Hjuler Pedersen

🐛 🤔 👀

Francesca

💻

Ricardo Casares

💻

Michał Wieczorek

💻

Koen Punt

💻

Zeke Nierenberg

💻

Tomáš Voslař

💻

Ben Kimball

💻

Jiapei Liang

💻

Richard W

🤔 🔬

This project follows the all-contributors specification. Contributions of any kind welcome!

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].