Skip to content

Commit

Permalink
Move skywalking_proto mod to single files. (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmjoy committed Jul 21, 2022
1 parent e8aba5a commit 3d12768
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 27 deletions.
24 changes: 3 additions & 21 deletions src/context/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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))
}
}

Expand Down
7 changes: 1 addition & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
16 changes: 16 additions & 0 deletions src/skywalking_proto/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// 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.
//
pub mod v3;
51 changes: 51 additions & 0 deletions src/skywalking_proto/v3/mod.rs
Original file line number Diff line number Diff line change
@@ -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(),
});
}
}

0 comments on commit 3d12768

Please sign in to comment.