{"id":13530352,"url":"https://github.com/DanielMSchmidt/apollo-opentracing","last_synced_at":"2025-04-01T18:31:36.176Z","repository":{"id":38050281,"uuid":"145334402","full_name":"DanielMSchmidt/apollo-opentracing","owner":"DanielMSchmidt","description":"Performance trace your Apollo GraphQL server with Opentracing","archived":false,"fork":false,"pushed_at":"2024-09-27T19:43:26.000Z","size":7873,"stargazers_count":182,"open_issues_count":13,"forks_count":24,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-13T14:16:57.701Z","etag":null,"topics":["apollo-server","apollographql","graphql","jaegertracing","opentracing","performance-monitoring","zipkin"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DanielMSchmidt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-19T20:13:04.000Z","updated_at":"2024-09-21T09:57:06.000Z","dependencies_parsed_at":"2023-12-12T01:42:09.309Z","dependency_job_id":"5ba35fef-a69a-4f6e-a8c9-84f175c0f6b0","html_url":"https://github.com/DanielMSchmidt/apollo-opentracing","commit_stats":{"total_commits":515,"total_committers":15,"mean_commits":"34.333333333333336","dds":"0.25631067961165044","last_synced_commit":"8dc3834e55fb4fcc48247e2399682cd48752ba4f"},"previous_names":[],"tags_count":154,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanielMSchmidt%2Fapollo-opentracing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanielMSchmidt%2Fapollo-opentracing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanielMSchmidt%2Fapollo-opentracing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanielMSchmidt%2Fapollo-opentracing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DanielMSchmidt","download_url":"https://codeload.github.com/DanielMSchmidt/apollo-opentracing/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246372740,"owners_count":20766635,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["apollo-server","apollographql","graphql","jaegertracing","opentracing","performance-monitoring","zipkin"],"created_at":"2024-08-01T07:00:48.606Z","updated_at":"2025-04-01T18:31:35.893Z","avatar_url":"https://github.com/DanielMSchmidt.png","language":"TypeScript","funding_links":[],"categories":["TypeScript","Uncategorized"],"sub_categories":["Uncategorized"],"readme":"# Apollo Opentracing [![npm version](https://badge.fury.io/js/apollo-opentracing.svg)](https://badge.fury.io/js/apollo-opentracing) [![Build Status](https://travis-ci.com/DanielMSchmidt/apollo-opentracing.svg?branch=master)](https://travis-ci.com/DanielMSchmidt/apollo-opentracing) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release) [![All Contributors](https://img.shields.io/badge/all_contributors-4-orange.svg?style=flat-square)](#contributors)\n\nApollo Opentracing allows you to integrate open source baked performance tracing to your Apollo server based on industry standards for tracing.\n\n- 🚀 Request \u0026 Field level resolvers are traced out of the box\n- 🔍 Queries and results are logged, to make debugging easier\n- ⚙️ Select which requests you want to trace\n- 🔗 Spans transmitted through the HTTP Headers are picked up\n- 🔧 Use the opentracing compatible tracer you like, e.g.\n  - [jaeger](https://www.jaegertracing.io/)\n  - [zipkin](https://github.com/DanielMSchmidt/zipkin-javascript-opentracing)\n- 🦖 Support from node 6 on\n\n## Installation\n\nRun `npm install --save apollo-opentracing` given that you already setup an opentracing tracer accordingly.\n\n## Setup\n\nWe need two types of tracer (which could be identical if you like):\n\n- server: Only used for the root (the first span we will start)\n- local: Used to start every other span\n\n```diff\nconst { graphqlExpress } = require(\"apollo-server-express\");\nconst {serverTracer, localTracer} = require(\"./tracer\");\n+const OpentracingPlugin = require(\"apollo-opentracing\").default;\n\napp.use(\n  \"/graphql\",\n  bodyParser.json(),\n  graphqlExpress({\n    schema,\n+   plugins: [OpentracingPlugin({\n+     server: serverTracer,\n+     local: localTracer,\n+   })]\n  })\n)\n```\n\n## Connecting Services\n\n![example image](demo.png)\n\nTo connect other services you need to use the opentracing [inject](http://opentracing.io/documentation/pages/api/cross-process-tracing.html) function of your tracer.\nWe pass the current span down to your resolvers as `info.span`, so you should use it.\n\nYou can also make use of it and add new logs or tags on the fly if you like.\nThis may look something like this:\n\n```js\nmyFieldResolver(source, args, context, info) {\n  const headers = {...};\n\n  const parentSpan = info.span;\n  // please use the same tracer you passed down to the extension\n  const networkSpan = tracer.startSpan(\"NetworkRequest:\" + endpoint, {\n    childOf: parentSpan\n  });\n\n  // Let's transfer the span information to the headers\n  tracer.inject(\n    networkSpan,\n    YourOpentracingImplementation.FORMAT_HTTP_HEADERS,\n    headers\n  );\n\n  return doNetworkRequest(endpoint, headers).then(result =\u003e {\n    networkSpan.finish()\n    return result;\n  }, err =\u003e {\n    networkSpan.log({\n      error: true,\n      errorMessage: err\n    });\n\n    networkSpan.finish();\n    return err;\n  });\n}\n```\n\n## Selective Tracing\n\nSometimes you don't want to trace everything, so we provide ways to select if you want to start a span right now or not.\n\n### By Request\n\nIf you construct the extension with `shouldTraceRequest` you get the option to opt-in or out on a request basis.\nWhen you don't start the span for the request the field resolvers will also not be used.\n\nThe function is called with the same arguments as the `requestDidStart` function extensions can provide, which is documented [here](https://github.com/apollographql/apollo-server/blob/master/packages/graphql-extensions/src/index.ts#L35).\n\nWhen the request is not traced there will also be no traces of the field resolvers.\n\n### By Field\n\nThere might be certain field resolvers that are not worth the tracing, e.g. when they get a value out of an object and need no further tracing. To control if you want a field resolver to be traced you can pass the `shouldTraceFieldResolver` option to the constructor. The function is called with the same arguments as your field resolver and you can get the name of the field by `info.fieldName`. When you return false no traces will be made of this field resolvers and all underlying ones.\n\n## Modifying span metadata\n\nIf you'd like to add custom tags or logs to span you can construct the extension with `onRequestResolve`. The function is called with two arguments: span and infos `onRequestResolve?: (span: Span, info: RequestStart)`\n\n## Using your own request span\n\nIf you need to take control of initializing the request span (e.g because you need to use it during context initialization) you can do so by having creating it as `context.requestSpan`.\n\n## Options\n\n- `server`: Opentracing Tracer for the incoming request\n- `local`: Opentracing Tracer for the local and outgoing requests\n- `onFieldResolve(source: any, args: { [argName: string]: any }, context: SpanContext, info: GraphQLResolveInfo)`: Allow users to add extra information to the span\n- `onFieldResolveFinish(error: Error | null, result: any, span: Span)`: Callback after a field was resolved\n- `shouldTraceRequest` \u0026 `shouldTraceFieldResolver`: See [Selective Tracing](#selective-tracing)\n- `onRequestResolve(span: Span, info: GraphQLRequestContext)`: Add extra information to the request span\n- `createCustomSpanName(name: String, info: GraphQLResolveInfo)`: Allow users to provide customized span name\n- `onRequestError(rootSpan: Span, info: GraphQLRequestContextDidEncounterErrors)`: Callback when a request errors\n\n## Contributing\n\nPlease feel free to add issues with new ideas, bugs and anything that might come up.\nLet's make performance measurement to everyone \u003c3\n\n## Contributors\n\nThanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- markdownlint-disable --\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"http://danielmschmidt.de/\"\u003e\u003cimg src=\"https://avatars2.githubusercontent.com/u/1337046?v=4?s=100\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eDaniel Schmidt\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/DanielMSchmidt/apollo-opentracing/commits?author=DanielMSchmidt\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"#ideas-DanielMSchmidt\" title=\"Ideas, Planning, \u0026 Feedback\"\u003e🤔\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/cliedeman\"\u003e\u003cimg src=\"https://avatars2.githubusercontent.com/u/3578740?v=4?s=100\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eCiaran Liedeman\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/DanielMSchmidt/apollo-opentracing/issues?q=author%3Acliedeman\" title=\"Bug reports\"\u003e🐛\u003c/a\u003e \u003ca href=\"https://github.com/DanielMSchmidt/apollo-opentracing/commits?author=cliedeman\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"https://github.com/DanielMSchmidt/apollo-opentracing/commits?author=cliedeman\" title=\"Tests\"\u003e⚠️\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"http://juhp.net\"\u003e\u003cimg src=\"https://avatars3.githubusercontent.com/u/453031?v=4?s=100\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eJens Ulrich Hjuler Pedersen\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/DanielMSchmidt/apollo-opentracing/issues?q=author%3AMultiply\" title=\"Bug reports\"\u003e🐛\u003c/a\u003e \u003ca href=\"#ideas-Multiply\" title=\"Ideas, Planning, \u0026 Feedback\"\u003e🤔\u003c/a\u003e \u003ca href=\"https://github.com/DanielMSchmidt/apollo-opentracing/pulls?q=is%3Apr+reviewed-by%3AMultiply\" title=\"Reviewed Pull Requests\"\u003e👀\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/frances3006\"\u003e\u003cimg src=\"https://avatars0.githubusercontent.com/u/9115596?v=4?s=100\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eFrancesca\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/DanielMSchmidt/apollo-opentracing/commits?author=frances3006\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://analogic.al\"\u003e\u003cimg src=\"https://avatars2.githubusercontent.com/u/84963?v=4?s=100\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eRicardo Casares\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/DanielMSchmidt/apollo-opentracing/commits?author=ricardocasares\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://keybase.io/mwieczorek\"\u003e\u003cimg src=\"https://avatars2.githubusercontent.com/u/7051680?v=4?s=100\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eMichał Wieczorek\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/DanielMSchmidt/apollo-opentracing/commits?author=mwieczorek\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://koen.pt\"\u003e\u003cimg src=\"https://avatars2.githubusercontent.com/u/351038?v=4?s=100\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eKoen Punt\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/DanielMSchmidt/apollo-opentracing/commits?author=koenpunt\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/zekenie\"\u003e\u003cimg src=\"https://avatars2.githubusercontent.com/u/962281?v=4?s=100\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eZeke Nierenberg\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/DanielMSchmidt/apollo-opentracing/commits?author=zekenie\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://app.sport-buddy.net\"\u003e\u003cimg src=\"https://avatars3.githubusercontent.com/u/1945040?v=4?s=100\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eTomáš Voslař\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/DanielMSchmidt/apollo-opentracing/commits?author=voslartomas\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"http://iam.benkimball.com/\"\u003e\u003cimg src=\"https://avatars2.githubusercontent.com/u/40365?v=4?s=100\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eBen Kimball\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/DanielMSchmidt/apollo-opentracing/commits?author=benkimball\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://jiapei.io/\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/9281185?v=4?s=100\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eJiapei Liang\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/DanielMSchmidt/apollo-opentracing/commits?author=liangjiapei\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/RichardWright\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/881815?v=4?s=100\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eRichard W\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#ideas-RichardWright\" title=\"Ideas, Planning, \u0026 Feedback\"\u003e🤔\u003c/a\u003e \u003ca href=\"#research-RichardWright\" title=\"Research\"\u003e🔬\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/leeweisberger\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/6363419?v=4?s=100\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eLee Weisberger\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/DanielMSchmidt/apollo-opentracing/commits?author=leeweisberger\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://starptech.de/\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/1764424?v=4?s=100\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eDustin Deus\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/DanielMSchmidt/apollo-opentracing/issues?q=author%3AStarpTech\" title=\"Bug reports\"\u003e🐛\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\u003c!-- markdownlint-restore --\u003e\n\u003c!-- prettier-ignore-end --\u003e\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\nThis project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDanielMSchmidt%2Fapollo-opentracing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FDanielMSchmidt%2Fapollo-opentracing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDanielMSchmidt%2Fapollo-opentracing/lists"}