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

fix(sdk-trace-base): always wait on pending export in SimpleSpanProcessor #5303

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

anuraaga
Copy link
Contributor

@anuraaga anuraaga commented Jan 7, 2025

Which problem is this PR solving?

It isn't possible to know when a SimpleSpanProcessor has finished exporting spans, e.g. before asserting on spans in a unit test. AFAIK unit tests are mostly required to use BatchSpanProcessor because of this.

Fixes #1841

Short description of the changes

Tracks pending exports always in SimpleSpanProcessor, not only when async resource is used. This is because export itself is async and has the same need for tracking as the async resource path. There isn't a way to avoid "scheduling a promise" if export itself is a promise.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Unit test

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been added
  • Documentation has been updated

@@ -38,16 +38,16 @@ import { Resource } from '@opentelemetry/resources';
*/
export class SimpleSpanProcessor implements SpanProcessor {
private _shutdownOnce: BindOnceFuture<void>;
private _unresolvedExports: Set<Promise<void>>;
private _pendingExports: Set<Promise<void>>;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unresolved seemed to be referring specifically to the resource so I renamed to pending to be more generic

@@ -81,26 +86,17 @@ export class SimpleSpanProcessor implements SpanProcessor {
globalErrorHandler(error);
});

// Avoid scheduling a promise to make the behavior more predictable and easier to test
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this since it seemed to be misleading - a promise is scheduled by doExport anyways so there's no way to avoid scheduling one

@anuraaga anuraaga changed the title fix(opentelemetry-sdk-trace-base): always wait on pending export in SimpleSpanProcessor fix(sdk-trace-base): always wait on pending export in SimpleSpanProcessor Jan 7, 2025
@anuraaga anuraaga changed the title fix(sdk-trace-base): always wait on pending export in SimpleSpanProcessor fix(sdk-trace-base)!: always wait on pending export in SimpleSpanProcessor Jan 7, 2025
Copy link

codecov bot commented Jan 7, 2025

Codecov Report

Attention: Patch coverage is 90.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 94.63%. Comparing base (90afa28) to head (229d810).

Files with missing lines Patch % Lines
...y-sdk-trace-base/src/export/SimpleSpanProcessor.ts 90.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5303      +/-   ##
==========================================
+ Coverage   94.62%   94.63%   +0.01%     
==========================================
  Files         323      323              
  Lines        8068     8067       -1     
  Branches     1637     1637              
==========================================
  Hits         7634     7634              
+ Misses        434      433       -1     
Files with missing lines Coverage Δ
...y-sdk-trace-base/src/export/SimpleSpanProcessor.ts 92.30% <90.00%> (-0.20%) ⬇️

... and 1 file with indirect coverage changes

@anuraaga anuraaga changed the title fix(sdk-trace-base)!: always wait on pending export in SimpleSpanProcessor fix(sdk-trace-base): always wait on pending export in SimpleSpanProcessor Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SimpleSpanProcessor.forceFlush doesn't wait for pending exports
1 participant