{"id":15407312,"url":"https://github.com/izumin5210/nrgrpc","last_synced_at":"2025-04-18T03:18:48.165Z","repository":{"id":57482767,"uuid":"105601082","full_name":"izumin5210/nrgrpc","owner":"izumin5210","description":"📈 gRPC `stats.Handler` implementation to measure and send performances metrics to New Relic","archived":false,"fork":false,"pushed_at":"2022-10-13T23:57:34.000Z","size":44,"stargazers_count":9,"open_issues_count":3,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-29T06:21:47.940Z","etag":null,"topics":["golang","grpc","newrelic"],"latest_commit_sha":null,"homepage":"https://godoc.org/github.com/izumin5210/nrgrpc","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/izumin5210.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":"2017-10-03T00:59:04.000Z","updated_at":"2023-12-04T10:16:46.000Z","dependencies_parsed_at":"2022-09-03T07:00:16.558Z","dependency_job_id":null,"html_url":"https://github.com/izumin5210/nrgrpc","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izumin5210%2Fnrgrpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izumin5210%2Fnrgrpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izumin5210%2Fnrgrpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izumin5210%2Fnrgrpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/izumin5210","download_url":"https://codeload.github.com/izumin5210/nrgrpc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249419560,"owners_count":21268659,"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":["golang","grpc","newrelic"],"created_at":"2024-10-01T16:28:27.304Z","updated_at":"2025-04-18T03:18:48.140Z","avatar_url":"https://github.com/izumin5210.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nrgrpc\n[![Build Status](https://travis-ci.com/izumin5210/nrgrpc.svg?branch=master)](https://travis-ci.com/izumin5210/nrgrpc)\n[![codecov](https://codecov.io/gh/izumin5210/nrgrpc/branch/master/graph/badge.svg)](https://codecov.io/gh/izumin5210/nrgrpc)\n[![GoDoc](https://godoc.org/github.com/izumin5210/nrgrpc?status.svg)](https://godoc.org/github.com/izumin5210/nrgrpc)\n[![Go project version](https://badge.fury.io/go/github.com%2Fizumin5210%2Fnrgrpc.svg)](https://badge.fury.io/go/github.com%2Fizumin5210%2Fnrgrpc)\n[![Go Report Card](https://goreportcard.com/badge/github.com/izumin5210/nrgrpc)](https://goreportcard.com/report/github.com/izumin5210/nrgrpc)\n[![license](https://img.shields.io/github/license/izumin5210/nrgrpc.svg)](./LICENSE)\n\ngRPC `stats.Handler` implementation to measure and send performances metrics to New Relic.\n\n## Example\n### gRPC server\n\n`nrgrpc.NewServerStatsHandler` creates a [`stats.Handler`](https://godoc.org/google.golang.org/grpc/stats#Handler) instance for gRPC servers.\nWhen the handler is passed to a gRPC server with [`grpc.StatsHandler`](https://godoc.org/google.golang.org/grpc#StatsHandler),\nit will set a [`newrelic.Transaction`](https://godoc.org/github.com/newrelic/go-agent#Transaction) into a request `context.Context` using [`newrelic.NewContext`](https://godoc.org/github.com/newrelic/go-agent#NewContext).\nSo you can retrieve `newrelic.Transaction` instances with [`newrelic.FromContext`](https://godoc.org/github.com/newrelic/go-agent#FromContext).\n\n```go\nfunc main() {\n\tlis, err := net.Listen(\"tcp\", \":3000\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// Initiailze a `newrelic.Appliation`\n\tcfg := newrelic.NewConfig(\"your_app\",\"your_license_key\")\n\tnrapp, err := newrelic.NewApplication(cfg)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\ts := grpc.NewServer(\n\t\t// Create a `stats.Handler` from `newrelic.Application`\n\t\tgrpc.StatsHandler(nrgrpc.NewServerStatsHandler(nrapp)),\n\t)\n\n\t// Register server implementations\n\n\ts.Serve(lis)\n}\n```\n\n### gRPC client\n\n```go\nfunc main() {\n\t// Initiailze a `newrelic.Appliation`\n\tnrapp, err := newrelic.NewApplication(newrelic.Config{\n\t\tAppName: \"your_app\",\n\t\tLicense: \"your_license_key\",\n\t})\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// Create a `grpc.ClientConn` with `stats.Handler`\n\tconn, err := grpc.Dial(\n\t\t\":3000\",\n\t\tgrpc.WithInsecure(),\n\t\tgrpc.WithStatsHandler(nrgrpc.NewClientStatsHandler()),\n\t)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\n\t// Register http handler using `https://godoc.org/github.com/newrelic/go-agent.WrapHandleFunc`.\n\t// This wrapper sets `newrelic.Transaction` into the `http.Request`'s context.\n\tnrhttp.WrapHandleFunc(app, \"/foo\", func(w http.ResponseWriter, r *http.Request) {\n\t\tresp, err := NewFooServiceClient.BarCall(r.Context(), \u0026BarRequest{})\n\t\t// ...\n\t})\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fizumin5210%2Fnrgrpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fizumin5210%2Fnrgrpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fizumin5210%2Fnrgrpc/lists"}