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

override sampling decision #338

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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 opencensus/trace/internal/span.cc
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ const SpanContext& Span::context() const { return context_; }

bool Span::IsSampled() const { return context_.trace_options().IsSampled(); }

void Span::StopRecording() { span_impl_ = nullptr; }
Copy link
Contributor

Choose a reason for hiding this comment

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

This approach will not work, it prevents Span::End from doing:

exporter::RunningSpanStoreImpl::Get()->RemoveSpan(span_impl_);

(i.e. leaks memory)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ouch. I was not aware of the mechanics of memory management here

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm sorry. I wish things were simple.


bool Span::IsRecording() const { return span_impl_ != nullptr; }

void swap(Span& a, Span& b) {
Expand Down
5 changes: 5 additions & 0 deletions opencensus/trace/span.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ class Span final {
// Sampled spans always record events.
bool IsSampled() const;

// Stops recording the span and overrides the sampling decision to false.
// This should be used by the client to force disable sampling in support of
// delayed sampling decisions (e.g. health check URI blacklist).
void StopRecording();

// Returns true if the Span is recording events (will appear in Span stores).
// Sampled spans always record events, but not all Spans that are recording
// are sampled.
Expand Down