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

Change SpanExporter::export &self to &mut self #350

Merged
merged 5 commits into from
Nov 8, 2020

Conversation

frigus02
Copy link
Member

@frigus02 frigus02 commented Nov 8, 2020

This is a proposal. I think it would make sense to change &self in the SpanExporter::export function to a &mut self. The spec says

Export() will never be called concurrently for the same exporter instance. Export() can be called again only after the current call returns.

This change would enforce the restriction at compile time, which is nice.

While doing this change I noticed that the SimpleSpanProcessor doesn't adhere to this. It calls export in on_end without any checks and on_end can be called from multiple threads concurrently. I changed it to use a Mutex for now.

As a second step I removed the Sync requirement for SpanExporter. We can now do this without any problems, because both of it's functions take a &mut self. This means the stdout exporter no longer needs an internal Mutex. I'm not entirely sure about this change, though. Is it possible for the spec to have a non-breaking change, that would require us to add Sync back (which would be a breaking change)?

@frigus02 frigus02 requested a review from a team November 8, 2020 20:56
@codecov
Copy link

codecov bot commented Nov 8, 2020

Codecov Report

Merging #350 (4916c2c) into master (fd8cf65) will increase coverage by 0.39%.
The diff coverage is 91.22%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #350      +/-   ##
==========================================
+ Coverage   53.81%   54.21%   +0.39%     
==========================================
  Files          69       69              
  Lines        5779     5829      +50     
==========================================
+ Hits         3110     3160      +50     
  Misses       2669     2669              
Impacted Files Coverage Δ
opentelemetry-otlp/src/span.rs 2.67% <ø> (ø)
opentelemetry/src/api/trace/noop.rs 68.93% <0.00%> (ø)
opentelemetry/src/exporter/trace/mod.rs 70.27% <ø> (ø)
opentelemetry/src/exporter/trace/stdout.rs 23.07% <ø> (-5.50%) ⬇️
opentelemetry/src/testing/trace.rs 72.91% <91.42%> (+49.83%) ⬆️
opentelemetry/src/sdk/trace/span_processor.rs 77.65% <95.23%> (+8.42%) ⬆️
...ntelemetry/src/sdk/metrics/aggregators/ddsketch.rs 78.59% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fd8cf65...4916c2c. Read the comment docs.

Copy link
Contributor

@TommyCpp TommyCpp left a comment

Choose a reason for hiding this comment

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

Looks great! Just a small nit.

@jtescher
Copy link
Member

jtescher commented Nov 8, 2020

I think this is a good idea, should be able to remove the inner mutexes from the exporters now too

e.g.

conn: tokio::sync::Mutex<tokio::net::UdpSocket>,
#[cfg(all(feature = "async-std", not(feature = "tokio")))]
conn: async_std::sync::Mutex<async_std::net::UdpSocket>,
buffer_client: Mutex<BufferClient>,

@frigus02
Copy link
Member Author

frigus02 commented Nov 8, 2020

should be able to remove the inner mutexes from the exporters now too

I think I looked at all exporters except Jaeger. Didn't think it would contain mutexes 🤦. Will remove those, too.

frigus02 and others added 4 commits November 8, 2020 22:25
This enforces the following part of the spec:

> Export() will never be called concurrently for the same exporter
> instance. Export() can be called again only after the current call
> returns.
None of the functions in the SpanExporter require it to be Sync. Export
is guaranteed not to be called concurrently and shutdown should only be
called once in total.

This change means the stdout exporter no longer requires a Mutex around
the Write.
Copy link
Member

@jtescher jtescher left a comment

Choose a reason for hiding this comment

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

Looks good! I think the jaeger exporter buffer clone can probably be removed now too, but can be done in a subsequent pr

@jtescher jtescher merged commit 5cf034c into open-telemetry:master Nov 8, 2020
@frigus02
Copy link
Member Author

frigus02 commented Nov 8, 2020

Yeah, I think we should be able to remove that. But I'm not entirely sure how. We want the thrift client to write into a buffer, which we can later read. What's the pattern we would typically use in Rust? A channel?

@frigus02 frigus02 deleted the mut-self-export branch November 8, 2020 23:15
@jtescher
Copy link
Member

jtescher commented Nov 8, 2020

Would be nice if the thrift crate had a cleaner way of writing and reading since it does not do either one in parallel, but the current API only lets you split. In that case it would ordinarily be fine to have a Rc<RefCell<T>>, but we need this processing to be spawned so it has to be Send. Even if we stay with Arc<Mutex<T>> we should still be able to lock, send data to the socket and then clear the vec, as opposed to clone then send data via reference to the cloned vec, but std mutexs don't play well across await points. This could use the async mutex types that were used before behind feature flags though.

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.

3 participants