{"id":13487630,"url":"https://github.com/inlym/egg-apigw-tracer","last_synced_at":"2026-01-25T17:01:35.340Z","repository":{"id":57220303,"uuid":"310781312","full_name":"inlym/egg-apigw-tracer","owner":"inlym","description":"⚡ 适配 API 网关的 HTTP 请求示踪器，用于 Egg.js 框架","archived":false,"fork":false,"pushed_at":"2021-05-07T08:42:10.000Z","size":26,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-31T02:25:06.841Z","etag":null,"topics":["egg","egg-plugin","eggjs","eggplugin"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/inlym.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}},"created_at":"2020-11-07T06:19:00.000Z","updated_at":"2024-04-29T10:54:47.000Z","dependencies_parsed_at":"2022-08-29T00:11:48.641Z","dependency_job_id":null,"html_url":"https://github.com/inlym/egg-apigw-tracer","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/inlym/egg-apigw-tracer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inlym%2Fegg-apigw-tracer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inlym%2Fegg-apigw-tracer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inlym%2Fegg-apigw-tracer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inlym%2Fegg-apigw-tracer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/inlym","download_url":"https://codeload.github.com/inlym/egg-apigw-tracer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inlym%2Fegg-apigw-tracer/sbom","scorecard":{"id":489050,"data":{"date":"2025-08-11","repo":{"name":"github.com/inlym/egg-apigw-tracer","commit":"c112b5b0ee8e67b28fc9f8c60f1a5f7dc402f7e5"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Code-Review","score":0,"reason":"Found 0/13 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-19T18:34:47.474Z","repository_id":57220303,"created_at":"2025-08-19T18:34:47.474Z","updated_at":"2025-08-19T18:34:47.474Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28755561,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-25T16:32:25.380Z","status":"ssl_error","status_checked_at":"2026-01-25T16:32:09.189Z","response_time":113,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["egg","egg-plugin","eggjs","eggplugin"],"created_at":"2024-07-31T18:01:01.384Z","updated_at":"2026-01-25T17:01:35.320Z","avatar_url":"https://github.com/inlym.png","language":"JavaScript","funding_links":[],"categories":["Plugins","仓库"],"sub_categories":["插件"],"readme":"# egg-apigw-tracer\r\n\r\n[![npm version](https://img.shields.io/npm/v/egg-apigw-tracer)](https://www.npmjs.com/package/egg-apigw-tracer) [![MIT](https://img.shields.io/npm/l/egg-apigw-tracer)](https://github.com/inlym/egg-apigw-tracer/blob/master/LICENSE) [![npm](https://img.shields.io/npm/dw/egg-apigw-tracer)](https://www.npmjs.com/package/egg-apigw-tracer) [![star](https://gitee.com/inlym/egg-apigw-tracer/badge/star.svg?theme=dark)](https://gitee.com/inlym/egg-apigw-tracer/stargazers)\r\n\r\n![egg-apigw-tracer-image](https://img.inlym.com/dca8bebe5e534bfa87b52f42e7be282c.png)\r\n\r\n适配 API 网关的 HTTP 请求示踪器，用于 Egg.js 框架。\r\n\r\n## 目录\r\n\r\n- [egg-apigw-tracer](#egg-apigw-tracer)\r\n  - [目录](#目录)\r\n  - [介绍](#介绍)\r\n  - [安装](#安装)\r\n  - [使用](#使用)\r\n    - [启用插件](#启用插件)\r\n    - [配置方式](#配置方式)\r\n    - [使用说明](#使用说明)\r\n  - [示例](#示例)\r\n  - [相关](#相关)\r\n  - [作者](#作者)\r\n  - [参与](#参与)\r\n  - [许可证](#许可证)\r\n\r\n## 介绍\r\n\r\n在对外提供 Web 服务时，可能在线上环境出现偶发性的错误，为了方便排查问题，给所有的请求都提供一个 **唯一请求 ID** 是一个不错的实践，开发者可以根据这个请求 ID 去相关日志中找寻对应的错误内容。\r\n\r\n这个「唯一请求 ID」（Unique Request ID）有的时候也叫「示踪 ID」（trace ID），一个通俗的做法是使用 UUID 生成一个字符串，并在响应中附带该字符串。另外一些 Web 服务，会使用云厂商的 API 网关作为接入层，然后将请求转发到开发者自己的服务器上。此时我们往往希望使用 API 网关自带的请求 ID 作为示踪 ID，本插件就是为了解决这个问题诞生的。\r\n\r\n本插件完美适配 **Egg.js** 框架，只需要按照框架要求启用插件，可以**零配置**使用。\r\n\r\n## 安装\r\n\r\n按照通用的方式使用 npm 下载安装到你的项目下即可，无需全局安装。\r\n\r\n安装命令：\r\n\r\n```shell\r\nnpm i egg-apigw-tracer\r\n```\r\n\r\n## 使用\r\n\r\n在使用前，请确保你已经阅读 Egg.js 框架关于**插件**的 [文档](https://eggjs.org/zh-cn/basics/plugin.html) 。\r\n\r\n下面说明如何配置以及使用插件。\r\n\r\n### 启用插件\r\n\r\n在 `config/plugin.js` 文件中中声明启用插件：\r\n\r\n```js\r\nexports.tracer = {\r\n  /** 是否启用插件，true 为启用，false 为禁用 */\r\n  enable: true,\r\n\r\n  /** 指定插件使用的包，为 'egg-apigw-tracer' */\r\n  package: 'egg-apigw-tracer',\r\n}\r\n```\r\n\r\n### 配置方式\r\n\r\n本插件无需任何配置即可使用。但考虑到以下使用场景：\r\n\r\n\u003e 线上生产环境使用 API 网关做接入层，使用 API 网关自带的请求 ID 做示踪 ID，但本地开发环境无该接入层，同时为了保持功能逻辑一致，也需要一个类似的示踪 ID，因此使用 UUID 做示踪 ID。\r\n\r\n在 `config/config.${env}.js` 文件配置插件的使用方式（以下为默认配置）：\r\n\r\n```js\r\nexports.tracer = {\r\n  mode: 'apigw',\r\n  idHeader: 'x-ca-request-id',\r\n}\r\n```\r\n\r\n各配置项的含义是：\r\n\r\n|   属性   |  类型  |      默认值       | 是否必填 |                                        说明                                        |\r\n| :------: | :----: | :---------------: | :------: | :--------------------------------------------------------------------------------: |\r\n|   mode   | string |      'apigw'      |    否    | 模式，使用 `apigw` 表示存在 API 网关接入层，使用 `uuid` 表示使用 uuid 生成示踪 ID  |\r\n| idHeader | string | 'x-ca-request-id' |    否    | 仅在使用`apigw` 模式下该设置项有效，表明从指定的请求头中获取`requestId`用作示踪 ID |\r\n\r\n### 使用说明\r\n\r\n主要有 2 处使用场景，一是你可以直接通过 `ctx.traceId` 获取示踪 ID，二是你使用 `ctx.logger` 打印日志时，框架会自动在日志前附上示踪 ID，前缀格式为：`[$userId/$ip/$traceId/${cost}ms $method $url]` ，详情见 [文档](https://eggjs.org/zh-cn/core/logger.html#如何打印日志) 。\r\n\r\n## 示例\r\n\r\n我们模拟以下这个使用场景，来演示如何配置和使用本插件：\r\n\r\n\u003e 线上生产环境使用 [阿里云](https://promotion.aliyun.com/ntms/yunparter/invite.html?userCode=lzfqdh6g) API 网关做接入层，本地开发测试未使用特定接入层。\r\n\r\n在 `config/plugin.js` 文件中中声明启用插件：\r\n\r\n```js\r\nexports.tracer = {\r\n  enable: true,\r\n  package: 'egg-apigw-tracer',\r\n}\r\n```\r\n\r\n在 `config.local.js` 文件中配置内容为：\r\n\r\n```js\r\nexports.tracer = {\r\n  mode: 'uuid',\r\n}\r\n```\r\n\r\n在 `config.prod.js` 文件中配置内容为：\r\n\r\n```js\r\nexports.tracer = {\r\n  mode: 'apigw',\r\n}\r\n```\r\n\r\n## 相关\r\n\r\n以下是作者开发的 Egg.js 框架的插件系列，已用于作者的生产项目中，推荐使用。\r\n\r\n- [egg-apigw-tracer](https://github.com/inlym/egg-apigw-tracer) - ⚡ 适配 API 网关的 HTTP 请求示踪器，用于 Egg.js 框架\r\n- [egg-aliyun-tablestore](https://github.com/inlym/egg-aliyun-tablestore) - 🚚 阿里云表格存储（Tablestore）插件，用于 Egg.js 框架\r\n- [egg-load](https://github.com/inlym/egg-load) - 🚀 自动挂载第三方模块至 Egg.js 框架上\r\n\r\n## 作者\r\n\r\n我是 [inlym](https://www.inlym.com) ，一个产品经理和全栈开发者。\r\n\r\n如果你有任何问题或者建议，欢迎联系我，以下是我的联系方式：\r\n\r\n- 邮箱：inlym@qq.com\r\n- 主页：[www.inlym.com](https://www.inlym.com)\r\n\r\n## 参与\r\n\r\n非常欢迎你能够参与这个项目的开发和维护。\r\n\r\n你可以通过以下几种方式参与到项目中：\r\n\r\n1.  提建议和需求。对于几句话就能说清楚的建议和需求，你可以直接 提一个 [New Issue](https://github.com/inlym/egg-apigw-tracer/issues/new) 。\r\n2.  Fork 项目，修改代码，然后提交 Pull requests 。（提交前请检查务必通过 ESLint 检查）\r\n\r\n## 许可证\r\n\r\n本插件使用 [MIT](LICENSE) 许可证。\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finlym%2Fegg-apigw-tracer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finlym%2Fegg-apigw-tracer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finlym%2Fegg-apigw-tracer/lists"}