{"id":18377201,"url":"https://github.com/bbc/http-transport-emf-stats","last_synced_at":"2026-05-14T20:04:14.921Z","repository":{"id":48374452,"uuid":"279809197","full_name":"bbc/http-transport-emf-stats","owner":"bbc","description":"An http-transport plugin that adds stats information about the upstream request/response, errors, cache events etc. This plugin can be used in combination with CloudWatch EMF.","archived":false,"fork":false,"pushed_at":"2021-07-29T09:17:47.000Z","size":95,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2026-04-09T05:43:11.533Z","etag":null,"topics":["aws","emf","http","http-transport","https","sounds","sounds-web","statistics","stats"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bbc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-15T08:18:55.000Z","updated_at":"2021-07-29T09:17:49.000Z","dependencies_parsed_at":"2022-08-24T14:49:47.569Z","dependency_job_id":null,"html_url":"https://github.com/bbc/http-transport-emf-stats","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/bbc/http-transport-emf-stats","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbc%2Fhttp-transport-emf-stats","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbc%2Fhttp-transport-emf-stats/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbc%2Fhttp-transport-emf-stats/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbc%2Fhttp-transport-emf-stats/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bbc","download_url":"https://codeload.github.com/bbc/http-transport-emf-stats/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbc%2Fhttp-transport-emf-stats/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33041218,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-13T13:14:54.681Z","status":"online","status_checked_at":"2026-05-14T02:00:06.663Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["aws","emf","http","http-transport","https","sounds","sounds-web","statistics","stats"],"created_at":"2024-11-06T00:27:18.335Z","updated_at":"2026-05-14T20:04:14.903Z","avatar_url":"https://github.com/bbc.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![BBC](https://circleci.com/gh/bbc/http-transport-emf-stats.svg?style=shield)](https://app.circleci.com/pipelines/github/bbc/http-transport-emf-stats?branch=master)\n\n* [Installation](#installation)\n* [Usage](#usage)\n* [Stats](#stats)\n* [Testing and linting](#testing-and-linting)\n\n# HTTP transport EMF stats\n\nEMF stats is a plugin that can be used by [http-transport](https://github.com/bbc/http-transport) to return a stats object alongside the HTTP response.\n\n## Installation\n\n```bash\nnpm install @bbc/http-transport-emf-stats\n```\n\nor\n\n```bash\nyarn add @bbc/http-transport-emf-stats\n```\n\n## Usage\n\n```js\nimport HttpTransport from '@bbc/http-transport';\n\nconst client = HttpTransport\n  .createBuilder()\n  .userAgent('...')\n  .retries(...)\n  .retryDelay(...)\n  .use(stats())\n  .createClient();\n```\n\n**With the cache enabled**\n\nUsed in conjunction with [@bbc/http-transport-cache](https://github.com/bbc/http-transport-cache)\n\n```js\nimport HttpTransport from '@bbc/http-transport';\nimport { maxAge, staleIfError } from '@bbc/http-transport-cache';\n\nconst catbox = ...; // a catbox instance\n\nconst cacheOpts = {\n  name: 'rms',\n  ...\n  ...\n}\n\nconst client = HttpTransport\n  .createBuilder()\n  .userAgent('...')\n  .retries(...)\n  .retryDelay(...)\n  .use(stats())\n  .use(maxAge(catbox, cacheOpts))\n  .use(staleIfError(catbox, cacheOpts))\n  .createClient();\n```\n\n## Stats\n\nThe stats object is structured as following:\n\n```js\n{\n  metrics: {\n    attemptCount: 0, // The number of request attempts in total. This number is equal to \"attempts.length\".\n    retryCount: 0, // The number of retried attempts. This number is equal to \"attemptCount - 1\".\n    requestCount: 0, // The number of times a request is sent to and a response is received from the upstream\n    requestErrorCount: 0, // The number of times the upstream service doesn't respond\n    response5xxCount: 0, // The number of 5xx responses\n    response4xxCount: 0, // The number of 4xx responses\n    response3xxCount: 0, // The number of 3XX responses\n    response2xxCount: 0, // The number of 2XX responses\n    response1xxCount: 0, // The number of 1XX responses\n    responseInvalidCount: 0, // The number of invalid response statuses\n    responseTime: 0,\n    cacheHitCount: 0,\n    cacheMissCount: 0,\n    cacheStaleCount: 0,\n    cacheErrorCount: 0,\n    cacheTimeoutCount: 0,\n    cacheConnectionErrorCount: 0\n  },\n  cacheAudit: [] // A list of cache events triggered by the cache plugin. It is used for troubleshooting purposes only.\n}\n```\n\nThe `stats` object is set within `res` when the request resolves or in the error object when it rejects. If you want to access the stats info do as following:\n\n```js\ntry {\n  const response = await client.get(uri).asResponse();\n  const { stats } = response.res;\n\n  // can access stats data\n} catch (error) {\n  const { stats } = error;\n\n  // can access stats data\n}\n```\n## Testing and linting\n\nTo run unit tests and coverage reports\n\n```\nnpm run test\n```\n\nor just tests without coverage report\n\n```\nnpm run test:only\n```\n\nTo run code linting\n\n```\nnpm run lint\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbbc%2Fhttp-transport-emf-stats","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbbc%2Fhttp-transport-emf-stats","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbbc%2Fhttp-transport-emf-stats/lists"}