diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ef40ef..d275a60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## v0.6.0 + +### [0.6.0](https://github.com/openfga/python-sdk/compare/v0.5.0...v0.6.0) (2024-06-28) + +- feat: add OpenTelemetry metrics reporting + ## v0.5.0 ### [0.5.0](https://github.com/openfga/python-sdk/compare/v0.4.2...v0.5.0) (2024-06-17) diff --git a/README.md b/README.md index e247c02..db4ceaf 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ This is an autogenerated python SDK for OpenFGA. It provides a wrapper around th - [Retries](#retries) - [API Endpoints](#api-endpoints) - [Models](#models) + - [OpenTelemetry](#opentelemetry) - [Contributing](#contributing) - [Issues](#issues) - [Pull Requests](#pull-requests) @@ -1139,6 +1140,12 @@ Class | Method | HTTP request | Description +### OpenTelemetry + +This SDK supports producing metrics that can be consumed as part of an [OpenTelemetry](https://opentelemetry.io/) setup. For more information, please see [the documentation](https://github.com/openfga/python-sdk/blob/main/docs/opentelemetry.md) + + + ## Contributing ### Issues diff --git a/docs/opentelemetry.md b/docs/opentelemetry.md new file mode 100644 index 0000000..ce32858 --- /dev/null +++ b/docs/opentelemetry.md @@ -0,0 +1,31 @@ +# OpenTelemetry + +This SDK produces [metrics](https://opentelemetry.io/docs/concepts/signals/metrics/) using [OpenTelemetry](https://opentelemetry.io/) that allow you to view data such as request timings. These metrics also include attributes for the model and store ID, as well as the API called to allow you to build reporting. + +When an OpenTelemetry SDK instance is configured, the metrics will be exported and sent to the collector configured as part of your applications configuration. If you are not using OpenTelemetry, the metric functionality is a no-op and the events are never sent. + +In cases when metrics events are sent, they will not be viewable outside of infrastructure configured in your application, and are never available to the OpenFGA team or contributors. + +## Metrics + +### Supported 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 | + +### Supported attributes + +| 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 | diff --git a/example/example1/requirements.txt b/example/example1/requirements.txt index 29a08b0..a6ad6a8 100644 --- a/example/example1/requirements.txt +++ b/example/example1/requirements.txt @@ -4,7 +4,7 @@ attrs >= 23.1.0 frozenlist >= 1.4.1 idna >= 3.6 multidict >= 6.0.4 -openfga-sdk >= 0.5.0 +openfga-sdk >= 0.6.0 python-dateutil >= 2.8.2 urllib3 >= 2.1.0 yarl >= 1.9.4 diff --git a/openfga_sdk/__init__.py b/openfga_sdk/__init__.py index d0e5831..0665bd2 100644 --- a/openfga_sdk/__init__.py +++ b/openfga_sdk/__init__.py @@ -10,7 +10,7 @@ NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. """ -__version__ = "0.5.0" +__version__ = "0.6.0" from openfga_sdk.api.open_fga_api import OpenFgaApi from openfga_sdk.api_client import ApiClient diff --git a/openfga_sdk/api_client.py b/openfga_sdk/api_client.py index d509e2d..5806d03 100644 --- a/openfga_sdk/api_client.py +++ b/openfga_sdk/api_client.py @@ -36,7 +36,7 @@ from openfga_sdk.telemetry import Telemetry from openfga_sdk.telemetry.attributes import TelemetryAttribute, TelemetryAttributes -DEFAULT_USER_AGENT = "openfga-sdk python/0.5.0" +DEFAULT_USER_AGENT = "openfga-sdk python/0.6.0" def random_time(loop_count, min_wait_in_ms): diff --git a/openfga_sdk/configuration.py b/openfga_sdk/configuration.py index f37cd25..8f1e3f1 100644 --- a/openfga_sdk/configuration.py +++ b/openfga_sdk/configuration.py @@ -469,7 +469,7 @@ def to_debug_report(self): "OS: {env}\n" "Python Version: {pyversion}\n" "Version of the API: 1.x\n" - "SDK Package Version: 0.5.0".format(env=sys.platform, pyversion=sys.version) + "SDK Package Version: 0.6.0".format(env=sys.platform, pyversion=sys.version) ) def get_host_settings(self): diff --git a/openfga_sdk/oauth2.py b/openfga_sdk/oauth2.py index 6a4dad7..b2b8c5e 100644 --- a/openfga_sdk/oauth2.py +++ b/openfga_sdk/oauth2.py @@ -83,7 +83,7 @@ async def _obtain_token(self, client): { "Accept": "application/json", "Content-Type": "application/x-www-form-urlencoded", - "User-Agent": "openfga-sdk (python) 0.5.0", + "User-Agent": "openfga-sdk (python) 0.6.0", } ) diff --git a/openfga_sdk/sync/api_client.py b/openfga_sdk/sync/api_client.py index 9745ee5..03e4b89 100644 --- a/openfga_sdk/sync/api_client.py +++ b/openfga_sdk/sync/api_client.py @@ -35,7 +35,7 @@ from openfga_sdk.telemetry import Telemetry from openfga_sdk.telemetry.attributes import TelemetryAttribute, TelemetryAttributes -DEFAULT_USER_AGENT = "openfga-sdk python/0.5.0" +DEFAULT_USER_AGENT = "openfga-sdk python/0.6.0" def random_time(loop_count, min_wait_in_ms): diff --git a/openfga_sdk/sync/oauth2.py b/openfga_sdk/sync/oauth2.py index cdecd99..7dce8f7 100644 --- a/openfga_sdk/sync/oauth2.py +++ b/openfga_sdk/sync/oauth2.py @@ -83,7 +83,7 @@ def _obtain_token(self, client): { "Accept": "application/json", "Content-Type": "application/x-www-form-urlencoded", - "User-Agent": "openfga-sdk (python) 0.5.0", + "User-Agent": "openfga-sdk (python) 0.6.0", } ) diff --git a/setup.py b/setup.py index 489f085..324aa53 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ import setuptools NAME = "openfga-sdk" -VERSION = "0.5.0" +VERSION = "0.6.0" REQUIRES = [] diff --git a/test/test_oauth2.py b/test/test_oauth2.py index 9acc235..4ecbd16 100644 --- a/test/test_oauth2.py +++ b/test/test_oauth2.py @@ -84,7 +84,7 @@ async def test_get_authentication_obtain_client_credentials(self, mock_request): { "Accept": "application/json", "Content-Type": "application/x-www-form-urlencoded", - "User-Agent": "openfga-sdk (python) 0.5.0", + "User-Agent": "openfga-sdk (python) 0.6.0", } ) mock_request.assert_called_once_with( diff --git a/test/test_oauth2_sync.py b/test/test_oauth2_sync.py index 2799c15..4dd4380 100644 --- a/test/test_oauth2_sync.py +++ b/test/test_oauth2_sync.py @@ -84,7 +84,7 @@ def test_get_authentication_obtain_client_credentials(self, mock_request): { "Accept": "application/json", "Content-Type": "application/x-www-form-urlencoded", - "User-Agent": "openfga-sdk (python) 0.5.0", + "User-Agent": "openfga-sdk (python) 0.6.0", } ) mock_request.assert_called_once_with( diff --git a/test/test_open_fga_api.py b/test/test_open_fga_api.py index f39eca0..a84df4e 100644 --- a/test/test_open_fga_api.py +++ b/test/test_open_fga_api.py @@ -1520,7 +1520,7 @@ async def test_check_api_token(self, mock_request): { "Accept": "application/json", "Content-Type": "application/json", - "User-Agent": "openfga-sdk python/0.5.0", + "User-Agent": "openfga-sdk python/0.6.0", "Authorization": "Bearer TOKEN1", } ) @@ -1574,7 +1574,7 @@ async def test_check_custom_header(self, mock_request): { "Accept": "application/json", "Content-Type": "application/json", - "User-Agent": "openfga-sdk python/0.5.0", + "User-Agent": "openfga-sdk python/0.6.0", "Custom Header": "custom value", } ) diff --git a/test/test_open_fga_api_sync.py b/test/test_open_fga_api_sync.py index 7fab633..d87b47e 100644 --- a/test/test_open_fga_api_sync.py +++ b/test/test_open_fga_api_sync.py @@ -1520,7 +1520,7 @@ async def test_check_api_token(self, mock_request): { "Accept": "application/json", "Content-Type": "application/json", - "User-Agent": "openfga-sdk python/0.5.0", + "User-Agent": "openfga-sdk python/0.6.0", "Authorization": "Bearer TOKEN1", } ) @@ -1574,7 +1574,7 @@ async def test_check_custom_header(self, mock_request): { "Accept": "application/json", "Content-Type": "application/json", - "User-Agent": "openfga-sdk python/0.5.0", + "User-Agent": "openfga-sdk python/0.6.0", "Custom Header": "custom value", } )