Skip to content

Commit 25b2c7d

Browse files
authoredFeb 18, 2025··
feat: add batch check telemetry attribute (#143)
* feat: add batch check attribute * add docs * fix docs typo * lint fix * add test for batch check telemetry is off by default * docs formatting cleanup
1 parent f487f6c commit 25b2c7d

File tree

4 files changed

+39
-16
lines changed

4 files changed

+39
-16
lines changed
 

‎docs/OpenTelemetry.md

+17-16
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,22 @@ In cases when metrics events are sent, they will not be viewable outside of infr
1818

1919
### Supported Attributes
2020

21-
| Attribute Name | Type | Enabled by Default | Description |
22-
| ------------------------------ | ------ | ------------------ | --------------------------------------------------------------------------------- |
23-
| `fga-client.request.client_id` | string | Yes | Client ID associated with the request, if any |
24-
| `fga-client.request.method` | string | Yes | FGA method/action that was performed (e.g., Check, ListObjects) in TitleCase |
25-
| `fga-client.request.model_id` | string | Yes | Authorization model ID that was sent as part of the request, if any |
26-
| `fga-client.request.store_id` | string | Yes | Store ID that was sent as part of the request |
27-
| `fga-client.response.model_id` | string | Yes | Authorization model ID that the FGA server used |
28-
| `fga-client.user` | string | No | User associated with the action of the request for check and list users |
29-
| `http.host` | string | Yes | Host identifier of the origin the request was sent to |
30-
| `http.request.method` | string | Yes | HTTP method for the request |
31-
| `http.request.resend_count` | int | Yes | Number of retries attempted, if any |
32-
| `http.response.status_code` | int | Yes | Status code of the response (e.g., `200` for success) |
33-
| `url.scheme` | string | Yes | HTTP scheme of the request (`http`/`https`) |
34-
| `url.full` | string | Yes | Full URL of the request |
35-
| `user_agent.original` | string | Yes | User Agent used in the query |
21+
| Attribute Name | Type | Enabled by Default | Description |
22+
|---------------------------------------|--------|--------------------|------------------------------------------------------------------------------|
23+
| `fga-client.request.client_id` | string | Yes | Client ID associated with the request, if any |
24+
| `fga-client.request.method` | string | Yes | FGA method/action that was performed (e.g., Check, ListObjects) in TitleCase |
25+
| `fga-client.request.model_id` | string | Yes | Authorization model ID that was sent as part of the request, if any |
26+
| `fga-client.request.store_id` | string | Yes | Store ID that was sent as part of the request |
27+
| `fga-client.request.batch_check_size` | int | No | Number of objects in the batch check request |
28+
| `fga-client.response.model_id` | string | Yes | Authorization model ID that the FGA server used |
29+
| `fga-client.user` | string | No | User associated with the action of the request for check and list users |
30+
| `http.host` | string | Yes | Host identifier of the origin the request was sent to |
31+
| `http.request.method` | string | Yes | HTTP method for the request |
32+
| `http.request.resend_count` | int | Yes | Number of retries attempted, if any |
33+
| `http.response.status_code` | int | Yes | Status code of the response (e.g., `200` for success) |
34+
| `url.scheme` | string | Yes | HTTP scheme of the request (`http`/`https`) |
35+
| `url.full` | string | Yes | Full URL of the request |
36+
| `user_agent.original` | string | Yes | User Agent used in the query |
3637

3738
## Examples
3839

@@ -176,4 +177,4 @@ public class Example {
176177
otel = openTelemetry;
177178
}
178179
}
179-
```
180+
```

‎src/main/java/dev/openfga/sdk/api/OpenFgaApi.java

+10
Original file line numberDiff line numberDiff line change
@@ -1149,6 +1149,16 @@ private Map<Attribute, String> buildTelemetryAttributes(Map<String, Object> attr
11491149
Attributes.FGA_CLIENT_REQUEST_MODEL_ID, writeRequest.getAuthorizationModelId());
11501150
}
11511151
}
1152+
1153+
if (body instanceof BatchCheckRequest) {
1154+
BatchCheckRequest batchCheckRequest = (BatchCheckRequest) body;
1155+
1156+
if (batchCheckRequest.getChecks() != null) {
1157+
telemetryAttributes.put(
1158+
Attributes.FGA_CLIENT_REQUEST_BATCH_CHECK_SIZE,
1159+
String.valueOf(batchCheckRequest.getChecks().size()));
1160+
}
1161+
}
11521162
}
11531163

11541164
return telemetryAttributes;

‎src/main/java/dev/openfga/sdk/telemetry/Attributes.java

+6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ public class Attributes {
3838
*/
3939
public static final Attribute FGA_CLIENT_REQUEST_STORE_ID = new Attribute("fga-client.request.store_id");
4040

41+
/**
42+
* The number of items to check in a batch request, if applicable.
43+
*/
44+
public static final Attribute FGA_CLIENT_REQUEST_BATCH_CHECK_SIZE =
45+
new Attribute("fga-client.request.batch_check_size");
46+
4147
/**
4248
* The authorization model ID used by the server when evaluating the request, if applicable.
4349
*/

‎src/test/java/dev/openfga/sdk/api/configuration/TelemetryConfigurationTest.java

+6
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ void testDefaultMetrics() {
8787
assertTrue(
8888
defaultAttributes.containsKey(Attributes.USER_AGENT),
8989
"The default attributes map should contain the USER_AGENT attribute.");
90+
assertFalse(
91+
defaultAttributes.containsKey(Attributes.FGA_CLIENT_REQUEST_BATCH_CHECK_SIZE),
92+
"The default attribute map should not contain the FGA_CLIENT_REQUEST_BATCH_CHECK_SIZE attribute.");
9093

9194
defaultAttributes = metrics.get(Histograms.QUERY_DURATION);
9295
assertNotNull(defaultAttributes, "The default attributes map should not be null.");
@@ -124,6 +127,9 @@ void testDefaultMetrics() {
124127
assertTrue(
125128
defaultAttributes.containsKey(Attributes.USER_AGENT),
126129
"The default attributes map should contain the USER_AGENT attribute.");
130+
assertFalse(
131+
defaultAttributes.containsKey(Attributes.FGA_CLIENT_REQUEST_BATCH_CHECK_SIZE),
132+
"The default attribute map should not contain the FGA_CLIENT_REQUEST_BATCH_CHECK_SIZE attribute.");
127133
}
128134

129135
@Test

0 commit comments

Comments
 (0)
Please sign in to comment.