Skip to content
This repository was archived by the owner on Jul 31, 2023. It is now read-only.

Commit 848cd7b

Browse files
authored
Check for span ended within End() (#70)
Adding check for span ended in End() so it does not populate exporters with 2 copies of the span.
1 parent 1ee85ff commit 848cd7b

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

opencensus/trace/internal/span.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ void Span::SetStatus(StatusCode canonical_code, absl::string_view message) {
201201
}
202202

203203
void Span::End() {
204-
if (IsRecording()) {
204+
if (IsRecording() && !span_impl_->HasEnded()) {
205205
span_impl_->End();
206206
exporter::RunningSpanStoreImpl::Get()->RemoveSpan(span_impl_);
207207
exporter::LocalSpanStoreImpl::Get()->AddSpan(span_impl_);

opencensus/trace/internal/span_impl.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ void SpanImpl::SetStatus(exporter::Status&& status) {
136136

137137
void SpanImpl::End() { EndWithTime(absl::Now()); }
138138

139+
bool SpanImpl::HasEnded() const {
140+
absl::MutexLock l(&mu_);
141+
return has_ended_;
142+
}
143+
139144
void SpanImpl::EndWithLatencyForTesting(absl::Duration latency) {
140145
EndWithTime(start_time_ + latency);
141146
}

opencensus/trace/internal/span_impl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ class SpanImpl final {
8787

8888
// Marks the end of the Span and sets its end_time_.
8989
void End() LOCKS_EXCLUDED(mu_);
90+
// Returns true if the span has ended.
91+
bool HasEnded() const LOCKS_EXCLUDED(mu_);
9092

9193
absl::string_view name() const { return name_; }
9294

0 commit comments

Comments
 (0)