From ee2faa37227315aa544731805c25a5f0b65555dc Mon Sep 17 00:00:00 2001 From: Rei Shimizu Date: Tue, 22 Mar 2022 22:49:46 +0900 Subject: [PATCH] enable to update span's operation name (#90) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 吴晟 Wu Sheng --- cpp2sky/tracing_context.h | 5 +++++ source/tracing_context_impl.cc | 5 +++++ source/tracing_context_impl.h | 1 + test/tracing_context_test.cc | 3 ++- 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/cpp2sky/tracing_context.h b/cpp2sky/tracing_context.h index 21bbdc7..7a54576 100644 --- a/cpp2sky/tracing_context.h +++ b/cpp2sky/tracing_context.h @@ -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. */ diff --git a/source/tracing_context_impl.cc b/source/tracing_context_impl.cc index f6b169b..2b6720c 100644 --- a/source/tracing_context_impl.cc +++ b/source/tracing_context_impl.cc @@ -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) diff --git a/source/tracing_context_impl.h b/source/tracing_context_impl.h index 9cb6045..818d676 100644 --- a/source/tracing_context_impl.h +++ b/source/tracing_context_impl.h @@ -85,6 +85,7 @@ class TracingSpanImpl : public TracingSpan { void addLog(std::string_view key, std::string_view value, TimePoint current_time) override; void setComponentId(int32_t component_id) override; + void setOperationName(std::string_view name) override; private: // Based on diff --git a/test/tracing_context_test.cc b/test/tracing_context_test.cc index 7632531..4a06e1a 100644 --- a/test/tracing_context_test.cc +++ b/test/tracing_context_test.cc @@ -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( @@ -168,7 +169,7 @@ TEST_F(TracingContextTest, ChildSegmentContext) { "spanLayer": "Http", "componentId": "9000", "skipAnalysis": "false", - "operationName": "sample1", + "operationName": "sample11", } )EOF"; skywalking::v3::SpanObject expected_obj;