From a3983faa442d4ffa68bd4077de83e5eca088eeb6 Mon Sep 17 00:00:00 2001 From: Justin Siebert Date: Wed, 4 Sep 2024 11:17:32 -0400 Subject: [PATCH] fix(jaeger-remote-sampler): Catch errors retrieving remote config (#4976) --- experimental/CHANGELOG.md | 2 ++ .../src/JaegerRemoteSampler.ts | 2 ++ .../test/JaegerRemoteSampler.test.ts | 17 ++++++++++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index 0b37b3aa31..673477fdbb 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -11,6 +11,8 @@ All notable changes to experimental packages in this project will be documented ### :bug: (Bug Fix) +* fix(sampler-jaeger-remote): fixes an issue where package could emit unhandled promise rejections @Just-Sieb + ### :books: (Refine Doc) ### :house: (Internal) diff --git a/experimental/packages/sampler-jaeger-remote/src/JaegerRemoteSampler.ts b/experimental/packages/sampler-jaeger-remote/src/JaegerRemoteSampler.ts index e662287934..419add1652 100644 --- a/experimental/packages/sampler-jaeger-remote/src/JaegerRemoteSampler.ts +++ b/experimental/packages/sampler-jaeger-remote/src/JaegerRemoteSampler.ts @@ -58,6 +58,8 @@ export class JaegerRemoteSampler implements Sampler { this._syncingConfig = true; try { await this.getAndUpdateSampler(); + } catch (err) { + diag.warn('Could not update sampler', err); } finally { this._syncingConfig = false; } diff --git a/experimental/packages/sampler-jaeger-remote/test/JaegerRemoteSampler.test.ts b/experimental/packages/sampler-jaeger-remote/test/JaegerRemoteSampler.test.ts index b675032e71..021555e50f 100644 --- a/experimental/packages/sampler-jaeger-remote/test/JaegerRemoteSampler.test.ts +++ b/experimental/packages/sampler-jaeger-remote/test/JaegerRemoteSampler.test.ts @@ -80,13 +80,28 @@ describe('JaegerRemoteSampler', () => { ); new JaegerRemoteSampler({ endpoint, - serviceName, poolingInterval, + serviceName, initialSampler: alwaysOnSampler, }); await clock.tickAsync(poolingInterval * 2); sinon.assert.callCount(getAndUpdateSamplerStub, 1); }); + + it('Doesnt throw unhandled promise rejection when failing to get remote config', async () => { + getAndUpdateSamplerStub.rejects(); + const unhandledRejectionListener = sinon.fake(); + process.once('unhandledRejection', unhandledRejectionListener); + new JaegerRemoteSampler({ + endpoint, + serviceName, + poolingInterval, + initialSampler: alwaysOnSampler, + }); + await clock.tickAsync(poolingInterval * 2); + sinon.assert.callCount(getAndUpdateSamplerStub, 2); + sinon.assert.callCount(unhandledRejectionListener, 0); + }); }); describe('shouldSample', () => {