Skip to content

Commit

Permalink
feat(js-sdk): Enhance Open Telemetry in JS SDK (#423)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmyjames authored Oct 3, 2024
2 parents 8509dbe + 4a88fca commit 153a2b6
Show file tree
Hide file tree
Showing 26 changed files with 926 additions and 188 deletions.
12 changes: 12 additions & 0 deletions config/clients/js/CHANGELOG.md.mustache
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## v0.7.0

### [0.7.0](https://github.com/openfga/js-sdk/compare/v0.6.3...v0.7.0) (2024-08-30)

- feat!: enhancements to OpenTelemetry support (#149)

BREAKING CHANGE:

This version changes the way in which telemetry is configured and reported. See #149 for additional information.

## v0.6.3

### [0.6.3](https://{{gitHost}}/{{gitUserId}}/{{gitRepoId}}/compare/v0.6.2...v0.6.3) (2024-08-28)

- fix: set the consistency parameter correctly in OpenFgaClient (#143)
Expand Down
42 changes: 39 additions & 3 deletions config/clients/js/config.overrides.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"sdkId": "js",
"gitRepoId": "js-sdk",
"packageName": "@openfga/sdk",
"packageVersion": "0.6.3",
"packageVersion": "0.7.0",
"packageDescription": "JavaScript and Node.js SDK for OpenFGA",
"packageDetailedDescription": "This is an autogenerated JavaScript SDK for OpenFGA. It provides a wrapper around the [OpenFGA API definition](https://openfga.dev/api), and includes TS typings.",
"npmRegistry": "https://registry.npmjs.org/",
Expand Down Expand Up @@ -42,6 +42,26 @@
"destinationFilename": "tests/helpers/default-config.ts",
"templateType": "SupportingFiles"
},
"tests/telemetry/attributes.test.ts.mustache": {
"destinationFilename": "tests/telemetry/attributes.test.ts",
"templateType": "SupportingFiles"
},
"tests/telemetry/configuration.test.ts.mustache": {
"destinationFilename": "tests/telemetry/configuration.test.ts",
"templateType": "SupportingFiles"
},
"tests/telemetry/counters.test.ts.mustache": {
"destinationFilename": "tests/telemetry/counters.test.ts",
"templateType": "SupportingFiles"
},
"tests/telemetry/histograms.test.ts.mustache": {
"destinationFilename": "tests/telemetry/histograms.test.ts",
"templateType": "SupportingFiles"
},
"tests/telemetry/metrics.test.ts.mustache": {
"destinationFilename": "tests/telemetry/metrics.test.ts",
"templateType": "SupportingFiles"
},
"utils/assert-never.ts.mustache": {
"destinationFilename": "utils/assert-never.ts",
"templateType": "SupportingFiles"
Expand Down Expand Up @@ -129,8 +149,24 @@
"templateType": "SupportingFiles"
},
".madgerc": {},
"telemetry.mustache": {
"destinationFilename": "telemetry.ts",
"telemetry/attributes.ts.mustache": {
"destinationFilename": "telemetry/attributes.ts",
"templateType": "SupportingFiles"
},
"telemetry/configuration.ts.mustache": {
"destinationFilename": "telemetry/configuration.ts",
"templateType": "SupportingFiles"
},
"telemetry/counters.ts.mustache": {
"destinationFilename": "telemetry/counters.ts",
"templateType": "SupportingFiles"
},
"telemetry/histograms.ts.mustache": {
"destinationFilename": "telemetry/histograms.ts",
"templateType": "SupportingFiles"
},
"telemetry/metrics.ts.mustache": {
"destinationFilename": "telemetry/metrics.ts",
"templateType": "SupportingFiles"
},
"docs/opentelemetry.md.mustache": {
Expand Down
119 changes: 66 additions & 53 deletions config/clients/js/patches/add-method-specific-attributes.patch
Original file line number Diff line number Diff line change
@@ -1,125 +1,138 @@
diff --git a/api.ts b/api.ts
index e45e6c2..260e0bc 100644
index 9e91ac6..c080806 100644
--- a/api.ts
+++ b/api.ts
@@ -759,6 +759,9 @@ export const OpenFgaApiFp = function(configuration: Configuration, credentials:
@@ -760,6 +760,9 @@ export const OpenFgaApiFp = function(configuration: Configuration, credentials:
const localVarAxiosArgs = localVarAxiosParamCreator.check(storeId, body, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, configuration, credentials, {
[attributeNames.requestMethod]: "check",
+ [attributeNames.requestStoreId]: storeId,
+ [attributeNames.requestModelId]: body.authorization_model_id,
+ [attributeNames.user]: body.tuple_key.user
[TelemetryAttribute.FgaClientRequestMethod]: "Check",
+ [TelemetryAttribute.FgaClientRequestStoreId]: storeId ?? "",
+ [TelemetryAttribute.FgaClientRequestModelId]: body.authorization_model_id ?? "",
+ [TelemetryAttribute.FgaClientUser]: body.tuple_key.user
});
},
/**
@@ -785,6 +788,7 @@ export const OpenFgaApiFp = function(configuration: Configuration, credentials:
@@ -786,6 +789,7 @@ export const OpenFgaApiFp = function(configuration: Configuration, credentials:
const localVarAxiosArgs = localVarAxiosParamCreator.deleteStore(storeId, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, configuration, credentials, {
[attributeNames.requestMethod]: "deleteStore",
+ [attributeNames.requestStoreId]: storeId,
[TelemetryAttribute.FgaClientRequestMethod]: "DeleteStore",
+ [TelemetryAttribute.FgaClientRequestStoreId]: storeId,
});
},
/**
@@ -799,6 +803,8 @@ export const OpenFgaApiFp = function(configuration: Configuration, credentials:
@@ -800,6 +804,8 @@ export const OpenFgaApiFp = function(configuration: Configuration, credentials:
const localVarAxiosArgs = localVarAxiosParamCreator.expand(storeId, body, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, configuration, credentials, {
[attributeNames.requestMethod]: "expand",
+ [attributeNames.requestModelId]: body.authorization_model_id,
+ [attributeNames.requestStoreId]: storeId,
[TelemetryAttribute.FgaClientRequestMethod]: "Expand",
+ [TelemetryAttribute.FgaClientRequestModelId]: body.authorization_model_id ?? "",
+ [TelemetryAttribute.FgaClientRequestStoreId]: storeId ?? "",
});
},
/**
@@ -812,6 +818,7 @@ export const OpenFgaApiFp = function(configuration: Configuration, credentials:
@@ -813,6 +819,7 @@ export const OpenFgaApiFp = function(configuration: Configuration, credentials:
const localVarAxiosArgs = localVarAxiosParamCreator.getStore(storeId, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, configuration, credentials, {
[attributeNames.requestMethod]: "getStore",
+ [attributeNames.requestStoreId]: storeId,
[TelemetryAttribute.FgaClientRequestMethod]: "GetStore",
+ [TelemetryAttribute.FgaClientRequestStoreId]: storeId,
});
},
/**
@@ -826,6 +833,9 @@ export const OpenFgaApiFp = function(configuration: Configuration, credentials:
@@ -827,10 +834,13 @@ export const OpenFgaApiFp = function(configuration: Configuration, credentials:
const localVarAxiosArgs = localVarAxiosParamCreator.listObjects(storeId, body, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, configuration, credentials, {
[attributeNames.requestMethod]: "listObjects",
+ [attributeNames.requestStoreId]: storeId,
+ [attributeNames.requestModelId]: body.authorization_model_id,
+ [attributeNames.user]: body.user
[TelemetryAttribute.FgaClientRequestMethod]: "ListObjects",
+ [TelemetryAttribute.FgaClientRequestStoreId]: storeId ?? "",
+ [TelemetryAttribute.FgaClientRequestModelId]: body.authorization_model_id ?? "",
+ [TelemetryAttribute.FgaClientUser]: body.user
});
},
/**
@@ -854,6 +864,8 @@ export const OpenFgaApiFp = function(configuration: Configuration, credentials:
- * Returns a paginated list of OpenFGA stores and a continuation token to get additional stores. The continuation token will be empty if there are no more stores.
+ * Returns a paginated list of OpenFGA stores and a continuation token to get additional stores. The continuation token will be empty if there are no more stores.
* @summary List all stores
* @param {number} [pageSize]
* @param {string} [continuationToken]
@@ -855,6 +865,8 @@ export const OpenFgaApiFp = function(configuration: Configuration, credentials:
const localVarAxiosArgs = localVarAxiosParamCreator.listUsers(storeId, body, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, configuration, credentials, {
[attributeNames.requestMethod]: "listUsers",
+ [attributeNames.requestStoreId]: storeId,
+ [attributeNames.requestModelId]: body.authorization_model_id,
[TelemetryAttribute.FgaClientRequestMethod]: "ListUsers",
+ [TelemetryAttribute.FgaClientRequestStoreId]: storeId ?? "",
+ [TelemetryAttribute.FgaClientRequestModelId]: body.authorization_model_id ?? "",
});
},
/**
@@ -868,6 +880,7 @@ export const OpenFgaApiFp = function(configuration: Configuration, credentials:
@@ -869,10 +881,11 @@ export const OpenFgaApiFp = function(configuration: Configuration, credentials:
const localVarAxiosArgs = localVarAxiosParamCreator.read(storeId, body, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, configuration, credentials, {
[attributeNames.requestMethod]: "read",
+ [attributeNames.requestStoreId]: storeId,
[TelemetryAttribute.FgaClientRequestMethod]: "Read",
+ [TelemetryAttribute.FgaClientRequestStoreId]: storeId,
});
},
/**
@@ -882,6 +895,8 @@ export const OpenFgaApiFp = function(configuration: Configuration, credentials:
- * The ReadAssertions API will return, for a given authorization model id, all the assertions stored for it. An assertion is an object that contains a tuple key, and the expectation of whether a call to the Check API of that tuple key will return true or false.
+ * The ReadAssertions API will return, for a given authorization model id, all the assertions stored for it. An assertion is an object that contains a tuple key, and the expectation of whether a call to the Check API of that tuple key will return true or false.
* @summary Read assertions for an authorization model ID
* @param {string} storeId
* @param {string} authorizationModelId
@@ -883,6 +896,8 @@ export const OpenFgaApiFp = function(configuration: Configuration, credentials:
const localVarAxiosArgs = localVarAxiosParamCreator.readAssertions(storeId, authorizationModelId, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, configuration, credentials, {
[attributeNames.requestMethod]: "readAssertions",
+ [attributeNames.requestStoreId]: storeId,
+ [attributeNames.requestModelId]: authorizationModelId,
[TelemetryAttribute.FgaClientRequestMethod]: "ReadAssertions",
+ [TelemetryAttribute.FgaClientRequestStoreId]: storeId,
+ [TelemetryAttribute.FgaClientRequestModelId]: authorizationModelId,
});
},
/**
@@ -896,6 +911,7 @@ export const OpenFgaApiFp = function(configuration: Configuration, credentials:
@@ -897,6 +912,7 @@ export const OpenFgaApiFp = function(configuration: Configuration, credentials:
const localVarAxiosArgs = localVarAxiosParamCreator.readAuthorizationModel(storeId, id, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, configuration, credentials, {
[attributeNames.requestMethod]: "readAuthorizationModel",
+ [attributeNames.requestStoreId]: storeId,
[TelemetryAttribute.FgaClientRequestMethod]: "ReadAuthorizationModel",
+ [TelemetryAttribute.FgaClientRequestStoreId]: storeId,
});
},
/**
@@ -911,6 +927,7 @@ export const OpenFgaApiFp = function(configuration: Configuration, credentials:
@@ -912,6 +928,7 @@ export const OpenFgaApiFp = function(configuration: Configuration, credentials:
const localVarAxiosArgs = localVarAxiosParamCreator.readAuthorizationModels(storeId, pageSize, continuationToken, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, configuration, credentials, {
[attributeNames.requestMethod]: "readAuthorizationModels",
+ [attributeNames.requestStoreId]: storeId,
[TelemetryAttribute.FgaClientRequestMethod]: "ReadAuthorizationModels",
+ [TelemetryAttribute.FgaClientRequestStoreId]: storeId,
});
},
/**
@@ -927,6 +944,7 @@ export const OpenFgaApiFp = function(configuration: Configuration, credentials:
@@ -928,6 +945,7 @@ export const OpenFgaApiFp = function(configuration: Configuration, credentials:
const localVarAxiosArgs = localVarAxiosParamCreator.readChanges(storeId, type, pageSize, continuationToken, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, configuration, credentials, {
[attributeNames.requestMethod]: "readChanges",
+ [attributeNames.requestStoreId]: storeId,
[TelemetryAttribute.FgaClientRequestMethod]: "ReadChanges",
+ [TelemetryAttribute.FgaClientRequestStoreId]: storeId,
});
},
/**
@@ -941,6 +959,8 @@ export const OpenFgaApiFp = function(configuration: Configuration, credentials:
@@ -942,6 +960,8 @@ export const OpenFgaApiFp = function(configuration: Configuration, credentials:
const localVarAxiosArgs = localVarAxiosParamCreator.write(storeId, body, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, configuration, credentials, {
[attributeNames.requestMethod]: "write",
+ [attributeNames.requestStoreId]: storeId,
+ [attributeNames.requestModelId]: body.authorization_model_id,
[TelemetryAttribute.FgaClientRequestMethod]: "Write",
+ [TelemetryAttribute.FgaClientRequestStoreId]: storeId ?? "",
+ [TelemetryAttribute.FgaClientRequestModelId]: body.authorization_model_id ?? "",
});
},
/**
@@ -956,6 +976,8 @@ export const OpenFgaApiFp = function(configuration: Configuration, credentials:
@@ -957,6 +977,8 @@ export const OpenFgaApiFp = function(configuration: Configuration, credentials:
const localVarAxiosArgs = localVarAxiosParamCreator.writeAssertions(storeId, authorizationModelId, body, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, configuration, credentials, {
[attributeNames.requestMethod]: "writeAssertions",
+ [attributeNames.requestStoreId]: storeId,
+ [attributeNames.requestModelId]: authorizationModelId,
[TelemetryAttribute.FgaClientRequestMethod]: "WriteAssertions",
+ [TelemetryAttribute.FgaClientRequestStoreId]: storeId,
+ [TelemetryAttribute.FgaClientRequestModelId]: authorizationModelId,
});
},
/**
@@ -970,6 +992,7 @@ export const OpenFgaApiFp = function(configuration: Configuration, credentials:
@@ -971,6 +993,7 @@ export const OpenFgaApiFp = function(configuration: Configuration, credentials:
const localVarAxiosArgs = localVarAxiosParamCreator.writeAuthorizationModel(storeId, body, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, configuration, credentials, {
[attributeNames.requestMethod]: "writeAuthorizationModel",
+ [attributeNames.requestStoreId]: storeId,
[TelemetryAttribute.FgaClientRequestMethod]: "WriteAuthorizationModel",
+ [TelemetryAttribute.FgaClientRequestStoreId]: storeId,
});
},
};
};
@@ -1380,4 +1403,3 @@ export class OpenFgaApi extends BaseAPI {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
fetch-depth: 0

- name: Set up node
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4
with:
node-version: ${{ matrix.node-version }}
registry-url: "https://registry.npmjs.org"
Expand All @@ -47,7 +47,7 @@ jobs:
fetch-depth: 0

- name: Set up node
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4
with:
node-version: 20
cache: "npm"
Expand Down Expand Up @@ -86,7 +86,7 @@ jobs:
fetch-depth: 0

- name: Set up node
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4
with:
node-version: 20
registry-url: "https://registry.npmjs.org"
Expand Down
2 changes: 1 addition & 1 deletion config/clients/js/template/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
CallResult,
PromiseResult
} from './common';
import { attributeNames } from "./telemetry";
import { Configuration } from './configuration';
import { Credentials } from "./credentials";
import { assertParamExists } from './validation';
Expand All @@ -24,6 +23,7 @@ import {
{{#model}}{{classname}},{{/model}}
{{/models}}
} from './apiModel';
import { TelemetryAttribute, TelemetryAttributes } from "./telemetry/attributes";

{{#apiInfo}}{{#apis}}
{{>apiInner}}
Expand Down
2 changes: 1 addition & 1 deletion config/clients/js/template/apiInner.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export const {{classname}}Fp = function(configuration: Configuration, credential
async {{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}options?: any): Promise<(axios?: AxiosInstance) => PromiseResult<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}>> {
const localVarAxiosArgs = localVarAxiosParamCreator.{{nickname}}({{#allParams}}{{paramName}}, {{/allParams}}options);
return createRequestFunction(localVarAxiosArgs, globalAxios, configuration, credentials, {
[attributeNames.requestMethod]: "{{nickname}}",
[TelemetryAttribute.FgaClientRequestMethod]: "{{operationIdCamelCase}}",
});
},
{{/operation}}
Expand Down
Loading

0 comments on commit 153a2b6

Please sign in to comment.