google / google/go-github

Feature Request: configurable telemetry

Aperta
#3,658 5 commenti 2 reazioni 0 assegnatari Vedi su GitHub
waiting for reply
Lingua principale
Go
Stelle
11.3k
Fork
2.5k
Merge medio
1g 20h
PR unite (30g)
52

Descrizione

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)
```

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia leggendo Client.bareDo e il percorso caller.Do menzionato nell’issue, quindi traccia il flusso delle requests e della paginazione attraverso il client. Confronta il callback proposto con le alternative middleware o hook e determina come i chiamanti lo configurerebbero senza aggirare accidentalmente la strumentazione. Il lavoro è completato quando l’API supporta un modo documentato e con poco boilerplate per osservare le requests, comprese le chiamate paginate.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
go
Ambito
api, observability-sre
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.