Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lifeomic/graphql-resolvers-xray-tracing
A GraphQL middleware to enable X-Ray tracing subsegments for GraphQL resolvers
https://github.com/lifeomic/graphql-resolvers-xray-tracing
aws-xray graphql team-infra
Last synced: 2 days ago
JSON representation
A GraphQL middleware to enable X-Ray tracing subsegments for GraphQL resolvers
- Host: GitHub
- URL: https://github.com/lifeomic/graphql-resolvers-xray-tracing
- Owner: lifeomic
- License: mit
- Created: 2018-05-30T01:40:07.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-09-12T00:00:46.000Z (2 months ago)
- Last Synced: 2024-10-12T19:48:39.174Z (about 1 month ago)
- Topics: aws-xray, graphql, team-infra
- Language: TypeScript
- Size: 2.49 MB
- Stars: 68
- Watchers: 24
- Forks: 16
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# GraphQL Middleware to add X-Ray tracing for resolvers
[![npm](https://img.shields.io/npm/v/@lifeomic/graphql-resolvers-xray-tracing.svg)](https://www.npmjs.com/package/@lifeomic/graphql-resolvers-xray-tracing)
[![Build Status](https://github.com/lifeomic/graphql-resolvers-xray-tracing/actions/workflows/release.yaml/badge.svg)](https://github.com/lifeomic/graphql-resolvers-xray-tracing/actions/workflows/release.yaml)
[![Coverage Status](https://coveralls.io/repos/github/lifeomic/graphql-resolvers-xray-tracing/badge.svg?branch=master)](https://coveralls.io/github/lifeomic/graphql-resolvers-xray-tracing?branch=master)
![Dependabot Badge](https://flat.badgen.net/dependabot/lifeomic/graphql-resolvers-xray-tracing?icon=dependabot)To enable X-Ray subsegment creation for GraphQL resolvers, add this package as a dependency of your project and use
code like this:```javascript
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](images/trace-screenshot.png)
## 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:
```js
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](https://docs.aws.amazon.com/xray/latest/devguide/xray-concepts.html#xray-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: {