From 08672ad4e596ecaf15816d326ba9717ef1e09fce Mon Sep 17 00:00:00 2001 From: Nidhi Work Date: Tue, 20 Feb 2024 17:31:57 +0000 Subject: [PATCH] refactor(publish-metrics): warning instead of throwing when no api set --- .../lib/open-telemetry/translators/vendor-adot.js | 3 ++- .../test/unit/adot-translators.js | 11 +++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/artillery-plugin-publish-metrics/lib/open-telemetry/translators/vendor-adot.js b/packages/artillery-plugin-publish-metrics/lib/open-telemetry/translators/vendor-adot.js index 355666d938..35bd4572fb 100644 --- a/packages/artillery-plugin-publish-metrics/lib/open-telemetry/translators/vendor-adot.js +++ b/packages/artillery-plugin-publish-metrics/lib/open-telemetry/translators/vendor-adot.js @@ -117,7 +117,8 @@ function getADOTEnvVars(adotRelevantconfigs, dotenv) { Object.assign(envVars, vendorVars); }); } catch (err) { - throw new Error(err); + // We warn here instead of throwing because in the future we will support providing these variables through secrets + console.warn(err.message); } return envVars; } diff --git a/packages/artillery-plugin-publish-metrics/test/unit/adot-translators.js b/packages/artillery-plugin-publish-metrics/test/unit/adot-translators.js index 55fe08e302..4d771b71eb 100644 --- a/packages/artillery-plugin-publish-metrics/test/unit/adot-translators.js +++ b/packages/artillery-plugin-publish-metrics/test/unit/adot-translators.js @@ -120,17 +120,16 @@ test('when getADOTEnvVars is called with a list of adotRelevantconfigs and a dot }); // Maybe remove throwing an error in the function itself as it propagates to the resolveADOTConfigSettings and then we can handle it there -test('when getADOTEnvVars is called with an unsupported vendor, it throws an error', async (t) => { +test('if an error happens in getADOTEnvVars it logs the error message and returns the current state of envVars variable ', async (t) => { const adotRelevantconfigs = [ { - type: 'unsupportedVendor', + type: 'datadog', tracing: {} } ]; - const dotenv = { - DD_API_KEY: '123' - }; - t.throws(() => getADOTEnvVars(adotRelevantconfigs, dotenv)); + const dotenv = {}; + const result = getADOTEnvVars(adotRelevantconfigs, dotenv); + t.same(result, {}); }); test('when getADOTEnvVars is called with an empty list of adotRelevantconfigs and an empty dotenv object it returns an empty object', async (t) => {