{"id":16879621,"url":"https://github.com/easycz/connect-go-prometheus","last_synced_at":"2025-04-11T12:07:18.060Z","repository":{"id":62865070,"uuid":"552525818","full_name":"easyCZ/connect-go-prometheus","owner":"easyCZ","description":"Prometheus interceptors for connect-go","archived":false,"fork":false,"pushed_at":"2024-03-13T21:58:57.000Z","size":70,"stargazers_count":7,"open_issues_count":1,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T08:22:56.114Z","etag":null,"topics":["connect-go","go","golang","prometheus"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/easyCZ/connect-go-prometheus","language":"Go","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/easyCZ.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":"2022-10-16T19:38:08.000Z","updated_at":"2024-12-01T21:01:57.000Z","dependencies_parsed_at":"2023-12-24T00:28:00.826Z","dependency_job_id":"ed4559cf-430a-4425-babb-bc485422f452","html_url":"https://github.com/easyCZ/connect-go-prometheus","commit_stats":{"total_commits":14,"total_committers":2,"mean_commits":7.0,"dds":0.1428571428571429,"last_synced_commit":"5197892c5ea9f866ea8a96b6004ddc4d90537dce"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/easyCZ%2Fconnect-go-prometheus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/easyCZ%2Fconnect-go-prometheus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/easyCZ%2Fconnect-go-prometheus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/easyCZ%2Fconnect-go-prometheus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/easyCZ","download_url":"https://codeload.github.com/easyCZ/connect-go-prometheus/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248396549,"owners_count":21096957,"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":["connect-go","go","golang","prometheus"],"created_at":"2024-10-13T15:55:06.179Z","updated_at":"2025-04-11T12:07:18.037Z","avatar_url":"https://github.com/easyCZ.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# connect-go-prometheus\n[Prometheus](https://prometheus.io/) monitoring for [connect-go](https://github.com/bufbuild/connect-go).\n\n## Interceptors\nThis library defines [interceptors](https://connect.build/docs/go/interceptors) to observe both client-side and server-side calls.\n\n## Install\n```bash\ngo get -u github.com/easyCZ/connect-go-prometheus\n```\n\n## Usage\n```golang\nimport (\n    \"github.com/easyCZ/connect-go-prometheus\"\n)\n\n// Construct the interceptor. The same intereceptor is used for both client-side and server-side.\ninterceptor := connect_go_prometheus.NewInterceptor()\n\n// Use the interceptor when constructing a new connect-go handler\n_, _ := your_connect_package.NewServiceHandler(handler, connect.WithInterceptors(interceptor))\n\n// Or with a client\nclient := your_connect_package.NewServiceClient(http.DefaultClient, serverURL, connect.WithInterceptors(interceptor))\n```\nFor configuration, and more advanced use cases see [Configuration](#Configuration)\n\n## Metrics\n\nMetrics exposed use the following labels:\n* `type` - one of `unary`, `client_stream`, `server_stream` or `bidi`\n* `service` - name of the service, for example `myservice.greet.v1`\n* `method` - name of the method, for example `SayHello`\n* `code` - the resulting outcome of the RPC. The codes match [connect-go Error Codes](https://connect.build/docs/protocol#error-codes) with the addition of `ok` for succesful RPCs. \n\n\n### Server-side metrics\n* Counter `connect_server_started_total` with `(type, service, method)` labels\n* Counter `connect_server_handled_total` with `(type, service, method, code)` labels\n* (optionally) Histogram `connect_server_handled_seconds` with `(type, service, method, code)` labels\n\n### Client-side metrics\n* Counter `connect_client_started_total` with `(type, service, method)` labels\n* Counter `connect_client_handled_total` with `(type, service, method, code)` labels\n* (optionally) Histogram `connect_client_handled_seconds` with `(type, service, method, code)` labels\n\n## Configuration\n\n### Customizing client/server metrics reported\n```golang\nimport (\n    \"github.com/easyCZ/connect-go-prometheus\"\n    prom \"github.com/prometheus/client_golang/prometheus\"\n)\n\noptions := []connect_go_prometheus.MetricOption{\n    connect_go_prometheus.WithHistogram(true),\n    connect_go_prometheus.WithNamespace(\"namespace\"),\n    connect_go_prometheus.WithSubsystem(\"subsystem\"),\n    connect_go_prometheus.WithConstLabels(prom.Labels{\"component\": \"foo\"}),\n    connect_go_prometheus.WithHistogramBuckets([]float64{1, 5}),\n}\n\n// Construct client metrics\nclientMetrics := connect_go_prometheus.NewClientMetrics(options...)\n\n// Construct server metrics\nserverMetrics := connect_go_prometheus.NewServerMetrics(options...)\n\n// When you construct either client/server metrics with options, you must also register the metrics with your Prometheus Registry\nprom.MustRegister(clientMetrics, serverMetrics)\n\n// Construct the interceptor with our configured metrics\ninterceptor := connect_go_prometheus.NewInterceptor(\n    connect_go_prometheus.WithClientMetrics(clientMetrics),\n    connect_go_prometheus.WithServerMetrics(serverMetrics),\n)\n```\n\n### Registering metrics against a Registry\nYou may want to register metrics against a [Prometheus Registry](https://pkg.go.dev/github.com/prometheus/client_golang/prometheus#Registry). You can do this with the following:\n```golang\nimport (\n    \"github.com/easyCZ/connect-go-prometheus\"\n    prom \"github.com/prometheus/client_golang/prometheus\"\n)\n\nclientMetrics := connect_go_prometheus.NewClientMetrics()\nserverMetrics := connect_go_prometheus.NewServerMetrics()\n\nregistry := prom.NewRegistry()\nregistry.MustRegister(clientMetrics, serverMetrics)\n\ninterceptor := connect_go_prometheus.NewInterceptor(\n    connect_go_prometheus.WithClientMetrics(clientMetrics),\n    connect_go_prometheus.WithServerMetrics(serverMetrics),\n)\n```\n\n### Disabling client/server metrics reporting\nTo disable reporting of either client or server metrics, pass `nil` as an option.\n```golang\nimport (\n    \"github.com/easyCZ/connect-go-prometheus\"\n)\n\n// Disable client-side metrics\ninterceptor := connect_go_prometheus.NewInterceptor(\n    connect_go_prometheus.WithClientMetrics(nil),\n)\n\n// Disable server-side metrics\ninterceptor := connect_go_prometheus.NewInterceptor(\n    connect_go_prometheus.WithServerMetrics(nil),\n)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feasycz%2Fconnect-go-prometheus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feasycz%2Fconnect-go-prometheus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feasycz%2Fconnect-go-prometheus/lists"}