zitadel / oidc

Easy to use OpenID Connect client and server library written for Go and certified by the OpenID Foundation
https://zitadel.com
Apache License 2.0
1.33k stars 138 forks source link

add prometheus metrics for apis #586

Closed drinktee closed 4 months ago

drinktee commented 5 months ago

Preflight Checklist

Describe your problem

It need to add prometheus metrics for apis. Just like http://xxxx:8888/metrics

Describe your ideal solution

add a middleware for metric

Version

No response

Additional Context

No response

muhlemmer commented 5 months ago

You can add your own middleware using options:

https://pkg.go.dev/github.com/zitadel/oidc/v3/pkg/op#WithHTTPMiddleware

We already have OpenTelemetry included in the package for metrics. If you define a tracer in your main package and pass the context, you should get metrics out of the OIDC package.

muhlemmer commented 4 months ago

It is also possible to configure OTEL to export to prometheus using this package: https://pkg.go.dev/go.opentelemetry.io/otel/exporters/prometheus

All the base infrastructure is already present in OIDC. The package consumer needs to setup otel with the desired exporter, in this case prometheus. Such setup is not in the scope of the OIDC library. Therefore I will now close this issue.