Feature Request: configurable telemetry
- Vorherrschende Sprache
- Go
- Sterne
- 11.3k
- Forks
- 2.5k
- Ø Merge
- 1 T. 20 Std.
- Gemergte PRs (30 T.)
- 52
Beschreibung
In a web service which may be making tens of thousands of call to Github, it's desirable to have instrumentation to identify hot code paths, bad tenants, or poor optimizations resulting in extra API calls.
Currently there are three ways to gain metrics on the API requests:
1. Wrapping every API call with a wrapper that emits the telemetry data
Ugly, a little verbose, easy for new code to accidentally forget to wrap the API call or manually emit the telemetry data, isn't accurate when paging
2. Wrapping API client access with a wrapper which emits the telemetry data every time get the client
Pretty clean, very easy to subvert by saving the returned client in a variable, isn't accurate when paging
3. Wrapping the entire struct and every necessary struct method
Very safe from accidentally using the client without metrics, boilerplate hell, isn't accurate when paging
It would be very helpful for the library to provide a mechanism to instrument the API usage with some form of telemetry. Any kind of pluggable middleware, callbacks, or hook would add a lot of utility. If there is a way to do this which is both hard to accidentally workaround and doesn't require a lot of boilerplate, that would be awesome to know about and document!
One very simple or rudimentary option would be to add an optional field `Client.OnDo: func()` (also settable via `Client.WithCallback()` or something) which, if set, would be called during `Client.bareDo` just before `caller.Do()`. A example usage might be:
```go
func metricEmitter(org: string, repo: string) func() {
return func() {
metrics.emit("api-request", tags: map[string]string{"organization": org, "repository": repo})
}
...
prs, _, err := client
.WithCallback(metricEmitter(request.Args.Owner, request.Args.Repository))
.PullRequests
.List(request.Args.Owner, request.Args.Repository)
```
Beitragsleitfaden
Rechercherichtung
Beginnen Sie damit, Client.bareDo und den im Issue erwähnten caller.Do-Pfad zu lesen, und verfolgen Sie anschließend, wie Requests und Paginierung durch den Client fließen. Vergleichen Sie den vorgeschlagenen Callback mit den Middleware- oder Hook-Alternativen und bestimmen Sie, wie Aufrufer ihn konfigurieren würden, ohne versehentlich die Instrumentierung zu umgehen. Als erledigt gilt die Aufgabe, wenn die API eine dokumentierte Möglichkeit mit wenig Boilerplate bietet, Requests einschließlich paginierter Aufrufe zu beobachten.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- go
- Bereich
- api, observability-sre
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100