You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2022/07/21 13:04:25 UTC

[skywalking-rust] branch master updated: Move skywalking_proto mod to single files. (#33)

This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking-rust.git


The following commit(s) were added to refs/heads/master by this push:
     new 3d12768  Move skywalking_proto mod to single files. (#33)
3d12768 is described below

commit 3d12768d2c1123418a6f7cc7b9a4c768ef14fc0c
Author: jmjoy <91...@qq.com>
AuthorDate: Thu Jul 21 21:04:20 2022 +0800

    Move skywalking_proto mod to single files. (#33)
---
 src/context/span.rs                     | 24 ++--------------
 src/lib.rs                              |  7 +----
 src/{lib.rs => skywalking_proto/mod.rs} | 17 +----------
 src/skywalking_proto/v3/mod.rs          | 51 +++++++++++++++++++++++++++++++++
 4 files changed, 56 insertions(+), 43 deletions(-)

diff --git a/src/context/span.rs b/src/context/span.rs
index c6c5e18..06b4bb9 100644
--- a/src/context/span.rs
+++ b/src/context/span.rs
@@ -14,7 +14,7 @@
 // limitations under the License.
 //
 
-use crate::skywalking_proto::v3::{KeyStringValuePair, Log, SpanLayer, SpanObject, SpanType};
+use crate::skywalking_proto::v3::{SpanLayer, SpanObject, SpanType};
 use std::fmt::Formatter;
 
 use super::{
@@ -141,30 +141,12 @@ impl Span {
         V: ToString,
         I: IntoIterator<Item = (K, V)>,
     {
-        let log = Log {
-            time: fetch_time(TimePeriod::Log),
-            data: message
-                .into_iter()
-                .map(|v| {
-                    let (key, value) = v;
-                    KeyStringValuePair {
-                        key: key.to_string(),
-                        value: value.to_string(),
-                    }
-                })
-                .collect(),
-        };
-        self.with_span_object_mut(|span| span.logs.push(log));
+        self.with_span_object_mut(|span| span.add_log(message))
     }
 
     /// Add tag to the span.
     pub fn add_tag(&mut self, key: impl ToString, value: impl ToString) {
-        self.with_span_object_mut(|span| {
-            span.tags.push(KeyStringValuePair {
-                key: key.to_string(),
-                value: value.to_string(),
-            })
-        })
+        self.with_span_object_mut(|span| span.add_tag(key, value))
     }
 }
 
diff --git a/src/lib.rs b/src/lib.rs
index 235d015..4bcb6b7 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -17,15 +17,10 @@
 #![warn(clippy::dbg_macro, clippy::print_stdout)]
 #![doc = include_str!("../README.md")]
 
-pub mod skywalking_proto {
-    pub mod v3 {
-        tonic::include_proto!("skywalking.v3");
-    }
-}
-
 pub mod common;
 pub mod context;
 pub(crate) mod error;
 pub mod reporter;
+pub mod skywalking_proto;
 
 pub use error::{Error, Result};
diff --git a/src/lib.rs b/src/skywalking_proto/mod.rs
similarity index 71%
copy from src/lib.rs
copy to src/skywalking_proto/mod.rs
index 235d015..c3e1141 100644
--- a/src/lib.rs
+++ b/src/skywalking_proto/mod.rs
@@ -13,19 +13,4 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 //
-#![warn(rust_2018_idioms)]
-#![warn(clippy::dbg_macro, clippy::print_stdout)]
-#![doc = include_str!("../README.md")]
-
-pub mod skywalking_proto {
-    pub mod v3 {
-        tonic::include_proto!("skywalking.v3");
-    }
-}
-
-pub mod common;
-pub mod context;
-pub(crate) mod error;
-pub mod reporter;
-
-pub use error::{Error, Result};
+pub mod v3;
diff --git a/src/skywalking_proto/v3/mod.rs b/src/skywalking_proto/v3/mod.rs
new file mode 100644
index 0000000..cd8302a
--- /dev/null
+++ b/src/skywalking_proto/v3/mod.rs
@@ -0,0 +1,51 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+use crate::context::system_time::{fetch_time, TimePeriod};
+
+tonic::include_proto!("skywalking.v3");
+
+impl SpanObject {
+    /// Add logs to the span.
+    pub fn add_log<K, V, I>(&mut self, message: I)
+    where
+        K: ToString,
+        V: ToString,
+        I: IntoIterator<Item = (K, V)>,
+    {
+        let log = Log {
+            time: fetch_time(TimePeriod::Log),
+            data: message
+                .into_iter()
+                .map(|v| {
+                    let (key, value) = v;
+                    KeyStringValuePair {
+                        key: key.to_string(),
+                        value: value.to_string(),
+                    }
+                })
+                .collect(),
+        };
+        self.logs.push(log);
+    }
+
+    /// Add tag to the span.
+    pub fn add_tag(&mut self, key: impl ToString, value: impl ToString) {
+        self.tags.push(KeyStringValuePair {
+            key: key.to_string(),
+            value: value.to_string(),
+        });
+    }
+}