Skip to content

Commit

Permalink
feat: add SDK and Crawlee version to the ApifyClient's user agent
Browse files Browse the repository at this point in the history
Closes #331
  • Loading branch information
B4nan committed Nov 1, 2024
1 parent 928a55e commit 3e1e0bf
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions packages/apify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@
"@crawlee/core": "^3.9.0",
"@crawlee/types": "^3.9.0",
"@crawlee/utils": "^3.9.0",
"apify-client": "^2.9.0",
"apify-client": "^2.10.0",
"fs-extra": "^11.2.0",
"ow": "^0.28.2",
"semver": "^7.5.4",
"tslib": "^2.6.2",
"ws": "^8.18.0"
}
}
}
6 changes: 4 additions & 2 deletions packages/apify/src/actor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import { KeyValueStore } from './key_value_store';
import { PlatformEventManager } from './platform_event_manager';
import type { ProxyConfigurationOptions } from './proxy_configuration';
import { ProxyConfiguration } from './proxy_configuration';
import { checkCrawleeVersion, logSystemInfo, printOutdatedSdkWarning } from './utils';
import { checkCrawleeVersion, getSystemInfo, printOutdatedSdkWarning } from './utils';

/**
* `Actor` class serves as an alternative approach to the static helpers exported from the package. It allows to pass configuration
Expand Down Expand Up @@ -191,7 +191,7 @@ export class Actor<Data extends Dictionary = Dictionary> {
this.initialized = true;

checkCrawleeVersion();
logSystemInfo();
log.info('System info', getSystemInfo());
printOutdatedSdkWarning();

// reset global config instance to respect APIFY_ prefixed env vars
Expand Down Expand Up @@ -938,9 +938,11 @@ export class Actor<Data extends Dictionary = Dictionary> {
*/
newClient(options: ApifyClientOptions = {}): ApifyClient {
const { storageDir, ...storageClientOptions } = this.config.get('storageClientOptions') as Dictionary;
const { apifyVersion, crawleeVersion } = getSystemInfo();
return new ApifyClient({
baseUrl: this.config.get('apiBaseUrl'),
token: this.config.get('token'),
userAgentSuffix: [`SDK/${apifyVersion}`, `Crawlee/${crawleeVersion}`],
...storageClientOptions,
...options, // allow overriding the instance configuration
});
Expand Down
9 changes: 4 additions & 5 deletions packages/apify/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,20 @@ import semver from 'semver';
import { version as apifyVersion } from '../package.json';

/**
* Logs info about system, node version and apify package version.
* Gets info about system, node version and apify package version.
* @internal
*/
export function logSystemInfo() {
log.info('System info', {
export function getSystemInfo() {
return {
apifyVersion,
apifyClientVersion,
crawleeVersion,
osType: type(),
nodeVersion: process.version,
});
};
}

/**
* Logs info about system, node version and apify package version.
* @internal
*/
export function checkCrawleeVersion() {
Expand Down

0 comments on commit 3e1e0bf

Please sign in to comment.