Skip to content

Commit 181ac82

Browse files
authored
Fix clippy warnings and deny them in CI (#453)
1 parent 47095f0 commit 181ac82

File tree

6 files changed

+85
-82
lines changed

6 files changed

+85
-82
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,21 @@ jobs:
2323
- name: Test
2424
run: ./scripts/test.sh
2525
lint:
26-
strategy:
27-
matrix:
28-
rust: [stable, beta]
2926
runs-on: ubuntu-latest
3027
steps:
3128
- uses: actions/checkout@v1
3229
with:
3330
submodules: true
3431
- uses: actions-rs/toolchain@v1
3532
with:
36-
toolchain: ${{ matrix.rust }}
33+
toolchain: stable
3734
components: rustfmt
3835
profile: minimal
3936
- uses: arduino/setup-protoc@v1
37+
- uses: actions-rs/cargo@v1
38+
with:
39+
command: fmt
40+
args: --all -- --check
4041
- name: Lint
4142
run: ./scripts/lint.sh
4243
msrv:
@@ -55,7 +56,7 @@ jobs:
5556
cargo test --verbose --manifest-path=opentelemetry/Cargo.toml --features trace,metrics,serialize,tokio-support,serde,testing &&
5657
cargo test --manifest-path=opentelemetry-jaeger/Cargo.toml &&
5758
cargo test --manifest-path=opentelemetry-zipkin/Cargo.toml
58-
meta:
59+
coverage:
5960
continue-on-error: true
6061
runs-on: ubuntu-latest
6162
steps:
@@ -65,7 +66,6 @@ jobs:
6566
- uses: actions-rs/toolchain@v1
6667
with:
6768
toolchain: nightly
68-
components: rustfmt, clippy
6969
override: true
7070
- uses: arduino/setup-protoc@v1
7171
- uses: actions-rs/cargo@v1
@@ -78,8 +78,3 @@ jobs:
7878
RUSTDOCFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests'
7979
- uses: actions-rs/[email protected]
8080
- uses: codecov/codecov-action@v1
81-
- run: cargo fmt -- --check
82-
- uses: actions-rs/clippy-check@v1
83-
with:
84-
token: ${{ secrets.GITHUB_TOKEN }}
85-
args: --all-features --workspace

opentelemetry-jaeger/src/exporter/mod.rs

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use opentelemetry::{
2626
global, sdk,
2727
sdk::export::trace,
2828
trace::{Event, Link, SpanKind, StatusCode, TracerProvider},
29-
Key, KeyValue, Value,
29+
Key, KeyValue,
3030
};
3131
#[cfg(feature = "collector_client")]
3232
use opentelemetry_http::HttpClient;
@@ -86,15 +86,6 @@ pub struct Process {
8686
pub tags: Vec<KeyValue>,
8787
}
8888

89-
impl Into<jaeger::Process> for Process {
90-
fn into(self) -> jaeger::Process {
91-
jaeger::Process::new(
92-
self.service_name,
93-
Some(self.tags.into_iter().map(Into::into).collect()),
94-
)
95-
}
96-
}
97-
9889
#[async_trait]
9990
impl trace::SpanExporter for Exporter {
10091
/// Export spans to Jaeger
@@ -447,48 +438,6 @@ impl surf::middleware::Middleware for BasicAuthMiddleware {
447438
}
448439
}
449440

450-
#[rustfmt::skip]
451-
impl Into<jaeger::Tag> for KeyValue {
452-
fn into(self) -> jaeger::Tag {
453-
let KeyValue { key, value } = self;
454-
match value {
455-
Value::String(s) => jaeger::Tag::new(key.into(), jaeger::TagType::String, Some(s.into()), None, None, None, None),
456-
Value::F64(f) => jaeger::Tag::new(key.into(), jaeger::TagType::Double, None, Some(f.into()), None, None, None),
457-
Value::Bool(b) => jaeger::Tag::new(key.into(), jaeger::TagType::Bool, None, None, Some(b), None, None),
458-
Value::I64(i) => jaeger::Tag::new(key.into(), jaeger::TagType::Long, None, None, None, Some(i), None),
459-
// TODO: better Array handling, jaeger thrift doesn't support arrays
460-
v @ Value::Array(_) => jaeger::Tag::new(key.into(), jaeger::TagType::String, Some(v.to_string()), None, None, None, None),
461-
}
462-
}
463-
}
464-
465-
impl Into<jaeger::Log> for Event {
466-
fn into(self) -> jaeger::Log {
467-
let timestamp = self
468-
.timestamp
469-
.duration_since(SystemTime::UNIX_EPOCH)
470-
.unwrap_or_else(|_| Duration::from_secs(0))
471-
.as_micros() as i64;
472-
let mut event_set_via_attribute = false;
473-
let mut fields = self
474-
.attributes
475-
.into_iter()
476-
.map(|attr| {
477-
if attr.key.as_str() == "event" {
478-
event_set_via_attribute = true;
479-
};
480-
attr.into()
481-
})
482-
.collect::<Vec<_>>();
483-
484-
if !event_set_via_attribute {
485-
fields.push(Key::new("event").string(self.name).into());
486-
}
487-
488-
jaeger::Log::new(timestamp, fields)
489-
}
490-
}
491-
492441
fn links_to_references(links: sdk::trace::EvictedQueue<Link>) -> Option<Vec<jaeger::SpanRef>> {
493442
if !links.is_empty() {
494443
let refs = links
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,62 @@
11
//! Thrift generated Jaeger client
22
//!
33
//! Definitions: https://github.com/uber/jaeger-idl/blob/master/thrift/
4+
use std::time::{Duration, SystemTime};
5+
6+
use opentelemetry::trace::Event;
7+
use opentelemetry::{Key, KeyValue, Value};
8+
49
pub(crate) mod agent;
510
pub(crate) mod jaeger;
611
pub(crate) mod zipkincore;
12+
13+
impl From<super::Process> for jaeger::Process {
14+
fn from(process: super::Process) -> jaeger::Process {
15+
jaeger::Process::new(
16+
process.service_name,
17+
Some(process.tags.into_iter().map(Into::into).collect()),
18+
)
19+
}
20+
}
21+
22+
impl From<Event> for jaeger::Log {
23+
fn from(event: crate::exporter::Event) -> jaeger::Log {
24+
let timestamp = event
25+
.timestamp
26+
.duration_since(SystemTime::UNIX_EPOCH)
27+
.unwrap_or_else(|_| Duration::from_secs(0))
28+
.as_micros() as i64;
29+
let mut event_set_via_attribute = false;
30+
let mut fields = event
31+
.attributes
32+
.into_iter()
33+
.map(|attr| {
34+
if attr.key.as_str() == "event" {
35+
event_set_via_attribute = true;
36+
};
37+
attr.into()
38+
})
39+
.collect::<Vec<_>>();
40+
41+
if !event_set_via_attribute {
42+
fields.push(Key::new("event").string(event.name).into());
43+
}
44+
45+
jaeger::Log::new(timestamp, fields)
46+
}
47+
}
48+
49+
#[rustfmt::skip]
50+
impl From<KeyValue> for jaeger::Tag {
51+
fn from(kv: KeyValue) -> jaeger::Tag {
52+
let KeyValue { key, value } = kv;
53+
match value {
54+
Value::String(s) => jaeger::Tag::new(key.into(), jaeger::TagType::String, Some(s.into()), None, None, None, None),
55+
Value::F64(f) => jaeger::Tag::new(key.into(), jaeger::TagType::Double, None, Some(f.into()), None, None, None),
56+
Value::Bool(b) => jaeger::Tag::new(key.into(), jaeger::TagType::Bool, None, None, Some(b), None, None),
57+
Value::I64(i) => jaeger::Tag::new(key.into(), jaeger::TagType::Long, None, None, None, Some(i), None),
58+
// TODO: better Array handling, jaeger thrift doesn't support arrays
59+
v @ Value::Array(_) => jaeger::Tag::new(key.into(), jaeger::TagType::String, Some(v.to_string()), None, None, None, None),
60+
}
61+
}
62+
}

opentelemetry-zipkin/src/exporter/model/annotation.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
use std::time::{Duration, SystemTime};
2+
3+
use opentelemetry::trace::Event;
14
use serde::Serialize;
25

36
#[derive(TypedBuilder, Clone, Debug, Serialize)]
47
#[serde(rename_all = "camelCase")]
5-
pub struct Annotation {
8+
pub(crate) struct Annotation {
69
#[builder(setter(strip_option), default)]
710
#[serde(skip_serializing_if = "Option::is_none")]
811
timestamp: Option<u64>,
@@ -11,6 +14,22 @@ pub struct Annotation {
1114
value: Option<String>,
1215
}
1316

17+
/// Converts `Event` into an `annotation::Annotation`
18+
impl From<Event> for Annotation {
19+
fn from(event: Event) -> Annotation {
20+
let timestamp = event
21+
.timestamp
22+
.duration_since(SystemTime::UNIX_EPOCH)
23+
.unwrap_or_else(|_| Duration::from_secs(0))
24+
.as_micros() as u64;
25+
26+
Annotation::builder()
27+
.timestamp(timestamp)
28+
.value(event.name)
29+
.build()
30+
}
31+
}
32+
1433
#[cfg(test)]
1534
mod tests {
1635
use crate::exporter::model::annotation::Annotation;

opentelemetry-zipkin/src/exporter/model/mod.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use opentelemetry::{
22
sdk::export::trace,
3-
trace::{Event, SpanKind, StatusCode},
3+
trace::{SpanKind, StatusCode},
44
Key, KeyValue,
55
};
66
use std::collections::HashMap;
@@ -17,22 +17,6 @@ const INSTRUMENTATION_LIBRARY_VERSION: &str = "otel.library.version";
1717
const OTEL_ERROR_DESCRIPTION: &str = "error";
1818
const OTEL_STATUS_CODE: &str = "otel.status_code";
1919

20-
/// Converts `Event` into an `annotation::Annotation`
21-
impl Into<annotation::Annotation> for Event {
22-
fn into(self) -> annotation::Annotation {
23-
let timestamp = self
24-
.timestamp
25-
.duration_since(SystemTime::UNIX_EPOCH)
26-
.unwrap_or_else(|_| Duration::from_secs(0))
27-
.as_micros() as u64;
28-
29-
annotation::Annotation::builder()
30-
.timestamp(timestamp)
31-
.value(self.name)
32-
.build()
33-
}
34-
}
35-
3620
/// Converts StatusCode to Option<&'static str>
3721
/// `Unset` status code is unused.
3822
fn from_statuscode_to_str(status_code: StatusCode) -> Option<&'static str> {

opentelemetry/src/trace/span_context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ impl FromStr for TraceState {
302302
}
303303
}
304304

305-
Ok(TraceState::from_key_value(key_value_pairs)?)
305+
TraceState::from_key_value(key_value_pairs)
306306
}
307307
}
308308

0 commit comments

Comments
 (0)