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 optional forceFlush property to SpanExporter interface #3753

Merged
merged 39 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 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://github.com/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://github.com/sgracias1/opentelemet…
sgracias1 Aug 18, 2022
7fbe25e
Merge branch 'main' into Issue_3067
JacksonWeber Apr 24, 2023
c7d7f34
Merge branch 'main' into Issue_3067
JacksonWeber Apr 24, 2023
b8e1bd8
Fix lint.
JacksonWeber Apr 24, 2023
128a0bb
Have the SimpleSpanProcessor handle force flush.
JacksonWeber Apr 25, 2023
ed4233a
Merge branch 'main' into Issue_3067
JacksonWeber Apr 25, 2023
4160c98
Update changelog.
JacksonWeber Apr 25, 2023
c288545
Update the span processor to call forceFlush in the exporter.
JacksonWeber Apr 25, 2023
c5afa1d
Fix lint.
JacksonWeber Apr 25, 2023
8808b95
Merge branch 'main' into Issue_3067
JacksonWeber Apr 26, 2023
23eceda
Make the forceFlush method optional.
JacksonWeber May 11, 2023
7ea430e
fix(changelog): replace mandatory -> optional
pichlermarc May 11, 2023
928d18f
Merge branch 'main' into Issue_3067
pichlermarc May 11, 2023
c0f8ca2
Merge branch 'main' into Issue_3067
JacksonWeber May 11, 2023
6ce7ad5
Merge branch 'main' into Issue_3067
pichlermarc May 15, 2023
352369c
Add or update the Azure App Service build and deployment workflow config
JacksonWeber May 16, 2023
d9f8201
Delete issue_3067_jacksonweber-test-github.yml
JacksonWeber May 17, 2023
1f10e70
Merge branch 'main' into Issue_3067
JacksonWeber May 17, 2023
4681464
Merge branch 'main' into Issue_3067
JacksonWeber May 17, 2023
6914c20
Add comment for ignoring resolved values.
JacksonWeber May 17, 2023
d22a10e
Merge branch 'Issue_3067' of https://github.com/JacksonWeber/opentele…
JacksonWeber May 17, 2023
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
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
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