From f642f51d006ffe2eda20761ec05d535551028a4b Mon Sep 17 00:00:00 2001 From: ekremney Date: Wed, 8 Jan 2025 14:34:59 +0100 Subject: [PATCH] feat(rum-api-client): log fetches bundles length --- packages/spacecat-shared-rum-api-client/src/index.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/spacecat-shared-rum-api-client/src/index.js b/packages/spacecat-shared-rum-api-client/src/index.js index e06bcc9a..18835ecc 100644 --- a/packages/spacecat-shared-rum-api-client/src/index.js +++ b/packages/spacecat-shared-rum-api-client/src/index.js @@ -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