From 46abc57e790d39ff31b6ca3c29e6f30b01c4bbca Mon Sep 17 00:00:00 2001 From: Fangdun Tsai Date: Fri, 27 Sep 2024 19:45:32 +0800 Subject: [PATCH] fix: update trace attributes --- Cargo.toml | 4 ++-- examples/compression/src/main.rs | 2 -- examples/cors/src/main.rs | 2 -- examples/csrf/src/main.rs | 2 -- examples/databases/sea-orm/src/main.rs | 2 -- examples/forms/form/src/main.rs | 2 -- examples/forms/multipart/src/main.rs | 2 -- examples/graceful-shutdown/src/main.rs | 2 -- examples/hello-world/src/main.rs | 2 -- examples/htmlx/src/main.rs | 2 -- examples/limits/src/main.rs | 2 -- examples/otel/metrics/src/main.rs | 2 -- examples/otel/tracing/src/main.rs | 1 - examples/routing/openapi/src/main.rs | 1 - examples/routing/todos/src/main.rs | 2 -- examples/rustls/src/main.rs | 2 -- examples/session/src/main.rs | 2 -- examples/sse/src/main.rs | 2 -- examples/static-files/embed/src/main.rs | 2 -- examples/static-files/include-dir/src/main.rs | 1 - examples/static-files/serve/src/main.rs | 2 -- examples/static-routes/src/main.rs | 2 -- examples/tracing/src/main.rs | 2 -- examples/unix-socket/src/main.rs | 1 - examples/websocket-chat/src/main.rs | 2 -- viz-core/src/middleware/otel/tracing.rs | 9 ++++++--- 26 files changed, 8 insertions(+), 49 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 60f8f7d4..87069d79 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -107,10 +107,10 @@ opentelemetry-otlp = { version = "0.25", default-features = false, features = [ "trace", "http-proto", ] } -opentelemetry-prometheus = { version = "0.16", features = [ +opentelemetry-semantic-conventions = { version = "0.25" } +opentelemetry-prometheus = { version = "0.17", features = [ "prometheus-encoding", ] } -opentelemetry-semantic-conventions = { version = "0.15" } prometheus = "0.13" # Tracing diff --git a/examples/compression/src/main.rs b/examples/compression/src/main.rs index 839b3a3a..0761916e 100644 --- a/examples/compression/src/main.rs +++ b/examples/compression/src/main.rs @@ -1,5 +1,3 @@ -#![deny(warnings)] - use std::net::SocketAddr; use tokio::net::TcpListener; diff --git a/examples/cors/src/main.rs b/examples/cors/src/main.rs index f62b84df..77e23496 100644 --- a/examples/cors/src/main.rs +++ b/examples/cors/src/main.rs @@ -1,5 +1,3 @@ -#![deny(warnings)] - use std::net::SocketAddr; use tokio::net::TcpListener; use viz::{get, middleware::cors, serve, Method, Request, Result, Router}; diff --git a/examples/csrf/src/main.rs b/examples/csrf/src/main.rs index e6878b35..fb76f1fe 100644 --- a/examples/csrf/src/main.rs +++ b/examples/csrf/src/main.rs @@ -1,5 +1,3 @@ -#![deny(warnings)] - use std::{net::SocketAddr, time::Duration}; use tokio::net::TcpListener; diff --git a/examples/databases/sea-orm/src/main.rs b/examples/databases/sea-orm/src/main.rs index ced916ca..5880f3a2 100644 --- a/examples/databases/sea-orm/src/main.rs +++ b/examples/databases/sea-orm/src/main.rs @@ -1,5 +1,3 @@ -#![deny(warnings)] - //! `SeaOrm` example for Viz framework. use sea_orm_example::{api, db::init_db}; use std::{env, net::SocketAddr, path::PathBuf}; diff --git a/examples/forms/form/src/main.rs b/examples/forms/form/src/main.rs index 9624979f..aec7e7ae 100644 --- a/examples/forms/form/src/main.rs +++ b/examples/forms/form/src/main.rs @@ -1,5 +1,3 @@ -#![deny(warnings)] - use serde::{Deserialize, Serialize}; use std::net::SocketAddr; use tokio::net::TcpListener; diff --git a/examples/forms/multipart/src/main.rs b/examples/forms/multipart/src/main.rs index 83e661d0..763bc5a8 100644 --- a/examples/forms/multipart/src/main.rs +++ b/examples/forms/multipart/src/main.rs @@ -1,5 +1,3 @@ -#![deny(warnings)] - use futures_util::TryStreamExt; use std::{fs::File, net::SocketAddr}; use tempfile::tempdir; diff --git a/examples/graceful-shutdown/src/main.rs b/examples/graceful-shutdown/src/main.rs index 3a2b112a..e03e72de 100644 --- a/examples/graceful-shutdown/src/main.rs +++ b/examples/graceful-shutdown/src/main.rs @@ -1,5 +1,3 @@ -#![deny(warnings)] - use std::net::SocketAddr; use tokio::net::TcpListener; use tokio::signal; diff --git a/examples/hello-world/src/main.rs b/examples/hello-world/src/main.rs index 9d6e7fa3..40e90d9e 100644 --- a/examples/hello-world/src/main.rs +++ b/examples/hello-world/src/main.rs @@ -1,5 +1,3 @@ -#![deny(warnings)] - use std::{net::SocketAddr, str::FromStr}; use tokio::net::TcpListener; use viz::{serve, Request, Result, Router}; diff --git a/examples/htmlx/src/main.rs b/examples/htmlx/src/main.rs index 91d2fd32..a0a69cb2 100644 --- a/examples/htmlx/src/main.rs +++ b/examples/htmlx/src/main.rs @@ -1,5 +1,3 @@ -// #![deny(warnings)] - use handlebars::{DirectorySourceOptions, Handlebars}; use serde::{Deserialize, Serialize}; use serde_json::json; diff --git a/examples/limits/src/main.rs b/examples/limits/src/main.rs index 0f2da782..2b12cd9e 100644 --- a/examples/limits/src/main.rs +++ b/examples/limits/src/main.rs @@ -1,5 +1,3 @@ -#![deny(warnings)] - use std::net::SocketAddr; use tokio::net::TcpListener; use viz::{ diff --git a/examples/otel/metrics/src/main.rs b/examples/otel/metrics/src/main.rs index 45195ea2..e2196e3f 100644 --- a/examples/otel/metrics/src/main.rs +++ b/examples/otel/metrics/src/main.rs @@ -1,5 +1,3 @@ -#![deny(warnings)] - use std::net::SocketAddr; use tokio::net::TcpListener; diff --git a/examples/otel/tracing/src/main.rs b/examples/otel/tracing/src/main.rs index f15e3b25..75fec38c 100644 --- a/examples/otel/tracing/src/main.rs +++ b/examples/otel/tracing/src/main.rs @@ -1,4 +1,3 @@ -#![deny(warnings)] #![allow(clippy::unused_async)] use opentelemetry::global; diff --git a/examples/routing/openapi/src/main.rs b/examples/routing/openapi/src/main.rs index 2a22f9b0..f51eb03a 100644 --- a/examples/routing/openapi/src/main.rs +++ b/examples/routing/openapi/src/main.rs @@ -1,4 +1,3 @@ -#![deny(warnings)] #![allow(clippy::unused_async)] #![allow(clippy::needless_pass_by_value)] diff --git a/examples/routing/todos/src/main.rs b/examples/routing/todos/src/main.rs index c0d2f1fc..1bf2f769 100644 --- a/examples/routing/todos/src/main.rs +++ b/examples/routing/todos/src/main.rs @@ -1,5 +1,3 @@ -#![deny(warnings)] - use std::{ net::SocketAddr, sync::{Arc, Mutex, PoisonError}, diff --git a/examples/rustls/src/main.rs b/examples/rustls/src/main.rs index d0b26db3..31f0f6d0 100644 --- a/examples/rustls/src/main.rs +++ b/examples/rustls/src/main.rs @@ -1,5 +1,3 @@ -#![deny(warnings)] - use std::{net::SocketAddr, sync::Arc}; use tokio::net::TcpListener; use viz::{get, serve, tls, Request, Result, Router}; diff --git a/examples/session/src/main.rs b/examples/session/src/main.rs index 44f87c06..8be0fd3b 100644 --- a/examples/session/src/main.rs +++ b/examples/session/src/main.rs @@ -1,5 +1,3 @@ -#![deny(warnings)] - use std::net::SocketAddr; use tokio::net::TcpListener; diff --git a/examples/sse/src/main.rs b/examples/sse/src/main.rs index 1fc2ffcc..57794b1e 100644 --- a/examples/sse/src/main.rs +++ b/examples/sse/src/main.rs @@ -1,5 +1,3 @@ -#![deny(warnings)] - use futures_util::StreamExt; use std::{net::SocketAddr, sync::Arc}; use systemstat::{Platform, System}; diff --git a/examples/static-files/embed/src/main.rs b/examples/static-files/embed/src/main.rs index e6d7283f..5f6ff4c0 100644 --- a/examples/static-files/embed/src/main.rs +++ b/examples/static-files/embed/src/main.rs @@ -1,5 +1,3 @@ -#![deny(warnings)] - use std::net::SocketAddr; use tokio::net::TcpListener; use viz::{handlers::embed, serve, Result, Router, StatusCode}; diff --git a/examples/static-files/include-dir/src/main.rs b/examples/static-files/include-dir/src/main.rs index 0f330ee5..5441a976 100644 --- a/examples/static-files/include-dir/src/main.rs +++ b/examples/static-files/include-dir/src/main.rs @@ -1,4 +1,3 @@ -#![deny(warnings)] #![allow(clippy::unused_async)] use http_body_util::Full; diff --git a/examples/static-files/serve/src/main.rs b/examples/static-files/serve/src/main.rs index ff197a57..57300fde 100644 --- a/examples/static-files/serve/src/main.rs +++ b/examples/static-files/serve/src/main.rs @@ -1,5 +1,3 @@ -#![deny(warnings)] - use std::{env, net::SocketAddr, path::PathBuf}; use tokio::net::TcpListener; use viz::{handlers::serve, serve, Request, Response, ResponseExt, Result, Router}; diff --git a/examples/static-routes/src/main.rs b/examples/static-routes/src/main.rs index 7bb1887d..f1036828 100644 --- a/examples/static-routes/src/main.rs +++ b/examples/static-routes/src/main.rs @@ -1,5 +1,3 @@ -#![deny(warnings)] - use hyper::server::conn::http1; use hyper::service::service_fn; use std::{ diff --git a/examples/tracing/src/main.rs b/examples/tracing/src/main.rs index 2565e3c9..fc6c9183 100644 --- a/examples/tracing/src/main.rs +++ b/examples/tracing/src/main.rs @@ -1,5 +1,3 @@ -#![deny(warnings)] - use std::net::SocketAddr; use tokio::net::TcpListener; use tracing::{debug, error, info, instrument}; diff --git a/examples/unix-socket/src/main.rs b/examples/unix-socket/src/main.rs index ec1f6cf8..d5cce33f 100644 --- a/examples/unix-socket/src/main.rs +++ b/examples/unix-socket/src/main.rs @@ -3,7 +3,6 @@ //! ```sh //! curl --unix-socket /tmp/viz.sock http://localhost/ //! ``` -#![deny(warnings)] #[cfg(unix)] #[tokio::main] diff --git a/examples/websocket-chat/src/main.rs b/examples/websocket-chat/src/main.rs index 888fba6b..782143d2 100644 --- a/examples/websocket-chat/src/main.rs +++ b/examples/websocket-chat/src/main.rs @@ -1,5 +1,3 @@ -#![deny(warnings)] - use futures_util::{SinkExt, StreamExt}; use std::net::SocketAddr; use tokio::net::TcpListener; diff --git a/viz-core/src/middleware/otel/tracing.rs b/viz-core/src/middleware/otel/tracing.rs index 10fedc44..393b927e 100644 --- a/viz-core/src/middleware/otel/tracing.rs +++ b/viz-core/src/middleware/otel/tracing.rs @@ -12,9 +12,9 @@ use opentelemetry::{ Context, KeyValue, }; use opentelemetry_semantic_conventions::trace::{ - CLIENT_ADDRESS, EXCEPTION_MESSAGE, HTTP_REQUEST_BODY_SIZE, HTTP_REQUEST_METHOD, - HTTP_RESPONSE_BODY_SIZE, HTTP_RESPONSE_STATUS_CODE, HTTP_ROUTE, NETWORK_PROTOCOL_VERSION, - SERVER_ADDRESS, SERVER_PORT, URL_PATH, URL_QUERY, URL_SCHEME, USER_AGENT_ORIGINAL, + CLIENT_ADDRESS, EXCEPTION_MESSAGE, HTTP_REQUEST_METHOD, HTTP_RESPONSE_STATUS_CODE, HTTP_ROUTE, + NETWORK_PROTOCOL_VERSION, SERVER_ADDRESS, SERVER_PORT, URL_PATH, URL_QUERY, URL_SCHEME, + USER_AGENT_ORIGINAL, }; use crate::{ @@ -23,6 +23,9 @@ use crate::{ Handler, IntoResponse, Request, RequestExt, Response, ResponseExt, Result, Transform, }; +const HTTP_REQUEST_BODY_SIZE: &str = "http.request.body.size"; +const HTTP_RESPONSE_BODY_SIZE: &str = "http.response.body.size"; + /// `OpenTelemetry` tracing config. #[derive(Debug)] pub struct Config {