Skip to content

Commit 50f0bb8

Browse files
ci: run clippy on features separately to find issues (#2866)
Co-authored-by: Cijo Thomas <[email protected]>
1 parent da2029e commit 50f0bb8

File tree

12 files changed

+37
-10
lines changed

12 files changed

+37
-10
lines changed

.github/workflows/ci.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ jobs:
5858
submodules: true
5959
- uses: dtolnay/rust-toolchain@stable
6060
with:
61-
components: rustfmt
61+
components: rustfmt, clippy
62+
- uses: taiki-e/install-action@v2
63+
with:
64+
tool: cargo-hack
6265
- uses: arduino/setup-protoc@v3
6366
with:
6467
repo-token: ${{ secrets.GITHUB_TOKEN }}

examples/tracing-grpc/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ opentelemetry_sdk = { path = "../../opentelemetry-sdk", features = ["rt-tokio"]
2222
opentelemetry-stdout = { workspace = true, features = ["trace"] }
2323
prost = { workspace = true }
2424
tokio = { workspace = true, features = ["full"] }
25-
tonic = { workspace = true, features = ["server", "codegen", "channel", "prost"] }
25+
tonic = { workspace = true, features = ["server", "codegen", "channel", "prost", "router"] }
2626

2727
[build-dependencies]
2828
tonic-build = { workspace = true }

opentelemetry-otlp/src/exporter/tonic/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ impl Default for TonicExporterBuilder {
145145
}
146146

147147
impl TonicExporterBuilder {
148+
// This is for clippy to work with only the grpc-tonic feature enabled
149+
#[allow(unused)]
148150
fn build_channel(
149151
self,
150152
signal_endpoint_var: &str,

opentelemetry-otlp/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,8 @@ pub struct NoExporterBuilderSet;
370370
///
371371
/// Allowing access to [TonicExporterBuilder] specific configuration methods.
372372
#[cfg(feature = "grpc-tonic")]
373+
// This is for clippy to work with only the grpc-tonic feature enabled
374+
#[allow(unused)]
373375
#[derive(Debug, Default)]
374376
pub struct TonicExporterBuilderSet(TonicExporterBuilder);
375377

Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
pub mod logs_asserter;
2+
#[cfg(any(
3+
feature = "hyper-client",
4+
feature = "reqwest-client",
5+
feature = "reqwest-blocking-client",
6+
feature = "tonic-client"
7+
))]
28
pub mod metric_helpers;
39
pub mod test_utils;
410
pub mod trace_asserter;

opentelemetry-sdk/Cargo.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pprof = { version = "0.14", features = ["flamegraph", "criterion"] }
4343
[features]
4444
default = ["trace", "metrics", "logs", "internal-logs"]
4545
trace = ["opentelemetry/trace", "rand", "percent-encoding"]
46-
jaeger_remote_sampler = ["trace", "opentelemetry-http", "http", "serde", "serde_json", "url"]
46+
jaeger_remote_sampler = ["trace", "opentelemetry-http", "http", "serde", "serde_json", "url", "experimental_async_runtime"]
4747
logs = ["opentelemetry/logs", "serde_json"]
4848
spec_unstable_logs_enabled = ["logs", "opentelemetry/spec_unstable_logs_enabled"]
4949
metrics = ["opentelemetry/metrics", "glob"]
@@ -52,11 +52,11 @@ experimental_async_runtime = []
5252
rt-tokio = ["tokio", "tokio-stream", "experimental_async_runtime"]
5353
rt-tokio-current-thread = ["tokio", "tokio-stream", "experimental_async_runtime"]
5454
internal-logs = ["tracing"]
55-
experimental_metrics_periodicreader_with_async_runtime = ["metrics"]
55+
experimental_metrics_periodicreader_with_async_runtime = ["metrics", "experimental_async_runtime"]
5656
spec_unstable_metrics_views = ["metrics"]
57-
experimental_logs_batch_log_processor_with_async_runtime = ["logs"]
57+
experimental_logs_batch_log_processor_with_async_runtime = ["logs", "experimental_async_runtime"]
5858
experimental_logs_concurrent_log_processor = ["logs"]
59-
experimental_trace_batch_span_processor_with_async_runtime = ["trace"]
59+
experimental_trace_batch_span_processor_with_async_runtime = ["trace", "experimental_async_runtime"]
6060
experimental_metrics_disable_name_validation = ["metrics"]
6161

6262
[package.metadata.cargo-machete]

opentelemetry-sdk/src/logs/log_processor_with_async_runtime.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::{
66

77
use opentelemetry::{otel_debug, otel_error, otel_warn, InstrumentationScope};
88

9-
use std::env;
109
use std::{
1110
fmt::{self, Debug, Formatter},
1211
sync::Arc,
@@ -17,6 +16,7 @@ use std::{
1716
};
1817

1918
use super::{BatchConfig, LogProcessor};
19+
#[cfg(feature = "experimental_async_runtime")]
2020
use crate::runtime::{to_interval_stream, RuntimeChannel, TrySend};
2121
use futures_channel::oneshot;
2222
use futures_util::{

opentelemetry-zipkin/src/exporter/env.rs

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ const ENV_TIMEOUT: &str = "OTEL_EXPORTER_ZIPKIN_TIMEOUT";
1414
/// Default Zipkin timeout in milliseconds
1515
const DEFAULT_COLLECTOR_TIMEOUT: Duration = Duration::from_millis(10_000);
1616

17+
// This is for clippy to work with only the reqwest-rustls feature enabled
18+
#[allow(unused)]
1719
pub(crate) fn get_timeout() -> Duration {
1820
match env::var(ENV_TIMEOUT).ok().filter(|var| !var.is_empty()) {
1921
Some(timeout) => match timeout.parse() {

opentelemetry-zipkin/src/exporter/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ pub struct ZipkinExporterBuilder {
4141

4242
impl Default for ZipkinExporterBuilder {
4343
fn default() -> Self {
44+
#[cfg(any(feature = "reqwest-blocking-client", feature = "reqwest-client"))]
4445
let timeout = env::get_timeout();
4546

4647
ZipkinExporterBuilder {

opentelemetry/Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ tracing = {workspace = true, optional = true} # optional for opentelemetry inter
3232
js-sys = "0.3.63"
3333

3434
[features]
35-
default = ["trace", "metrics", "logs", "internal-logs"]
36-
trace = ["pin-project-lite", "futures-sink", "futures-core", "thiserror"]
35+
default = ["trace", "metrics", "logs", "internal-logs", "futures"]
36+
futures = ["futures-core", "futures-sink", "pin-project-lite"]
37+
trace = ["futures", "thiserror"]
3738
metrics = []
3839
testing = ["trace"]
3940
logs = []

opentelemetry/src/context.rs

+6
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ use std::hash::{BuildHasherDefault, Hasher};
2020
use std::marker::PhantomData;
2121
use std::sync::Arc;
2222

23+
#[cfg(feature = "futures")]
2324
mod future_ext;
2425

26+
#[cfg(feature = "futures")]
2527
pub use future_ext::FutureExt;
2628

2729
thread_local! {
@@ -428,6 +430,8 @@ impl Context {
428430
impl fmt::Debug for Context {
429431
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
430432
let mut dbg = f.debug_struct("Context");
433+
434+
#[cfg(feature = "trace")]
431435
let mut entries = self.entries.as_ref().map_or(0, |e| e.len());
432436
#[cfg(feature = "trace")]
433437
{
@@ -438,6 +442,8 @@ impl fmt::Debug for Context {
438442
dbg.field("span", &"None");
439443
}
440444
}
445+
#[cfg(not(feature = "trace"))]
446+
let entries = self.entries.as_ref().map_or(0, |e| e.len());
441447

442448
dbg.field("entries count", &entries)
443449
.field("suppress_telemetry", &self.suppress_telemetry)

scripts/lint.sh

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ cargo_feature() {
99
-Dwarnings
1010
}
1111

12-
if rustup component add clippy; then
12+
if rustup component add clippy && \
13+
((cargo --list | grep -q hack) || cargo install cargo-hack); then
1314
# Exit with a nonzero code if there are clippy warnings
1415
cargo clippy --workspace --all-targets --all-features -- -Dwarnings
1516
17+
# Run through all the features one by one and exit if there are clippy warnings
18+
cargo hack --each-feature --no-dev-deps clippy -- -Dwarnings
19+
1620
# `opentelemetry-prometheus` doesn't belong to the workspace
1721
cargo clippy --manifest-path=opentelemetry-prometheus/Cargo.toml --all-targets --all-features -- \
1822
-Dwarnings

0 commit comments

Comments
 (0)