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

Commit 858195c

Browse files
kyessenovg-easy
authored andcommitted
Add Span::SetName() (#335)
1 parent a506cf8 commit 858195c

File tree

6 files changed

+28
-5
lines changed

6 files changed

+28
-5
lines changed

opencensus/trace/internal/span.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,12 @@ void Span::SetStatus(StatusCode canonical_code,
202202
}
203203
}
204204

205+
void Span::SetName(absl::string_view name) const {
206+
if (IsRecording()) {
207+
span_impl_->SetName(name);
208+
}
209+
}
210+
205211
void Span::End() const {
206212
if (IsRecording()) {
207213
if (!span_impl_->End()) {

opencensus/trace/internal/span_impl.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,13 @@ void SpanImpl::SetStatus(exporter::Status&& status) {
137137
}
138138
}
139139

140+
void SpanImpl::SetName(absl::string_view name) {
141+
absl::MutexLock l(&mu_);
142+
if (!has_ended_) {
143+
name_ = std::string(name);
144+
}
145+
}
146+
140147
bool SpanImpl::End() {
141148
absl::MutexLock l(&mu_);
142149
if (has_ended_) {

opencensus/trace/internal/span_impl.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ class SpanImpl final {
8585

8686
void SetStatus(exporter::Status&& status) LOCKS_EXCLUDED(mu_);
8787

88+
void SetName(absl::string_view name) LOCKS_EXCLUDED(mu_);
89+
8890
// Returns true on success (if this is the first time the Span has ended) and
8991
// also marks the end of the Span and sets its end_time_.
9092
bool End() LOCKS_EXCLUDED(mu_);
@@ -119,7 +121,7 @@ class SpanImpl final {
119121
// The status of the span. Only set if start_options_.record_events is true.
120122
exporter::Status status_ GUARDED_BY(mu_);
121123
// The displayed name of the span.
122-
const std::string name_;
124+
std::string name_ GUARDED_BY(mu_);
123125
// The parent SpanId of this span. Parent SpanId will be not valid if this is
124126
// a root span.
125127
const SpanId parent_span_id_;

opencensus/trace/internal/span_test.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ TEST(SpanTest, FullSpanTest) {
203203

204204
span.SetStatus(StatusCode::DEADLINE_EXCEEDED, "desc");
205205

206+
// Change span name
207+
span.SetName("NewSpanName");
208+
206209
EXPECT_TRUE(span.context().IsValid());
207210
span.End();
208211
// Add a few extra things and make sure they are NOT included since the span
@@ -213,7 +216,7 @@ TEST(SpanTest, FullSpanTest) {
213216

214217
const exporter::SpanData data = SpanTestPeer::ToSpanData(&span);
215218

216-
EXPECT_EQ("MyRootSpan", data.name());
219+
EXPECT_EQ("NewSpanName", data.name());
217220
EXPECT_EQ(parent.context().span_id(), data.parent_span_id());
218221
EXPECT_EQ(0, data.annotations().dropped_events_count());
219222
EXPECT_EQ(0, data.message_events().dropped_events_count());

opencensus/trace/span.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ class Span final {
154154
void SetStatus(StatusCode canonical_code,
155155
absl::string_view message = "") const;
156156

157+
// Set the span name.
158+
void SetName(absl::string_view name) const;
159+
157160
// Marks the end of a Span. No further changes can be made to the Span after
158161
// End is called.
159162
void End() const;

tools/travis/build_bazel.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ if [[ "$TRAVIS_COMPILER" = "clang" ]]; then
2727
export BAZEL_OPTIONS="$BAZEL_OPTIONS --copt=-Werror=thread-safety"
2828
fi
2929

30-
wget https://github.com/bazelbuild/bazel/releases/download/0.20.0/bazel-0.20.0-installer-${BAZEL_OS}-x86_64.sh
31-
chmod +x bazel-0.20.0-installer-${BAZEL_OS}-x86_64.sh
32-
./bazel-0.20.0-installer-${BAZEL_OS}-x86_64.sh --user
30+
export BAZEL_VERSION="0.24.1"
31+
32+
wget https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-installer-${BAZEL_OS}-x86_64.sh
33+
chmod +x bazel-${BAZEL_VERSION}-installer-${BAZEL_OS}-x86_64.sh
34+
./bazel-${BAZEL_VERSION}-installer-${BAZEL_OS}-x86_64.sh --user
3335
echo "build --disk_cache=$HOME/bazel-cache" > ~/.bazelrc
3436
echo "build --experimental_strict_action_env" >> ~/.bazelrc
3537
du -sk $HOME/bazel-cache || true

0 commit comments

Comments
 (0)