Skip to content

Commit 94ca5bb

Browse files
committed
Fix workspace assumptions, format, and fix unused warnings
1 parent b2b3329 commit 94ca5bb

File tree

10 files changed

+58
-45
lines changed

10 files changed

+58
-45
lines changed

tracing-actix-web/Cargo.toml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@ readme = "README.md"
1515
description = "Structured logging middleware for actix-web."
1616
keywords = ["http", "actix-web", "tracing", "logging"]
1717
categories = ["asynchronous", "web-programming"]
18-
19-
repository.workspace = true
20-
homepage.workspace = true
21-
license.workspace = true
22-
edition.workspace = true
23-
rust-version.workspace = true
18+
repository = "https://github.com/actix/actix-extras"
19+
homepage = "https://actix.rs"
20+
license = "MIT OR Apache-2.0"
21+
edition = "2021"
22+
rust-version = "1.82"
2423

2524
[features]
2625
default = ["emit_event_on_error"]

tracing-actix-web/examples/custom-root-span/src/main.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
use actix_web::body::MessageBody;
2-
use actix_web::dev::{ServiceRequest, ServiceResponse};
3-
use actix_web::{web, App, Error, HttpServer};
4-
use opentelemetry::trace::TracerProvider;
5-
use opentelemetry::{global, KeyValue};
1+
use std::{io, sync::LazyLock};
2+
3+
use actix_web::{
4+
body::MessageBody,
5+
dev::{ServiceRequest, ServiceResponse},
6+
web, App, Error, HttpServer,
7+
};
8+
use opentelemetry::{global, trace::TracerProvider, KeyValue};
69
use opentelemetry_otlp::WithExportConfig;
710
use opentelemetry_sdk::{propagation::TraceContextPropagator, Resource};
811
use opentelemetry_semantic_conventions::resource;
9-
use std::io;
10-
use std::sync::LazyLock;
1112
use tracing::Span;
1213
use tracing_actix_web::{DefaultRootSpanBuilder, RootSpan, RootSpanBuilder, TracingLogger};
1314
use tracing_bunyan_formatter::{BunyanFormattingLayer, JsonStorageLayer};

tracing-actix-web/examples/opentelemetry/src/main.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1+
use std::{io, sync::LazyLock};
2+
13
use actix_web::{web, App, HttpServer};
2-
use opentelemetry::trace::TracerProvider;
3-
use opentelemetry::{global, KeyValue};
4+
use opentelemetry::{global, trace::TracerProvider, KeyValue};
45
use opentelemetry_otlp::WithExportConfig;
56
use opentelemetry_sdk::{propagation::TraceContextPropagator, Resource};
67
use opentelemetry_semantic_conventions::resource;
7-
use std::io;
8-
use std::sync::LazyLock;
98
use tracing_actix_web::TracingLogger;
109
use tracing_bunyan_formatter::{BunyanFormattingLayer, JsonStorageLayer};
1110
use tracing_subscriber::{layer::SubscriberExt, EnvFilter, Registry};

tracing-actix-web/examples/request-id-response-header/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
use std::io;
2+
13
use actix_web::{
24
dev::Service,
35
http::header::{HeaderName, HeaderValue},
46
web, App, HttpMessage, HttpServer,
57
};
6-
use std::io;
78
use tracing_actix_web::{RequestId, TracingLogger};
89

910
async fn hello() -> &'static str {

tracing-actix-web/src/middleware.rs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
1-
use crate::{DefaultRootSpanBuilder, RequestId, RootSpan, RootSpanBuilder};
2-
use actix_web::body::{BodySize, MessageBody};
3-
use actix_web::dev::{Service, ServiceRequest, ServiceResponse, Transform};
4-
use actix_web::http::StatusCode;
5-
use actix_web::web::Bytes;
6-
use actix_web::{Error, HttpMessage, ResponseError};
7-
use std::future::{ready, Future, Ready};
8-
use std::pin::Pin;
9-
use std::task::{Context, Poll};
1+
use std::{
2+
future::{ready, Future, Ready},
3+
pin::Pin,
4+
task::{Context, Poll},
5+
};
6+
7+
use actix_web::{
8+
body::{BodySize, MessageBody},
9+
dev::{Service, ServiceRequest, ServiceResponse, Transform},
10+
web::Bytes,
11+
Error, HttpMessage,
12+
};
1013
use tracing::Span;
1114

15+
use crate::{DefaultRootSpanBuilder, RequestId, RootSpan, RootSpanBuilder};
16+
1217
/// `TracingLogger` is a middleware to capture structured diagnostic when processing an HTTP request.
1318
/// Check the crate-level documentation for an in-depth introduction.
1419
///
1520
/// `TracingLogger` is designed as a drop-in replacement of [`actix-web`]'s [`Logger`].
1621
///
1722
/// # Usage
1823
///
19-
/// Register `TracingLogger` as a middleware for your application using `.wrap` on `App`.
24+
/// Register `TracingLogger` as a middleware for your application using `.wrap` on `App`.
2025
/// In this example we add a [`tracing::Subscriber`] to output structured logs to the console.
2126
///
2227
/// ```rust
@@ -235,6 +240,7 @@ where
235240
}
236241
}
237242

