diff --git a/experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusExporter.ts b/experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusExporter.ts index 35c1de5bd9..3028f22723 100644 --- a/experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusExporter.ts +++ b/experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusExporter.ts @@ -68,7 +68,8 @@ export class PrometheusExporter implements MetricExporter { typeof config.appendTimestamp === 'boolean' ? config.appendTimestamp : PrometheusExporter.DEFAULT_OPTIONS.appendTimestamp; - this._server = createServer(this._requestHandler); + // unref to prevent prometheus exporter from holding the process open on exit + this._server = createServer(this._requestHandler).unref(); this._serializer = new PrometheusSerializer( this._prefix, this._appendTimestamp diff --git a/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusExporter.test.ts b/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusExporter.test.ts index 3b5f044be3..9860d82eed 100644 --- a/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusExporter.test.ts @@ -36,6 +36,7 @@ describe('PrometheusExporter', () => { mockAggregator(HistogramAggregator); afterEach(() => { + sinon.restore(); delete process.env.OTEL_EXPORTER_PROMETHEUS_HOST; delete process.env.OTEL_EXPORTER_PROMETHEUS_PORT; }); @@ -116,6 +117,16 @@ describe('PrometheusExporter', () => { ); }); + it('should unref the server to allow graceful termination', () => { + const mockServer = sinon.createStubInstance(http.Server); + const createStub = sinon.stub(http, 'createServer'); + createStub.returns((mockServer as any) as http.Server); + const exporter = new PrometheusExporter({}, async () => { + await exporter.shutdown(); + }); + sinon.assert.calledOnce(mockServer.unref); + }); + it('should listen on environmentally set host and port', () => { process.env.OTEL_EXPORTER_PROMETHEUS_HOST = '127.0.0.1'; process.env.OTEL_EXPORTER_PROMETHEUS_PORT = '1234'; diff --git a/experimental/packages/opentelemetry-instrumentation-xml-http-request/src/xhr.ts b/experimental/packages/opentelemetry-instrumentation-xml-http-request/src/xhr.ts index 09d8a0c588..d2d126be8e 100644 --- a/experimental/packages/opentelemetry-instrumentation-xml-http-request/src/xhr.ts +++ b/experimental/packages/opentelemetry-instrumentation-xml-http-request/src/xhr.ts @@ -57,13 +57,15 @@ export type XHRCustomAttributeFunction = ( */ export interface XMLHttpRequestInstrumentationConfig extends InstrumentationConfig { - // the number of timing resources is limited, after the limit - // (chrome 250, safari 150) the information is not collected anymore - // the only way to prevent that is to regularly clean the resources - // whenever it is possible, this is needed only when PerformanceObserver - // is not available + /** + * The number of timing resources is limited, after the limit + * (chrome 250, safari 150) the information is not collected anymore. + * The only way to prevent that is to regularly clean the resources + * whenever it is possible. This is needed only when PerformanceObserver + * is not available + */ clearTimingResources?: boolean; - // urls which should include trace headers when origin doesn't match + /** URLs which should include trace headers when origin doesn't match */ propagateTraceHeaderCorsUrls?: PropagateTraceHeaderCorsUrls; /** * URLs that partially match any regex in ignoreUrls will not be traced.