From f0486e769dd38b7fb08020821d1822f89ee3b463 Mon Sep 17 00:00:00 2001 From: Adam Egyed Date: Wed, 17 Jun 2020 21:05:50 +0000 Subject: [PATCH] refactor: change resource detection to use logger from opentelemetry-api Signed-off-by: Adam Egyed --- .../src/platform/node/config.ts | 4 +++- .../src/platform/node/detect-resources.ts | 4 ++-- .../test/detect-resources.test.ts | 15 +++++++++++---- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/packages/opentelemetry-resources/src/platform/node/config.ts b/packages/opentelemetry-resources/src/platform/node/config.ts index ae7b89215b..a6d7a91177 100644 --- a/packages/opentelemetry-resources/src/platform/node/config.ts +++ b/packages/opentelemetry-resources/src/platform/node/config.ts @@ -14,10 +14,12 @@ * limitations under the License. */ +import { Logger } from '@opentelemetry/api'; + /** * ResourceDetectionConfig provides an interface for configuring resource auto-detection. */ export interface ResourceDetectionConfig { /** Optional Logger. */ - logger?: (message: string) => void; + logger?: Logger; } diff --git a/packages/opentelemetry-resources/src/platform/node/detect-resources.ts b/packages/opentelemetry-resources/src/platform/node/detect-resources.ts index 265c55b590..81ff7b69ec 100644 --- a/packages/opentelemetry-resources/src/platform/node/detect-resources.ts +++ b/packages/opentelemetry-resources/src/platform/node/detect-resources.ts @@ -53,8 +53,8 @@ export const detectResources = async ( const detectorName = DETECTORS[index].constructor ? DETECTORS[index].constructor.name : 'Unknown detector'; - config.logger!(`${detectorName} found resource.`); - config.logger!(resourceDebugString); + config.logger!.debug(`${detectorName} found resource.`); + config.logger!.debug(resourceDebugString); } }); } diff --git a/packages/opentelemetry-resources/test/detect-resources.test.ts b/packages/opentelemetry-resources/test/detect-resources.test.ts index b63c611865..6d6586f081 100644 --- a/packages/opentelemetry-resources/test/detect-resources.test.ts +++ b/packages/opentelemetry-resources/test/detect-resources.test.ts @@ -167,13 +167,20 @@ describe('detectResources', async () => { describe('with a debug logger', () => { it('prints detected resources to the logger', async () => { // This test depends on the env detector to be functioning as intended - const mockedLogger = sinon.fake(); - await detectResources({ logger: mockedLogger }); + const mockedLoggerMethod = sinon.fake(); + await detectResources({ + logger: { + debug: mockedLoggerMethod, + info: sinon.fake(), + warn: sinon.fake(), + error: sinon.fake(), + }, + }); - assert.deepStrictEqual(mockedLogger.getCall(0).args, [ + assert.deepStrictEqual(mockedLoggerMethod.getCall(0).args, [ 'EnvDetector found resource.', ]); - assert.deepStrictEqual(mockedLogger.getCall(1).args, [ + assert.deepStrictEqual(mockedLoggerMethod.getCall(1).args, [ "{\n 'service.instance.id': '627cc493',\n 'service.name': 'my-service',\n 'service.namespace': 'default',\n 'service.version': '0.0.1'\n}", ]); });