2.3.24 • Published 4 years ago

graphql-middleware-jaeger v2.3.24

Weekly downloads
288
License
MIT
Repository
github
Last release
4 years ago

graphql-middleware-jaeger

CircleCI

The easiest way to add tracing support to your GraphQL service

Based on the OpenCensus project, this minimal library provides an easy solution to add basic tracing to your services. Recorded traces are exported to a supplied Jaeger instance automatically.

getting started

First of all, install this middleware from your package registry by running the following:

yarn add graphql-middleware-jaeger

# or using npm
npm i graphql-middleware-jaeger

After this is done, you can simply add the middleware to your existing service, it could look like the following snippet

import { graphqlJaegerMiddleware } from 'graphql-middleware-jaeger';
import { makeExecutableSchema } from 'graphql-tools';
import { applyMiddleware } from 'graphql-middleware';
import { gql, ApolloServer } from 'apollo-server';
import { Request, Response } from 'express';

...

const tracingMiddleware = graphqlJaegerMiddleware<IContext>(
  { logLevel: 3, samplingRate: 1 },
  { host: 'tracing', serviceName: 'example-service' },
  { rootSpanOptions: { name: 'graphqlRequest' } },
  {
    preResolve: [
      ({ context, rootSpan }) => {
        const { req } = context;
        rootSpan.addAttribute('ip', req.ip);
      }
    ]
  }
);

const withTracing = {
  Query: tracingMiddleware,
  Mutation: tracingMiddleware
};

const schema = applyMiddleware(
  makeExecutableSchema({ typeDefs, resolvers }),
  withTracing
);

configuration

The core principle of this package is to stay as unopinionated as possible towards the actual usage, which is why you can configure every aspect, except the run-time behaviour of resolving the middleware.

options

You can configure the OpenCensus tracer, as well as the Jaeger exporter. For more details, head over to the OpenCensus Node.js repository.

hooks

Since there's contextual data that you might want to add to your span, this middleware allows you to define a number of hooks triggered at specific execution points. An example of the usage of hooks is included in the example code above.

Available hooks are: preResolve, postResolve, resolveError

more resources

2.3.24

4 years ago

2.3.23

4 years ago

2.3.22

4 years ago

2.3.20

4 years ago

2.3.21

4 years ago

2.3.19

4 years ago

2.3.18

4 years ago

2.3.17

4 years ago

2.3.16

4 years ago

2.3.15

5 years ago

2.3.14

5 years ago

2.3.13

5 years ago

2.3.12

5 years ago

2.3.11

5 years ago

2.3.10

5 years ago

2.3.9

5 years ago

2.3.8

5 years ago

2.3.7

5 years ago

2.3.6

5 years ago

2.3.5

5 years ago

2.3.4

5 years ago

2.3.3

5 years ago

2.3.2

5 years ago

2.3.1

5 years ago

2.3.0

5 years ago

1.0.0

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago