{"id":16003523,"url":"https://github.com/nhatthm/go-requestid","last_synced_at":"2026-04-02T18:38:34.246Z","repository":{"id":219025942,"uuid":"747951939","full_name":"nhatthm/go-requestid","owner":"nhatthm","description":null,"archived":false,"fork":false,"pushed_at":"2025-09-02T19:51:38.000Z","size":116,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-28T19:55:32.687Z","etag":null,"topics":["go","golang","http","http-client","http-middleware","http-server","requestid"],"latest_commit_sha":null,"homepage":"","language":"Go","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/nhatthm.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-01-25T00:47:43.000Z","updated_at":"2025-09-02T19:51:41.000Z","dependencies_parsed_at":"2024-02-19T21:25:30.019Z","dependency_job_id":"8d5a35a0-2d93-4bd6-acae-f8e6decbd711","html_url":"https://github.com/nhatthm/go-requestid","commit_stats":null,"previous_names":["nhatthm/go-requestid"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/nhatthm/go-requestid","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhatthm%2Fgo-requestid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhatthm%2Fgo-requestid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhatthm%2Fgo-requestid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhatthm%2Fgo-requestid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nhatthm","download_url":"https://codeload.github.com/nhatthm/go-requestid/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhatthm%2Fgo-requestid/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31313089,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-02T12:59:32.332Z","status":"ssl_error","status_checked_at":"2026-04-02T12:54:48.875Z","response_time":89,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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":["go","golang","http","http-client","http-middleware","http-server","requestid"],"created_at":"2024-10-08T10:21:07.104Z","updated_at":"2026-04-02T18:38:34.227Z","avatar_url":"https://github.com/nhatthm.png","language":"Go","funding_links":["https://www.paypal.com/donate/?hosted_button_id=PJZSGJN57TDJY"],"categories":[],"sub_categories":[],"readme":"# RequestID\n\n[![GitHub Releases](https://img.shields.io/github/v/release/nhatthm/go-requestid)](https://github.com/nhatthm/go-requestid/releases/latest)\n[![Build Status](https://github.com/nhatthm/go-requestid/actions/workflows/test.yaml/badge.svg)](https://github.com/nhatthm/go-requestid/actions/workflows/test.yaml)\n[![codecov](https://codecov.io/gh/nhatthm/go-requestid/branch/master/graph/badge.svg?token=eTdAgDE2vR)](https://codecov.io/gh/nhatthm/requestid)\n[![Go Report Card](https://goreportcard.com/badge/go.nhat.io/requestid)](https://goreportcard.com/report/go.nhat.io/requestid)\n[![GoDevDoc](https://img.shields.io/badge/dev-doc-00ADD8?logo=go)](https://pkg.go.dev/go.nhat.io/requestid)\n[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/donate/?hosted_button_id=PJZSGJN57TDJY)\n\nA library to propagate Request ID across the context.\n\n## Prerequisites\n\n- `Go \u003e= 1.23`\n\n## Install\n\n```bash\ngo get go.nhat.io/requestid\n```\n\n## Usage\n\n### HTTP Server\n\nYou can use `requestid.NewHandler()` to wrap your HTTP handler or `requestid.HandlerMiddleware()` if you use `chi` router.\n\n### HTTP Client\n\nYou can use `requestid.DefaultTransport` or `requestid.NewRoundTripper()` to wrap your HTTP transport. If your client factory supports middleware, you can use `requestid.RoundTripperMiddleware()`.\n\n### OpenTelemetry Propagation\n\nYou can use `requestid.Propagator` to propagate Request ID across the context. See [the doc](https://opentelemetry.io/docs/specs/otel/context/api-propagators/) for more details.\n\n## Examples\n\nExample 1: HTTP server and client middleware.\n\n```go\npackage integration_test\n\nimport (\n\t\"context\"\n\t\"net/http\"\n\t\"net/http/httptest\"\n\t\"testing\"\n\t\"time\"\n\n\t\"github.com/go-chi/chi/v5\"\n\t\"github.com/google/uuid\"\n\t\"github.com/stretchr/testify/assert\"\n\t\"github.com/stretchr/testify/require\"\n\n\t\"go.nhat.io/requestid\"\n)\n\nfunc TestHTTP(t *testing.T) {\n\tt.Parallel()\n\n\tactual := \"\"\n\n\t// Setup HTTP Client.\n\tc := \u0026http.Client{\n\t\tTransport: requestid.DefaultTransport,\n\t\tTimeout:   time.Second,\n\t}\n\n\t// Spin up server 2.\n\tsrv2 := httptest.NewServer(newRouter(func(w http.ResponseWriter, r *http.Request) {\n\t\tactual = requestid.FromContext(r.Context())\n\n\t\tw.WriteHeader(http.StatusOK)\n\t}))\n\n\tt.Cleanup(srv2.Close)\n\n\t// Spin up server 1.\n\tsrv1 := httptest.NewServer(newRouter(func(w http.ResponseWriter, r *http.Request) {\n\t\tnextReq, err := http.NewRequestWithContext(r.Context(), http.MethodGet, srv2.URL, nil)\n\t\trequire.NoError(t, err)\n\n\t\tresp, err := c.Do(nextReq)\n\t\trequire.NoError(t, err)\n\n\t\tdefer resp.Body.Close()\n\n\t\tw.WriteHeader(http.StatusOK)\n\t}))\n\n\tt.Cleanup(srv1.Close)\n\n\t// Make request for testing.\n\trequestID := uuid.New().String()\n\n\treq, err := http.NewRequestWithContext(context.Background(), http.MethodGet, srv1.URL, nil)\n\trequire.NoError(t, err)\n\n\treq.Header.Set(\"x-request-id\", requestID)\n\n\tresp, err := c.Do(req)\n\trequire.NoError(t, err)\n\n\tdefer resp.Body.Close()\n\n\t// Assertions.\n\tassert.Equal(t, http.StatusOK, resp.StatusCode)\n\tassert.Equal(t, requestID, actual)\n}\n\nfunc newRouter(h func(w http.ResponseWriter, r *http.Request)) *chi.Mux {\n\tr := chi.NewRouter()\n\n\tr.Use(requestid.HandlerMiddleware())\n\tr.Get(\"/\", h)\n\n\treturn r\n}\n```\n\nExample 2: OpenTelemetry propagation.\n\n```go\npackage integration_test\n\nimport (\n\t\"net/http\"\n\t\"net/http/httptest\"\n\t\"testing\"\n\n\t\"github.com/google/uuid\"\n\t\"github.com/stretchr/testify/assert\"\n\t\"github.com/stretchr/testify/require\"\n\t\"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp\"\n\n\t\"go.nhat.io/requestid\"\n)\n\nfunc TestPropagator(t *testing.T) {\n\tt.Parallel()\n\n\trequestID := uuid.New().String()\n\tactual := \"\"\n\n\th := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {\n\t\tactual = requestid.FromContext(r.Context())\n\t})\n\n\tsrv := httptest.NewServer(otelhttp.NewHandler(h, \"test\",\n\t\totelhttp.WithPropagators(requestid.Propagator{})),\n\t)\n\n\tdefer srv.Close()\n\n\treq, err := http.NewRequest(http.MethodGet, srv.URL, nil)\n\trequire.NoError(t, err)\n\n\treq.Header.Set(\"x-request-id\", requestID)\n\n\tresp, err := srv.Client().Do(req)\n\trequire.NoError(t, err)\n\trequire.NoError(t, resp.Body.Close())\n\n\tassert.Equal(t, requestID, actual)\n}\n```\n\n## Donation\n\nIf this project help you reduce time to develop, you can give me a cup of coffee :)\n\n### Paypal donation\n\n[![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/donate/?hosted_button_id=PJZSGJN57TDJY)\n\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;or scan this\n\n\u003cimg src=\"https://user-images.githubusercontent.com/1154587/113494222-ad8cb200-94e6-11eb-9ef3-eb883ada222a.png\" width=\"147px\" /\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnhatthm%2Fgo-requestid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnhatthm%2Fgo-requestid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnhatthm%2Fgo-requestid/lists"}