Skip to content

Commit

Permalink
fix: zipkin-exporter: don't export after shutdown
Browse files Browse the repository at this point in the history
According to spec and exporter should return FailedNotRetryable error
after shutdown was called.
  • Loading branch information
Flarna committed Nov 13, 2019
1 parent f15dedb commit cb5d416
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/opentelemetry-exporter-zipkin/src/zipkin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class ZipkinExporter implements SpanExporter {
private readonly _statusCodeTagName: string;
private readonly _statusDescriptionTagName: string;
private readonly _reqOpts: http.RequestOptions;
private _shutdown: boolean;

constructor(config: zipkinTypes.ExporterConfig) {
const urlStr = config.url || ZipkinExporter.DEFAULT_URL;
Expand All @@ -60,6 +61,7 @@ export class ZipkinExporter implements SpanExporter {
this._statusCodeTagName = config.statusCodeTagName || statusCodeTagName;
this._statusDescriptionTagName =
config.statusDescriptionTagName || statusDescriptionTagName;
this._shutdown = false;
}

/**
Expand All @@ -70,6 +72,10 @@ export class ZipkinExporter implements SpanExporter {
resultCallback: (result: ExportResult) => void
) {
this._logger.debug('Zipkin exporter export');
if (this._shutdown) {
setImmediate(resultCallback, ExportResult.FAILED_NOT_RETRYABLE);
return;
}
return this._sendSpans(spans, resultCallback);
}

Expand All @@ -78,6 +84,10 @@ export class ZipkinExporter implements SpanExporter {
*/
shutdown() {
this._logger.debug('Zipkin exporter shutdown');
if (this._shutdown) {
return;
}
this._shutdown = true;
// Make an optimistic flush.
if (this._forceFlush) {
// @todo get spans from span processor (batch)
Expand Down
14 changes: 14 additions & 0 deletions packages/opentelemetry-exporter-zipkin/test/zipkin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,20 @@ describe('ZipkinExporter', () => {
assert.strictEqual(result, ExportResult.FAILED_RETRYABLE);
});
});

it('should return FailedNonRetryable after shutdown', done => {
const exporter = new ZipkinExporter({
serviceName: 'my-service',
logger: new NoopLogger(),
});

exporter.shutdown();

exporter.export([getReadableSpan()], (result: ExportResult) => {
assert.strictEqual(result, ExportResult.FAILED_NOT_RETRYABLE);
done();
});
});
});

describe('shutdown', () => {
Expand Down

0 comments on commit cb5d416

Please sign in to comment.