@openfga/sdk
Advanced tools
Comparing version 0.5.0 to 0.6.0
# Changelog | ||
## v0.6.0 | ||
### [0.6.0](https://github.com/openfga/js-sdk/compare/v0.5.0...v0.6.0) (2024-06-28) | ||
- feat: add opentelemetry metrics reporting (#117) | ||
## v0.5.0 | ||
@@ -4,0 +9,0 @@ |
@@ -61,3 +61,3 @@ /** | ||
*/ | ||
export declare const createRequestFunction: (axiosArgs: RequestArgs, axiosInstance: AxiosInstance, configuration: Configuration, credentials: Credentials) => (axios?: AxiosInstance) => PromiseResult<any>; | ||
export declare const createRequestFunction: (axiosArgs: RequestArgs, axiosInstance: AxiosInstance, configuration: Configuration, credentials: Credentials, methodAttributes?: Record<string, unknown>) => (axios?: AxiosInstance) => PromiseResult<any>; | ||
export {}; |
@@ -23,5 +23,17 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createRequestFunction = exports.attemptHttpRequest = exports.toPathString = exports.serializeDataIfNeeded = exports.setSearchParams = exports.setBearerAuthToObject = exports.DUMMY_BASE_URL = void 0; | ||
exports.createRequestFunction = exports.toPathString = exports.serializeDataIfNeeded = exports.setSearchParams = exports.setBearerAuthToObject = exports.DUMMY_BASE_URL = void 0; | ||
exports.attemptHttpRequest = attemptHttpRequest; | ||
const api_1 = require("@opentelemetry/api"); | ||
const errors_1 = require("./errors"); | ||
const utils_1 = require("./utils"); | ||
const telemetry_1 = require("./telemetry"); | ||
const meter = api_1.metrics.getMeter("@openfga/sdk", "0.6.0"); | ||
const durationHist = meter.createHistogram("fga-client.request.duration", { | ||
description: "The duration of requests", | ||
unit: "milliseconds", | ||
}); | ||
const queryDurationHist = meter.createHistogram("fga-client.query.duration", { | ||
description: "The duration of queries on the FGA server", | ||
unit: "milliseconds", | ||
}); | ||
/** | ||
@@ -160,7 +172,6 @@ * | ||
} | ||
exports.attemptHttpRequest = attemptHttpRequest; | ||
/** | ||
* creates an axios request function | ||
*/ | ||
const createRequestFunction = function (axiosArgs, axiosInstance, configuration, credentials) { | ||
const createRequestFunction = function (axiosArgs, axiosInstance, configuration, credentials, methodAttributes = {}) { | ||
var _a, _b; | ||
@@ -171,2 +182,3 @@ configuration.isValid(); | ||
const minWaitInMs = retryParams ? retryParams.minWaitInMs : 0; | ||
const start = Date.now(); | ||
return (...args_1) => __awaiter(this, [...args_1], void 0, function* (axios = axiosInstance) { | ||
@@ -179,5 +191,14 @@ yield (0, exports.setBearerAuthToObject)(axiosArgs.options.headers, credentials); | ||
}, axios); | ||
const executionTime = Date.now() - start; | ||
const data = typeof (response === null || response === void 0 ? void 0 : response.data) === "undefined" ? {} : response === null || response === void 0 ? void 0 : response.data; | ||
const result = Object.assign({}, data); | ||
(0, utils_1.setNotEnumerableProperty)(result, "$response", response); | ||
const attributes = (0, telemetry_1.buildAttributes)(response, configuration.credentials, methodAttributes); | ||
if (response === null || response === void 0 ? void 0 : response.headers) { | ||
const duration = response.headers["fga-query-duration-ms"]; | ||
if (duration !== undefined) { | ||
queryDurationHist.record(parseInt(duration, 10), attributes); | ||
} | ||
} | ||
durationHist.record(executionTime, attributes); | ||
return result; | ||
@@ -184,0 +205,0 @@ }); |
@@ -14,3 +14,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Configuration = exports.GetDefaultRetryParams = void 0; | ||
exports.Configuration = void 0; | ||
exports.GetDefaultRetryParams = GetDefaultRetryParams; | ||
const types_1 = require("./credentials/types"); | ||
@@ -23,3 +24,3 @@ const errors_1 = require("./errors"); | ||
const DEFAULT_MIN_WAIT_MS = 100; | ||
const DEFAULT_USER_AGENT = "openfga-sdk js/0.5.0"; | ||
const DEFAULT_USER_AGENT = "openfga-sdk js/0.6.0"; | ||
function GetDefaultRetryParams(maxRetry = DEFAULT_MAX_RETRY, minWaitInMs = DEFAULT_MIN_WAIT_MS) { | ||
@@ -31,3 +32,2 @@ return { | ||
} | ||
exports.GetDefaultRetryParams = GetDefaultRetryParams; | ||
class Configuration { | ||
@@ -126,2 +126,2 @@ constructor(params = {}) { | ||
*/ | ||
Configuration.sdkVersion = "0.5.0"; | ||
Configuration.sdkVersion = "0.6.0"; |
@@ -19,2 +19,3 @@ /** | ||
private accessTokenExpiryDate?; | ||
private tokenCounter?; | ||
static init(configuration: { | ||
@@ -21,0 +22,0 @@ credentials: AuthCredentialsConfig; |
@@ -28,3 +28,5 @@ "use strict"; | ||
const common_1 = require("../common"); | ||
const telemetry_1 = require("../telemetry"); | ||
const types_1 = require("./types"); | ||
const api_1 = require("@opentelemetry/api"); | ||
class Credentials { | ||
@@ -57,3 +59,7 @@ static init(configuration) { | ||
break; | ||
case types_1.CredentialsMethod.ClientCredentials: | ||
case types_1.CredentialsMethod.ClientCredentials: { | ||
const meter = api_1.metrics.getMeter("@openfga/sdk", "0.6.0"); | ||
this.tokenCounter = meter.createCounter("fga-client.credentials.request"); | ||
break; | ||
} | ||
case types_1.CredentialsMethod.None: | ||
@@ -136,3 +142,3 @@ default: | ||
return __awaiter(this, void 0, void 0, function* () { | ||
var _a; | ||
var _a, _b; | ||
const clientCredentials = (_a = this.authConfig) === null || _a === void 0 ? void 0 : _a.config; | ||
@@ -160,2 +166,3 @@ try { | ||
} | ||
(_b = this.tokenCounter) === null || _b === void 0 ? void 0 : _b.add(1, (0, telemetry_1.buildAttributes)(response, this.authConfig)); | ||
return this.accessToken; | ||
@@ -162,0 +169,0 @@ } |
@@ -14,6 +14,5 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.assertNever = void 0; | ||
exports.assertNever = assertNever; | ||
function assertNever(value) { | ||
throw new Error(`Assertion failed. Unacceptable value: '${value}'`); | ||
} | ||
exports.assertNever = assertNever; |
@@ -14,3 +14,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.chunkArray = void 0; | ||
exports.chunkArray = chunkArray; | ||
function chunkArray(inputArray, maxChunkSize) { | ||
@@ -24,2 +24,1 @@ const arrayOfArrays = []; | ||
} | ||
exports.chunkArray = chunkArray; |
@@ -14,3 +14,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.generateRandomIdWithNonUniqueFallback = exports.generateRandomId = void 0; | ||
exports.generateRandomId = generateRandomId; | ||
exports.generateRandomIdWithNonUniqueFallback = generateRandomIdWithNonUniqueFallback; | ||
const crypto_1 = require("crypto"); | ||
@@ -33,6 +34,4 @@ /** | ||
} | ||
exports.generateRandomId = generateRandomId; | ||
function generateRandomIdWithNonUniqueFallback() { | ||
return generateRandomId() || "00000000-0000-0000-0000-000000000000"; | ||
} | ||
exports.generateRandomIdWithNonUniqueFallback = generateRandomIdWithNonUniqueFallback; |
@@ -14,3 +14,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.setHeaderIfNotSet = void 0; | ||
exports.setHeaderIfNotSet = setHeaderIfNotSet; | ||
function setHeaderIfNotSet(headers, key, value) { | ||
@@ -21,2 +21,1 @@ if (!headers[key] && value) { | ||
} | ||
exports.setHeaderIfNotSet = setHeaderIfNotSet; |
@@ -14,3 +14,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.setNotEnumerableProperty = void 0; | ||
exports.setNotEnumerableProperty = setNotEnumerableProperty; | ||
function setNotEnumerableProperty(entity, property, value) { | ||
@@ -23,2 +23,1 @@ Object.defineProperty(entity, property, { | ||
} | ||
exports.setNotEnumerableProperty = setNotEnumerableProperty; |
{ | ||
"name": "@openfga/sdk", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"description": "JavaScript and Node.js SDK for OpenFGA", | ||
@@ -25,2 +25,4 @@ "author": "OpenFGA", | ||
"dependencies": { | ||
"@opentelemetry/api": "^1.9.0", | ||
"@opentelemetry/semantic-conventions": "^1.25.0", | ||
"axios": "^1.6.8", | ||
@@ -27,0 +29,0 @@ "tiny-async-pool": "^2.1.0" |
@@ -48,2 +48,3 @@ # JavaScript and Node.js SDK for OpenFGA | ||
- [Models](#models) | ||
- [OpenTelemetry](#opentelemetry) | ||
- [Contributing](#contributing) | ||
@@ -715,2 +716,6 @@ - [Issues](#issues) | ||
### 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/js-sdk/blob/main/docs/opentelemetry.md) | ||
## Contributing | ||
@@ -717,0 +722,0 @@ |
Sorry, the diff of this file is too big to display
1418969
43
6952
738
4
+ Added@opentelemetry/api@^1.9.0
+ Added@opentelemetry/api@1.9.0(transitive)
+ Added@opentelemetry/semantic-conventions@1.30.0(transitive)