Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ test: install
npm test

format:
npm run prettier
npm run format

build: install
npm run build
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,20 @@ const chargebee = new Chargebee({

These examples demonstrate how to implement and inject custom clients using `axios` and `ky`, respectively.

### SDK telemetry

By default, the library sends anonymous usage telemetry to Chargebee. This helps us improve the SDK and API.

You can disable this behavior if you prefer:

```javascript
const chargebee = new Chargebee({
site: 'your-site',
apiKey: 'your-api-key',
sdkTelemetryEnabled: false,
});
```

### Telemetry (OpenTelemetry)

Optional. Pass a `telemetryAdapter` when you want Chargebee API calls traced in your observability stack (Datadog, Splunk, Honeycomb, Jaeger, etc.). The SDK ships a ready-to-use OpenTelemetry adapter, so for most setups you only need to add `@opentelemetry/api` and wire the adapter on the client.
Expand Down
26 changes: 26 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"$schema": "https://biomejs.dev/schemas/2.5.7/schema.json",
"files": {
"includes": ["src/**/*.ts", "types/**/*.d.ts"]
},
"formatter": {
"enabled": true,
"indentStyle": "space",
"indentWidth": 2,
"lineWidth": 80,
"lineEnding": "lf"
},
"javascript": {
"formatter": {
"quoteStyle": "single",
"semicolons": "always",
"trailingCommas": "all"
}
},
"linter": {
"enabled": false
},
"assist": {
"enabled": false
}
}
180 changes: 164 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 3 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"build": "npm run build-esm && npm run build-cjs",
"build-esm": "rm -rf esm && mkdir -p esm && tsc -p tsconfig.esm.json && echo '{\"type\":\"module\"}' > esm/package.json",
"build-cjs": "rm -rf cjs && mkdir -p cjs && tsc -p tsconfig.cjs.json && echo '{\"type\":\"commonjs\"}' > cjs/package.json",
"prettier": "prettier --write \"src/**/*.ts\" \"types/**/*.d.ts\""
"format": "biome format --write",
"format:check": "biome format"
},
"types": "./types/index.d.ts",
"keywords": [
Expand Down Expand Up @@ -76,22 +77,17 @@
}
},
"devDependencies": {
"@biomejs/biome": "^2.5.7",
"@opentelemetry/api": "^1.9.0",
"@types/chai": "^4.3.5",
"@types/mocha": "^10.0.10",
"@types/node": "20.12.0",
"chai": "^4.3.7",
"mocha": "^10.2.0",
"prettier": "^3.3.3",
"ts-node": "^10.9.1",
"typescript": "^5.5.4",
"undici-types": "^7.16.0"
},
"prettier": {
"semi": true,
"singleQuote": true,
"parser": "typescript"
},
"dependencies": {
"zod": "^4.3.6"
}
Expand Down
15 changes: 14 additions & 1 deletion src/RequestWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
extractHttpStatusCode,
extractRequestTelemetryError,
resolveChargebeeApiVersion,
attachSdkTelemetryHeader,
type TelemetryAdapter,
} from './telemetry/index.js';
import { handleResponse } from './coreCommon.js';
Expand Down Expand Up @@ -115,6 +116,15 @@ export class RequestWrapper {
if (this.envArg.telemetryAdapter !== undefined) {
_env.telemetryAdapter = this.envArg.telemetryAdapter;
}
if (this.envArg.sdkTelemetryState !== undefined) {
_env.sdkTelemetryState = this.envArg.sdkTelemetryState;
}
if (this.envArg.sdkTelemetryEnabled !== undefined) {
_env.sdkTelemetryEnabled = this.envArg.sdkTelemetryEnabled;
}
if (this.envArg.httpClientIsCustom !== undefined) {
_env.httpClientIsCustom = this.envArg.httpClientIsCustom;
}

const env = _env as EnvType;

Expand Down Expand Up @@ -233,6 +243,7 @@ export class RequestWrapper {
...this.httpHeaders,
...telemetryHeaders,
};
attachSdkTelemetryHeader(env, requestHeaders);

const contentType = this.apiCall.isJsonRequest
? 'application/json;charset=UTF-8'
Expand Down Expand Up @@ -385,10 +396,12 @@ export class RequestWrapper {
}
};

const promise =
const executeCall = () =>
telemetryAdapter !== undefined
? runWithTelemetry(telemetryAdapter)
: withRetry(0, requestStartTime);

const promise = executeCall();
return callbackifyPromise(promise);
}

Expand Down
6 changes: 5 additions & 1 deletion src/chargebee.cjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import {
} from './resources/webhook/handler.js';
import { basicAuthValidator } from './resources/webhook/auth.js';
import { ChargebeeZodValidationError } from './chargebeeZodValidationError.js';
import { TelemetryAttributeKeys } from './telemetry/index.js';
import {
TelemetryAttributeKeys,
SDK_TELEMETRY_HEADER_NAME,
} from './telemetry/index.js';

const httpClient = new FetchHttpClient();
const Chargebee = CreateChargebee(httpClient);
Expand All @@ -29,6 +32,7 @@ module.exports.WebhookAuthenticationError = WebhookAuthenticationError;
module.exports.WebhookPayloadValidationError = WebhookPayloadValidationError;
module.exports.WebhookPayloadParseError = WebhookPayloadParseError;
module.exports.TelemetryAttributeKeys = TelemetryAttributeKeys;
module.exports.SDK_TELEMETRY_HEADER_NAME = SDK_TELEMETRY_HEADER_NAME;

// Export validation error class
module.exports.ChargebeeZodValidationError = ChargebeeZodValidationError;
Expand Down
5 changes: 4 additions & 1 deletion src/chargebee.esm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ export {
WebhookPayloadValidationError,
WebhookPayloadParseError,
} from './resources/webhook/handler.js';
export { TelemetryAttributeKeys } from './telemetry/index.js';
export {
TelemetryAttributeKeys,
SDK_TELEMETRY_HEADER_NAME,
} from './telemetry/index.js';

// Export validation error class
export { ChargebeeZodValidationError } from './chargebeeZodValidationError.js';
Expand Down
Loading
Loading