Code Monkey home page Code Monkey logo

graphql-resolvers-xray-tracing's Introduction

GraphQL Middleware to add X-Ray tracing for resolvers

npm Build Status Coverage Status Dependabot Badge

To enable X-Ray subsegment creation for GraphQL resolvers, add this package as a dependency of your project and use code like this:

const traceResolvers = require('@lifeomic/graphql-resolvers-xray-tracing');
const schema = makeExecutableSchema( ... );
traceResolvers(schema);

After enabling X-Ray tracing, you should see new subsegments in your X-Ray traces like this:

Image of X-Ray trace

Local Development

If you would like to run your GraphQL server without tracing the resolvers (such as during local development), you can use environment variables to conditionally wrap them. For example, the AWS Lambda runtime injects the AWS_LAMBDA_FUNCTION_NAME which you can use so that the resolvers are only traced when running on Lambda:

const traceResolvers = require('@lifeomic/graphql-resolvers-xray-tracing');
const schema = makeExecutableSchema( ... );
if (process.env.AWS_LAMBDA_FUNCTION_NAME) {
  traceResolvers(schema);
}

AWS Segment Size Limitation

AWS has a 64K upload limit when submitting segments to AWS see AWSXRay concepts segments.

If you try and submit more than this limit you will see the following aws error message
" [ERROR] Segment too large to send: {<traceinformation...}"

One approach to remove this error, is to reduce the size of the batch upload (eg.. setStreamingThreshold(0) which will send each subsegment on close). See SDK - nodejs - setStreamingThreshold.

graphql-resolvers-xray-tracing's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

graphql-resolvers-xray-tracing's Issues

Remove is-promise dependency?

Why not remove an external dependency on is-promise and implement:

function isPromise(obj) {
  return !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
}

in index.js itself.

An in-range update of nock is breaking the build 🚨

The devDependency nock was updated from 11.8.2 to 11.9.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

nock is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).
  • coverage/coveralls: First build on greenkeeper/nock-11.9.0 at 100.0% (Details).

Release Notes for v11.9.0

11.9.0 (2020-02-13)

Features

  • allow passing a function to enableNetConnect() (#1889) (566461b)
Commits

The new version differs by 11 commits.

  • a275769 test: Update got to the latest version and fill in missing coverage (#1825)
  • 566461b feat: allow passing a function to enableNetConnect() (#1889)
  • 11c0542 Require Node 10+ (#1895)
  • e04d61d Update mkdirp to the latest version 🚀 (#1857)
  • 9379f09 Do not return the nock global from cleanAll() (#1872)
  • 6c504c3 Drop support for String constructor (#1873)
  • 1fae725 refactor(test): use Mocha DSL for allow unmocked (#1894)
  • d0694a7 ci: move semantic-release to GitHub Action
  • 524dd29 test: fix assertRejects usage (#1890)
  • 5d3b270 refactor(test): Chai assert allow unmocked (#1891)
  • 5eaa5f5 Bump lolex and sinon (#1887)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of is-promise is breaking the build 🚨


☝️ Important announcement: Greenkeeper will be saying goodbye 👋 and passing the torch to Snyk on June 3rd, 2020! Find out how to migrate to Snyk and more at greenkeeper.io


The dependency is-promise was updated from 2.1.0 to 2.2.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

is-promise is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).
  • coverage/coveralls: First build on greenkeeper/is-promise-2.2.0 at 100.0% (Details).

Release Notes for 2.2.0
  • Adds TypeScript definition
  • Adds support for ES Module style default import
Commits

The new version differs by 12 commits.

  • 78eec0c docs: update example to es6
  • feb90a4 feat: support type narrowing via isPromise and default export
  • 562a060 add typescript declaration file (#10)
  • eb988e0 Create FUNDING.yml
  • d1665cd chore: update CI versions
  • 874c17f Added tests for func (#9)
  • cba5862 Fix broken logo (#8)
  • 580e433 remove codesponsor (#7)
  • a43f799 Add sponsor
  • ff47ce5 Update badges
  • c43eeab Merge pull request #5 from floatdrop/patch-1
  • d023ef1 Include only index.js in module

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper App’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.

Error on tsc

When running tsc I am getting the following error:

❯ yarn run tsc --noEmit
yarn run v1.22.10
$ node_modules/.bin/tsc --noEmit
node_modules/@lifeomic/graphql-resolvers-xray-tracing/src/traceResolvers.ts:26:23 - error TS1196: Catch clause variable cannot have a type annotation.

26       } catch (error: any) {
                         ~~~


Found 1 error.

Circular structure on error

Hey there! First off, a huge thanks for authoring this, it's incredibly useful!

Unfortunately there is an issue with x-ray where data (errors, annotations, etc) cannot be properly serialized if they have a circular structure which leaves a potential for runtime crashes depending on the error.

Is it possible to get a release out of this which serializes the errors?

Running locally

Hello, and thanks for this project. I added this to a graphql server that runs on Lambda and it works great. However, I can't run my server locally. I added this conditional to make it work. Is this something you'd consider adding to the library?

if (process.env.AWS_LAMBDA_FUNCTION_NAME) {
  traceResolvers(schema);
}

-d was unexpected at this time

Hi, 2 members of my team have been having trouble installing this package using git bash, for whatever reason npm running on git bash in windows is complaining about the if statement in the postinstall script. I had both of them try just typing a bash if statement to check for a directory and that seems to work, it's just failing when npm tries to execute the postinstall script.

Looking at that script, it appears that it's checking if there is a tests directory, and if so execute graphql-codegen. Is it necessary to have package consumers run this script? or could it be moved elsewhere?

"postinstall": "if [ -d test ]; then yarn types; fi",

image

FYI, they are both running windows 10, and
git bash version is 4.4.12(3)
npm version is 6.14.12
node version is 12.22.1

@DavidTanner

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.