Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

apollo-link-tracer

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-link-tracer

Trace your apollo queries and mutations

  • 1.0.26
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7
increased by133.33%
Maintainers
1
Weekly downloads
 
Created
Source

Trace your apollo queries and mutations with apollo-link.

Relies on @convoy/tracer.

Getting started

npm install apollo-link-tracer --save
import ApolloLinkTracer from 'apollo-link-tracer';
import { Reporter } from '@convoy/tracer';

const apiReporter = new Reporter({
  flushHandler: async (timings, traces) => {
    // Report traces to API
  },
});

new ApolloClient({
  link: ApolloLink.from([
    new ApolloLinkTracer({
      service: 'my-service',
      tracerConfig: {
        reporter: apiReporter,
        fullTraceSampleRate: 1,
      },
      name: 'apollo-link',
    }),

    new ApolloLink((operation, forward) => {
      const { tracer } = operation.getContext().tracer;
      const requestId = tracer.getTraceId();

      operation.setContext({
        headers: {
          'x-req-id': requestId,
        },
      });

      return forward(operation);
    }),

    new RetryLink(retryOptions),

    new ApolloLinkTracer({
      service: 'my-service',
      tracerConfig: {
        reporter: apiReporter,
        fullTraceSampleRate: 1,
      },
      name: 'apollo-link-retry',
    }),

    new HttpLink({ uri, fetch }),
  ]),
});

Applying apollo-link-tracer both before and after the retry link lets you separately measure each retry, but provides a single trace across all of them.

A Tracer object is added to the operation context, which can then be used to pass a trace id to the HTTP headers to support cross service tracing.

Advanced options

On a per GQL request basis you can alter how the trace is captured.

api.mutate({
  mutation,
  variables,
  context: {
    tracerConfig: {
      fullTraceSampleRate: 1 / 20,
    },
    traceService: 'my-service',
    traceName: 'apollo-link-mutate',
    traceResource: 'getSomething',
    avoidTrace: false, // If true, skips tracing
  },
});
Filtering Sensitive Variables

To avoid reporting the contents of sensitive variables, you can specify variable filters.

new ApolloLinkTracer({
  service: 'my-service',
  tracerConfig: {
    reporter: apiReporter,
    fullTraceSampleRate: 1,
  },
  name: 'apollo-link-retry',
  variableFilters: ['password', /secret.*sauce/],
}),

Variable filters can be either string matches or regular expressions. Any variables whose names match these filters will have their values filtered out, e.g.

{ username: 'bob', password: 'hunter2', secret_hot_sauce: 'sri racha'}

becomes

{ username: 'bob', password: '<filtered>', secret_hot_sauce: '<filtered>'}

FAQs

Package last updated on 31 Oct 2018

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc