openfga / python-sdk

OpenFGA SDK for Python 3 - https://pypi.org/project/openfga-sdk/
https://openfga.dev
Apache License 2.0
38 stars 15 forks source link

Export metrics #93

Closed rhamzeh closed 4 months ago

rhamzeh commented 5 months ago

Checklist

Describe the problem you'd like to have solved

As a consumer of the SDK, I would like to hook it to my dashboards to get data on several metrics.

Describe the ideal solution

Integrate the OpenTelemetry Python API https://github.com/open-telemetry/opentelemetry-python/tree/main/opentelemetry-api (API docs)

Expose only from the inner OpenFgaApi. We need to be able to report the following metrics

Metric Name Type Description
fga-client.request.duration Histogram The total request time for FGA requests
fga-client.query.duration Histogram The amount of time the FGA server took to process the request
fga-client.credentials.request Counter The total number of times a new token was requested when using ClientCredentials

And the metrics should have the following attributes associated with them

Attribute Name Type Description
fga-client.response.model_id string The authorization model ID that the FGA server used
fga-client.request.method string The FGA method/action that was performed
fga-client.request.store_id string The store ID that was sent as part of the request
fga-client.request.model_id string The authorization model ID that was sent as part of the request, if any
fga-client.request.client_id string The client ID associated with the request, if any
fga-client.user string The user that is associated with the action of the request for check and list users
http.status_code int The status code of the response
http.method string The HTTP method for the request
http.host string Host identifier of the origin the request was sent to

We should create an overall meter for OpenFgaApi and then create counters, histograms as required for each metric we report.

For the semantically named attributes we can use the semantic conventions package https://pypi.org/project/opentelemetry-semantic-conventions/