Skip to content

Commit

Permalink
Merge branch 'main' into patch-2
Browse files Browse the repository at this point in the history
  • Loading branch information
dyladan authored Oct 26, 2021
2 parents 0fdb6bd + c1939a7 commit e30984e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit e30984e

Please sign in to comment.