Skip to content

Commit

Permalink
Merge branch 'main' into automatic-release-prep
Browse files Browse the repository at this point in the history
  • Loading branch information
pichlermarc authored May 17, 2023
2 parents dbdfd1a + fcd75df commit 7519920
Show file tree
Hide file tree
Showing 16 changed files with 98 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/

### :rocket: (Enhancement)

* feat(SpanExpoter): Add optional forceFlush to SpanExporter interface [#3753](https://github.com/open-telemetry/opentelemetry-js/pull/3753/) @sgracias1 @JacksonWeber

### :bug: (Bug Fix)

### :books: (Refine Doc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ class DummySpanExporter implements tracing.SpanExporter {
shutdown() {
return Promise.resolve();
}

forceFlush(): Promise<void> {
return Promise.resolve();
}
}

const getData = (url: string, method?: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ class DummySpanExporter implements tracing.SpanExporter {
shutdown() {
return Promise.resolve();
}

forceFlush(): Promise<void> {
return Promise.resolve();
}
}

const XHR_TIMEOUT = 2000;
Expand Down
13 changes: 10 additions & 3 deletions experimental/packages/otlp-exporter-base/src/OTLPExporterBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,22 @@ export abstract class OTLPExporterBase<
return this._shutdownOnce.call();
}

/**
* Exports any pending spans in the exporter
*/
forceFlush(): Promise<void> {
return Promise.all(this._sendingPromises).then(() => {
/** ignore resolved values */
});
}

/**
* Called by _shutdownOnce with BindOnceFuture
*/
private _shutdown(): Promise<void> {
diag.debug('shutdown started');
this.onShutdown();
return Promise.all(this._sendingPromises).then(() => {
/** ignore resolved values */
});
return this.forceFlush();
}

abstract onShutdown(): void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ class Exporter extends OTLPExporterNodeBase<object, object> {
}
}

describe('force flush', () => {
it('forceFlush should flush spans and return', async () => {
const exporter = new Exporter({});
await exporter.forceFlush();
});
});

describe('configureExporterTimeout', () => {
const envSource = process.env;
it('should use timeoutMillis parameter as export timeout value', () => {
Expand Down
7 changes: 7 additions & 0 deletions packages/opentelemetry-exporter-jaeger/src/jaeger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ export class JaegerExporter implements SpanExporter {
return this._shutdownOnce.call();
}

/**
* Exports any pending spans in exporter
*/
forceFlush(): Promise<void> {
return this._flush();
}

private _shutdown(): Promise<void> {
return Promise.race([
new Promise<void>((_resolve, reject) => {
Expand Down
8 changes: 8 additions & 0 deletions packages/opentelemetry-exporter-jaeger/test/jaeger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ describe('JaegerExporter', () => {
});
});

describe('force flush', () => {
let exporter: JaegerExporter;
it('forceFlush should flush spans and return', async () => {
exporter = new JaegerExporter();
await exporter.forceFlush();
});
});

describe('export', () => {
let exporter: JaegerExporter;

Expand Down
7 changes: 7 additions & 0 deletions packages/opentelemetry-exporter-zipkin/src/zipkin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ export class ZipkinExporter implements SpanExporter {
shutdown(): Promise<void> {
diag.debug('Zipkin exporter shutdown');
this._isShutdown = true;
return this.forceFlush();
}

/**
* Exports any pending spans in exporter
*/
forceFlush(): Promise<void> {
return new Promise((resolve, reject) => {
Promise.all(this._sendingPromises).then(() => {
resolve();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,13 @@ describe('Zipkin Exporter - node', () => {
});
});

describe('force flush', () => {
it('forceFlush should flush spans and return', async () => {
const exporter = new ZipkinExporter({});
await exporter.forceFlush();
});
});

describe('when env.OTEL_EXPORTER_ZIPKIN_ENDPOINT is set', () => {
before(() => {
process.env.OTEL_EXPORTER_ZIPKIN_ENDPOINT = 'http://localhost:9412';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ export class ConsoleSpanExporter implements SpanExporter {
*/
shutdown(): Promise<void> {
this._sendSpans([]);
return this.forceFlush();
}

/**
* Exports any pending spans in exporter
*/
forceFlush(): Promise<void> {
return Promise.resolve();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ export class InMemorySpanExporter implements SpanExporter {
shutdown(): Promise<void> {
this._stopped = true;
this._finishedSpans = [];
return this.forceFlush();
}

/**
* Exports any pending spans in the exporter
*/
forceFlush(): Promise<void> {
return Promise.resolve();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ export class SimpleSpanProcessor implements SpanProcessor {
async forceFlush(): Promise<void> {
// await unresolved resources before resolving
await Promise.all(Array.from(this._unresolvedExports));
if (this._exporter.forceFlush) {
await this._exporter.forceFlush();
}
}

onStart(_span: Span, _parentContext: Context): void {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@ export interface SpanExporter {

/** Stops the exporter. */
shutdown(): Promise<void>;

/** Immediately export all spans */
forceFlush?(): Promise<void>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,11 @@ describe('ConsoleSpanExporter', () => {
});
});
});

describe('force flush', () => {
it('forceFlush should flush spans and return', async () => {
consoleExporter = new ConsoleSpanExporter();
await consoleExporter.forceFlush();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ describe('InMemorySpanExporter', () => {
assert.strictEqual(memoryExporter.getFinishedSpans().length, 0);
});

describe('force flush', () => {
it('forceFlush should flush spans and return', async () => {
memoryExporter = new InMemorySpanExporter();
await memoryExporter.forceFlush();
});
});

it('should return the success result', () => {
const exorter = new InMemorySpanExporter();
exorter.export([], (result: ExportResult) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ describe('SimpleSpanProcessor', () => {
});

describe('force flush', () => {
it('should call forceflush on exporter', () => {
const spyflush = sinon.spy(exporter, 'forceFlush');
const processor = new SimpleSpanProcessor(exporter);
processor.forceFlush().then(() => {
assert.ok(spyflush.calledOnce);
});
});

it('should await unresolved resources', async () => {
const processor = new SimpleSpanProcessor(exporter);
const providerWithAsyncResource = new BasicTracerProvider({
Expand Down

0 comments on commit 7519920

Please sign in to comment.