Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(opentelemetry-sdk-trace-base): Add mandatory forceFlush property to SpanExporter interface #3071

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
01fe26e
feat(opentelemetry-sdk-trace-base): Add optional forceFlush property …
sgracias1 Jun 29, 2022
9073b2c
feat(opentelemetry-sdk-trace-base): fixup changelog
sgracias1 Jun 29, 2022
a8bc10d
feat(opentelemetry-sdk-trace-base): fixup changelog
sgracias1 Jun 29, 2022
f746ece
Merge branch 'main' into Issue_3067
sgracias1 Jul 27, 2022
c2af065
feat(opentelemetry-sdk-trace-base): add exporter forceflush functions
sgracias1 Jul 27, 2022
55c5c36
feat(opentelemetry-sdk-trace-base): add tests, add empty implemtation…
sgracias1 Jul 27, 2022
18e90f5
feat(opentelemetry-sdk-trace-base): add implementation for forceflush…
sgracias1 Aug 1, 2022
99c1be5
Merge remote-tracking branch 'upstream/main' into Issue_3067
sgracias1 Aug 1, 2022
8058f45
feat(opentelemetry-sdk-trace-base): fix lint, minor review change
sgracias1 Aug 4, 2022
5b7dce7
Merge remote-tracking branch 'upstream/main' into Issue_3067
sgracias1 Aug 4, 2022
4bc295a
Merge branch 'main' into Issue_3067
sgracias1 Aug 5, 2022
b09a48f
Merge branch 'main' into Issue_3067
sgracias1 Aug 8, 2022
39160d7
feat(opentelemetry-sdk-trace-base): minor review change
sgracias1 Aug 11, 2022
f7b49fb
Merge remote-tracking branch 'upstream/main' into Issue_3067
sgracias1 Aug 11, 2022
9eae0d4
Merge branch 'Issue_3067' of https:/sgracias1/opentelemet…
sgracias1 Aug 11, 2022
3490194
feat(opentelemetry-sdk-trace-base): fix lint
sgracias1 Aug 12, 2022
9d7b74e
Merge branch 'main' into Issue_3067
sgracias1 Aug 17, 2022
5a81e5f
feat(opentelemetry-sdk-trace-base): minor change
sgracias1 Aug 18, 2022
6c8b184
Merge branch 'Issue_3067' of https:/sgracias1/opentelemet…
sgracias1 Aug 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.

### :rocket: (Enhancement)

* feat(SpanExpoter): Add optional forceFlush to SpanExporter interface [#3067] @sgracias1
* feat(sdk-trace-base): move Sampler declaration into sdk-trace-base [#3088](https:/open-telemetry/opentelemetry-js/pull/3088) @legendecas
* fix(grpc-instrumentation): added grpc attributes in instrumentation [#3127](https:/open-telemetry/opentelemetry-js/pull/3127) @andrewzenkov

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ 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 @@ -47,6 +47,10 @@ class DummySpanExporter implements tracing.SpanExporter {
shutdown() {
return Promise.resolve();
}

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

const XHR_TIMEOUT = 2000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,20 @@ export abstract class OTLPExporterBase<
return this._shutdownOnce.call();
}

/**
* Exports any pending spans in the exporter
*/
forceFlush(): Promise<void> {
sgracias1 marked this conversation as resolved.
Show resolved Hide resolved
return Promise.all(this._sendingPromises).then(() => {});
}

/**
* 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 @@ -82,6 +82,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 @@ -166,6 +166,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 @@ -509,6 +509,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> {
dyladan marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -40,8 +40,7 @@ export class SimpleSpanProcessor implements SpanProcessor {
}

forceFlush(): Promise<void> {
// do nothing as all spans are being exported without waiting
return Promise.resolve();
return this._exporter.forceFlush();
}

// does nothing.
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 @@ -80,6 +80,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 @@ -149,6 +149,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(() => {
sgracias1 marked this conversation as resolved.
Show resolved Hide resolved
});
assert.ok(spyflush.calledOnce);
});

describe('when flushing complete', () => {
it('should call an async callback', done => {
const processor = new SimpleSpanProcessor(exporter);
Expand Down