Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rum-api-client): log fetches bundles length #530

Merged
merged 1 commit into from
Jan 8, 2025
Merged
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
12 changes: 11 additions & 1 deletion packages/spacecat-shared-rum-api-client/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,19 @@ const HANDLERS = {

export default class RUMAPIClient {
static createFrom(context) {
const { log = console } = context;

if (context.rumApiClient) return context.rumApiClient;

const client = new RUMAPIClient();
const client = new RUMAPIClient(log);
context.rumApiClient = client;
return client;
}

constructor(log) {
this.log = log;
}

// eslint-disable-next-line class-methods-use-this
async query(query, opts) {
const { handler, checkpoints } = HANDLERS[query] || {};
Expand All @@ -56,6 +62,8 @@ export default class RUMAPIClient {
checkpoints,
});

this.log.info(`Query "${query}" fetched ${bundles.length} bundles`);

return handler(bundles, opts);
} catch (e) {
throw new Error(`Query '${query}' failed. Opts: ${JSON.stringify(opts)}. Reason: ${e.message}`);
Expand Down Expand Up @@ -87,6 +95,8 @@ export default class RUMAPIClient {

const results = {};

this.log.info(`Multi query ${JSON.stringify(queries.join(', '))} fetched ${bundles.length} bundles`);

// Execute each query handler sequentially
for (const { query, handler } of queryHandlers) {
// eslint-disable-next-line no-await-in-loop
Expand Down
Loading