-
Notifications
You must be signed in to change notification settings - Fork 451
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
Ensure is_recording
is false after span ends
#265
Comments
It seems currently span can be ended in two ways:
Right now match self.with_data(|data| data.end_time.is_some()) {
Some(ended) => !ended,
None => false,
} |
@morigs yeah additionally it may be a good idea to move the logic from drop to |
@jtescher I think it's better not to move logic from drop because this will not allow to get SpanContext after end. |
Oh-oh, I forgot that |
Actually it's probably preferable to move span context outside the mutex, would also allow span context to return a reference instead of a clone which would be an improvement. I have a branch that does this that I could clean up and push. |
I have added some tests in #309 |
Currently the `Span` trait in the API has its `span_context` method return an owned `SpanContext`. In order to be more consistent with the rest of the APIs, this patch updates the trait to instead return a reference, and moves the `SpanContext` data outside of the mutex in the SDK to implement the trait. This also allows #265 to be implemented without having to lock.
Currently the `Span` trait in the API has its `span_context` method return an owned `SpanContext`. In order to be more consistent with the rest of the APIs, this patch updates the trait to instead return a reference, and moves the `SpanContext` data outside of the mutex in the SDK to implement the trait. This also allows #265 to be implemented without having to lock. Additionally the spec now states that the `on_start` method for `SpanProcessor`s must be passed a span and the parent context so those are updated as well.
Currently the `Span` trait in the API has its `span_context` method return an owned `SpanContext`. In order to be more consistent with the rest of the APIs, this patch updates the trait to instead return a reference, and moves the `SpanContext` data outside of the mutex in the SDK to implement the trait. This also allows #265 to be implemented without having to lock. Additionally the spec now states that the `on_start` method for `SpanProcessor`s must be passed a span and the parent context so those are updated as well.
Currently the `Span` trait in the API has its `span_context` method return an owned `SpanContext`. In order to be more consistent with the rest of the APIs, this patch updates the trait to instead return a reference, and moves the `SpanContext` data outside of the mutex in the SDK to implement the trait. This also allows #265 to be implemented without having to lock. Additionally the spec now states that the `on_start` method for `SpanProcessor`s must be passed a span and the parent context so those are updated as well.
@jtescher Hi. I'm working on moving logic from drop to
Click to expanderror[E0053]: method `end_with_timestamp` has an incompatible type for trait --> opentelemetry\src\sdk\trace\span.rs:142:27 | 142 | fn end_with_timestamp(&mut self, timestamp: SystemTime) { | ^^^^^^^^^ types differ in mutability | ::: opentelemetry\src\api\trace\span.rs:165:27 | 165 | fn end_with_timestamp(&self, timestamp: SystemTime); | ----- type in trait | = note: expected fn pointer `fn(&sdk::trace::span::Span, std::time::SystemTime)` found fn pointer `fn(&mut sdk::trace::span::Span, std::time::SystemTime)` |
@morigs I believe drop has to be on impl SpanInner {
fn end_with_timestamp(&self, timestamp: Option<SystemTime>) {
// Calling end on unsampled span or already ended span is ignored
if let Some(data) = &self.data {
if let Ok(mut span_data) = data.lock().map(|mut data| data.take()) {
// Ensure end time is set via explicit end or implicitly on drop
if let Some(span_data) = span_data.as_mut() {
if let Some(timestamp) = timestamp {
span_data.end_time = timestamp;
} else if span_data.end_time == span_data.start_time {
span_data.end_time = SystemTime::now();
}
}
// Notify each span processor that the span has ended
if let Some(provider) = self.tracer.provider() {
let mut processors = provider.span_processors().iter().peekable();
while let Some(processor) = processors.next() {
let span_data = if processors.peek().is_none() {
// last loop or single processor/exporter, move data
span_data.take()
} else {
// clone so each exporter gets owned data
span_data.clone()
};
if let Some(span_data) = span_data {
processor.on_end(build_export_data(
span_data,
self.span_context.clone(),
&self.tracer,
));
}
}
}
}
}
}
} |
See open-telemetry/opentelemetry-specification#1011 for details.
The text was updated successfully, but these errors were encountered: