Skip to content
This repository has been archived by the owner on Jan 26, 2024. It is now read-only.

SetTag when span finish #129

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
22 changes: 22 additions & 0 deletions include/opentracing/span.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ struct FinishSpanOptions {
// (or SystemTime::now() if finish_steady_timestamp is default-constructed).
// Otherwise the behavior of FinishWithOptions() is unspecified.
std::vector<LogRecord> log_records;

std::vector<std::pair<std::string, Value>> tags;
};

// FinishSpanOption instances (zero or more) may be passed to Span.Finish.
Expand Down Expand Up @@ -222,6 +224,26 @@ class FinishTimestamp : public FinishSpanOption {
private:
SteadyTime steady_when_;
};

class SetTagWhenFinish : public FinishSpanOption {
public:
SetTagWhenFinish(string_view key, const Value& value) noexcept
: key_(key), value_(value) {}

SetTagWhenFinish(const SetTagWhenFinish& other) noexcept
: FinishSpanOption(), key_(other.key_), value_(other.value_) {}

void Apply(FinishSpanOptions& options) const noexcept override {
try {
options.tags.emplace_back(key_, value_);
} catch (const std::bad_alloc&) {
}
}

private:
const string_view key_;
const Value& value_;
};
END_OPENTRACING_ABI_NAMESPACE
} // namespace opentracing

Expand Down