Skip to content

Commit ee2faa3

Browse files
Shikugawawu-sheng
andauthored
enable to update span's operation name (#90)
Co-authored-by: 吴晟 Wu Sheng <[email protected]>
1 parent 6baf3c3 commit ee2faa3

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

cpp2sky/tracing_context.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ class TracingSpan {
174174
*/
175175
virtual void setComponentId(int32_t component_id) = 0;
176176

177+
/**
178+
* Set operation name.
179+
*/
180+
virtual void setOperationName(std::string_view operation_name) = 0;
181+
177182
/**
178183
* This span had finished or not.
179184
*/

source/tracing_context_impl.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ void TracingSpanImpl::setComponentId(int32_t component_id) {
144144
component_id_ = component_id;
145145
}
146146

147+
void TracingSpanImpl::setOperationName(std::string_view name) {
148+
assert(!finished_);
149+
operation_name_ = name;
150+
}
151+
147152
TracingContextImpl::TracingContextImpl(const std::string& service_name,
148153
const std::string& instance_name,
149154
RandomGenerator& random)

source/tracing_context_impl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class TracingSpanImpl : public TracingSpan {
8585
void addLog(std::string_view key, std::string_view value,
8686
TimePoint<SteadyTime> current_time) override;
8787
void setComponentId(int32_t component_id) override;
88+
void setOperationName(std::string_view name) override;
8889

8990
private:
9091
// Based on

test/tracing_context_test.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ TEST_F(TracingContextTest, ChildSegmentContext) {
145145

146146
span->startSpan("sample1", t1);
147147
span->setPeer("localhost:9000");
148+
span->setOperationName("sample11");
148149
span->endSpan(t2);
149150

150151
std::string json = R"EOF(
@@ -168,7 +169,7 @@ TEST_F(TracingContextTest, ChildSegmentContext) {
168169
"spanLayer": "Http",
169170
"componentId": "9000",
170171
"skipAnalysis": "false",
171-
"operationName": "sample1",
172+
"operationName": "sample11",
172173
}
173174
)EOF";
174175
skywalking::v3::SpanObject expected_obj;

0 commit comments

Comments
 (0)