Skip to content

Commit

Permalink
feat: changed resource detection to use logger from opentelemetry-api
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Egyed <[email protected]>
  • Loading branch information
adamegyed committed Jun 17, 2020
1 parent 07f0e0e commit 0bccc3f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
4 changes: 3 additions & 1 deletion packages/opentelemetry-resources/src/platform/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
}
Expand Down
15 changes: 11 additions & 4 deletions packages/opentelemetry-resources/test/detect-resources.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
]);
});
Expand Down

0 comments on commit 0bccc3f

Please sign in to comment.