Socket
Book a DemoInstallSign in
Socket

graphql-middleware-jaeger

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-middleware-jaeger

GraphQL Jaeger tracing middleware based on OpenCensus

2.3.24
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

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

FAQs

Package last updated on 05 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.