Skip to content

Commit

Permalink
enable to update span's operation name (#90)
Browse files Browse the repository at this point in the history
Co-authored-by: 吴晟 Wu Sheng <[email protected]>
  • Loading branch information
Shikugawa and wu-sheng authored Mar 22, 2022
1 parent 6baf3c3 commit ee2faa3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions cpp2sky/tracing_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ class TracingSpan {
*/
virtual void setComponentId(int32_t component_id) = 0;

/**
* Set operation name.
*/
virtual void setOperationName(std::string_view operation_name) = 0;

/**
* This span had finished or not.
*/
Expand Down
5 changes: 5 additions & 0 deletions source/tracing_context_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ void TracingSpanImpl::setComponentId(int32_t component_id) {
component_id_ = component_id;
}

void TracingSpanImpl::setOperationName(std::string_view name) {
assert(!finished_);
operation_name_ = name;
}

TracingContextImpl::TracingContextImpl(const std::string& service_name,
const std::string& instance_name,
RandomGenerator& random)
Expand Down
1 change: 1 addition & 0 deletions source/tracing_context_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class TracingSpanImpl : public TracingSpan {
void addLog(std::string_view key, std::string_view value,
TimePoint<SteadyTime> current_time) override;
void setComponentId(int32_t component_id) override;
void setOperationName(std::string_view name) override;

private:
// Based on
Expand Down
3 changes: 2 additions & 1 deletion test/tracing_context_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ TEST_F(TracingContextTest, ChildSegmentContext) {

span->startSpan("sample1", t1);
span->setPeer("localhost:9000");
span->setOperationName("sample11");
span->endSpan(t2);

std::string json = R"EOF(
Expand All @@ -168,7 +169,7 @@ TEST_F(TracingContextTest, ChildSegmentContext) {
"spanLayer": "Http",
"componentId": "9000",
"skipAnalysis": "false",
"operationName": "sample1",
"operationName": "sample11",
}
)EOF";
skywalking::v3::SpanObject expected_obj;
Expand Down

0 comments on commit ee2faa3

Please sign in to comment.