243+
#[cfg(feature = "emit_event_on_error")]
238244
fn emit_event_on_error<B: 'static>(outcome: &Result<ServiceResponse<B>, actix_web::Error>) {
239245
match outcome {
240246
Ok(response) => {
@@ -250,7 +256,11 @@ fn emit_event_on_error<B: 'static>(outcome: &Result<ServiceResponse<B>, actix_we
250256
}
251257
}
252258

253-
fn emit_error_event(response_error: &dyn ResponseError, status_code: StatusCode) {
259+
#[cfg(feature = "emit_event_on_error")]
260+
fn emit_error_event(
261+
response_error: &dyn actix_web::ResponseError,
262+
status_code: actix_web::http::StatusCode,
263+
) {
254264
let error_msg_prefix = "Error encountered while processing the incoming HTTP request";
255265
if status_code.is_client_error() {
256266
tracing::warn!("{}: {:?}", error_msg_prefix, response_error);

tracing-actix-web/src/otel.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use actix_web::dev::ServiceRequest;
2-
2+
use opentelemetry::propagation::Extractor;
33
#[cfg(feature = "opentelemetry_0_13")]
44
use opentelemetry_0_13_pkg as opentelemetry;
55
#[cfg(feature = "opentelemetry_0_14")]
@@ -38,7 +38,6 @@ use opentelemetry_0_29_pkg as opentelemetry;
3838
use opentelemetry_0_30_pkg as opentelemetry;
3939
#[cfg(feature = "opentelemetry_0_31")]
4040
use opentelemetry_0_31_pkg as opentelemetry;
41-
4241
#[cfg(feature = "opentelemetry_0_13")]
4342
use tracing_opentelemetry_0_12_pkg as tracing_opentelemetry;
4443
#[cfg(feature = "opentelemetry_0_14")]
@@ -78,8 +77,6 @@ use tracing_opentelemetry_0_31_pkg as tracing_opentelemetry;
7877
#[cfg(feature = "opentelemetry_0_31")]
7978
use tracing_opentelemetry_0_32_pkg as tracing_opentelemetry;
8079

81-
use opentelemetry::propagation::Extractor;
82-
8380
pub(crate) struct RequestHeaderCarrier<'a> {
8481
headers: &'a actix_web::http::header::HeaderMap,
8582
}

tracing-actix-web/src/request_id.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use actix_web::{dev::Payload, HttpMessage};
2-
use actix_web::{FromRequest, HttpRequest, ResponseError};
31
use std::future::{ready, Ready};
2+
3+
use actix_web::{dev::Payload, FromRequest, HttpMessage, HttpRequest, ResponseError};
44
use uuid::Uuid;
55

66
/// A unique identifier generated for each incoming request.

tracing-actix-web/src/root_span.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use actix_web::{dev::Payload, HttpMessage};
2-
use actix_web::{FromRequest, HttpRequest, ResponseError};
31
use std::future::{ready, Ready};
2+
3+
use actix_web::{dev::Payload, FromRequest, HttpMessage, HttpRequest, ResponseError};
44
use tracing::Span;
55

66
#[derive(Clone)]

tracing-actix-web/src/root_span_builder.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
use crate::root_span;
2-
use actix_web::body::MessageBody;
3-
use actix_web::dev::{ServiceRequest, ServiceResponse};
4-
use actix_web::http::StatusCode;
5-
use actix_web::{Error, ResponseError};
1+
use actix_web::{
2+
body::MessageBody,
3+
dev::{ServiceRequest, ServiceResponse},
4+
http::StatusCode,
5+
Error, ResponseError,
6+
};
67
use tracing::Span;
78

9+
use crate::root_span;
10+
811
/// `RootSpanBuilder` allows you to customise the root span attached by
912
/// [`TracingLogger`] to incoming requests.
1013
///

tracing-actix-web/src/root_span_macro.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,16 @@ pub mod private {
142142
//! in the code generated by the `root_span` macro.
143143
//! Items in this module are not part of the public interface of `tracing-actix-web` - they are considered
144144
//! implementation details and will change without notice in patch, minor and major releases.
145-
use crate::RequestId;
146-
use actix_web::dev::ServiceRequest;
147-
use actix_web::http::{Method, Version};
148145
use std::borrow::Cow;
149146

147+
use actix_web::{
148+
dev::ServiceRequest,
149+
http::{Method, Version},
150+
};
150151
pub use tracing;
151152

153+
use crate::RequestId;
154+
152155
#[doc(hidden)]
153156
// We need to allow unused variables because the function
154157
// body is empty if the user of the library chose not to activate

0 commit comments

Comments
 (0)