Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rum-api-client): log fetches bundles length
Browse files Browse the repository at this point in the history
ekremney committed Jan 8, 2025
1 parent b779abb commit f642f51
Showing 1 changed file with 11 additions and 1 deletion.
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
@@ -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] || {};
@@ -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}`);
@@ -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

0 comments on commit f642f51

Please sign in to comment.