Skip to content

Feature/switch to tower http metrics #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@


[build]
# Required for Tokio debugger - https://github.com/tokio-rs/console/blob/main/console-subscriber/README.md#enabling-tokio-instrumentation
rustflags = ["--cfg", "tokio_unstable"]
7 changes: 3 additions & 4 deletions bookapp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ name = "bookapp"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
client = { path = "../client" }
axum-otel-metrics = { git = "https://github.com/hardbyte/axum-otel-metrics" }

tower-otel-http-metrics = { version = "0.6.0", features = ["axum"] }

anyhow = "1.0.86"
axum = { workspace = true, features=["json"] }
Expand All @@ -21,7 +19,7 @@ opentelemetry-otlp = { version="0.17.0" , features = [
opentelemetry_sdk = { version="0.24.1", features = ["trace", "opentelemetry-http", "rt-tokio"]}
serde = "1.0.196"
sqlx = { version = "0.8.0", features = ["runtime-tokio", "postgres"] }
tokio = { version = "1.38.1", features = ["full"] }
tokio = { version = "1.38.1", features = ["full", "tracing"] }
tower = {workspace = true}
tower-http = { version = "0.5.2", features = ["trace"] }
tracing = { workspace = true }
Expand All @@ -42,3 +40,4 @@ opentelemetry-appender-tracing = "0.5.0"
hyper = "1.4.1"
rand = "0.8.5"
matchit = "0.8.4"
console-subscriber = "0.4.1"
9 changes: 5 additions & 4 deletions bookapp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ fn router(connection_pool: PgPool, producer: FutureProducer) -> Router {
// start OpenTelemetry trace on incoming request
// as long as not filtered out!
.layer(OtelAxumLayer::default())
.layer(axum_otel_metrics::HttpMetricsLayerBuilder::new()
.with_labels(vec![("env".to_string(), "testing".to_string())].into_iter().collect())
.build()
.layer(
tower_otel_http_metrics::HTTPMetricsLayerBuilder::new()
.with_meter(opentelemetry::global::meter(env!("CARGO_CRATE_NAME")))
.build()
.expect("Failed to build otel metrics layer"),
)


Expand Down Expand Up @@ -131,7 +133,6 @@ async fn main() -> Result<()> {
info!("Shutting down OpenTelemetry");

global::shutdown_tracer_provider();
info!("Shut down");

Ok(())
}
6 changes: 6 additions & 0 deletions bookapp/src/tracing_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ pub fn init_tracing() {

// Build the subscriber by combining layers
let subscriber = tracing_subscriber::Registry::default()
.with(
console_subscriber::ConsoleLayer::builder()
.with_default_env()
.server_addr(([0, 0, 0, 0], 6669))
.spawn()
)
.with(otel_log_layer)
.with(opentelemetry_metrics_layer)
.with(tracing_opentelemetry_layer)
Expand Down
1 change: 0 additions & 1 deletion client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ pub use generated::*;
/// with progenitor as of our pinned version https://github.com/oxidecomputer/progenitor/blob/4a3dfec3926f1f9db78eb6dc90087a1e2a1f9e45/progenitor-impl/src/method.rs#L1144-L1151
#[derive(Clone, Debug, Default)]
pub struct ClientState {}

1 change: 1 addition & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ services:
ENABLE_KAFKA_PRODUCER: "true"
ports:
- "8000:8000"
- "6669:6669"
depends_on:
kafka:
condition: service_healthy
Expand Down