diff --git a/Cargo.lock b/Cargo.lock index ebcff071..b22ab435 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -194,7 +194,7 @@ checksum = "686e48ce7820a1cf404b5c8e9b90ae24d03c867a408d8d651183945c7a554982" dependencies = [ "async-graphql", "async-trait", - "axum 0.7.5", + "axum", "bytes", "futures-util", "serde_json", @@ -308,34 +308,6 @@ dependencies = [ "cc", ] -[[package]] -name = "axum" -version = "0.6.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf" -dependencies = [ - "async-trait", - "axum-core 0.3.4", - "bitflags 1.3.2", - "bytes", - "futures-util", - "http 0.2.12", - "http-body 0.4.6", - "hyper 0.14.28", - "itoa", - "matchit", - "memchr", - "mime", - "percent-encoding", - "pin-project-lite", - "rustversion", - "serde", - "sync_wrapper 0.1.2", - "tower", - "tower-layer", - "tower-service", -] - [[package]] name = "axum" version = "0.7.5" @@ -343,15 +315,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3a6c9af12842a67734c9a2e355436e5d03b22383ed60cf13cd0c18fbfe3dcbcf" dependencies = [ "async-trait", - "axum-core 0.4.3", + "axum-core", "axum-macros", "base64 0.21.7", "bytes", "futures-util", "http 1.1.0", - "http-body 1.0.0", + "http-body", "http-body-util", - "hyper 1.4.1", + "hyper", "hyper-util", "itoa", "matchit", @@ -374,23 +346,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "axum-core" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "759fa577a247914fd3f7f76d62972792636412fbfd634cd452f6a385a74d2d2c" -dependencies = [ - "async-trait", - "bytes", - "futures-util", - "http 0.2.12", - "http-body 0.4.6", - "mime", - "rustversion", - "tower-layer", - "tower-service", -] - [[package]] name = "axum-core" version = "0.4.3" @@ -401,7 +356,7 @@ dependencies = [ "bytes", "futures-util", "http 1.1.0", - "http-body 1.0.0", + "http-body", "http-body-util", "mime", "pin-project-lite", @@ -418,13 +373,13 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0be6ea09c9b96cb5076af0de2e383bd2bc0c18f827cf1967bdd353e0b910d733" dependencies = [ - "axum 0.7.5", - "axum-core 0.4.3", + "axum", + "axum-core", "bytes", "futures-util", "headers", "http 1.1.0", - "http-body 1.0.0", + "http-body", "http-body-util", "mime", "pin-project-lite", @@ -670,7 +625,7 @@ dependencies = [ "derive_builder", "futures", "opentelemetry", - "prost 0.13.1", + "prost", "prost-wkt-types", "protobuf-src", "rand", @@ -682,7 +637,7 @@ dependencies = [ "tokio", "tokio-stream", "tokio-test", - "tonic 0.12.1", + "tonic", "tonic-build", "tonic-health", "tracing", @@ -725,14 +680,14 @@ dependencies = [ "cala-ledger-core-types", "chrono", "futures", - "prost 0.13.1", + "prost", "prost-wkt-types", "protobuf-src", "rust_decimal", "serde", "serde_json", "thiserror", - "tonic 0.12.1", + "tonic", "tonic-build", "tracing", "uuid", @@ -746,7 +701,7 @@ dependencies = [ "async-graphql", "async-graphql-axum", "async-trait", - "axum 0.7.5", + "axum", "axum-extra", "base64 0.22.1", "cala-cel-interpreter", @@ -784,7 +739,7 @@ dependencies = [ "opentelemetry_sdk", "serde", "serde_json", - "tonic 0.12.1", + "tonic", "tracing", "tracing-opentelemetry", "tracing-subscriber", @@ -891,16 +846,6 @@ dependencies = [ "unicode-segmentation", ] -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "core-foundation-sys" version = "0.8.6" @@ -931,15 +876,6 @@ version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" -[[package]] -name = "crossbeam-channel" -version = "0.5.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab3db02a9c5b5121e1e42fbdb1aeb65f5e02624cc58c43f2884c6ccac0b82f95" -dependencies = [ - "crossbeam-utils", -] - [[package]] name = "crossbeam-queue" version = "0.3.11" @@ -1391,25 +1327,6 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" -[[package]] -name = "h2" -version = "0.3.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8" -dependencies = [ - "bytes", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http 0.2.12", - "indexmap 2.2.6", - "slab", - "tokio", - "tokio-util", - "tracing", -] - [[package]] name = "h2" version = "0.4.5" @@ -1554,17 +1471,6 @@ dependencies = [ "itoa", ] -[[package]] -name = "http-body" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" -dependencies = [ - "bytes", - "http 0.2.12", - "pin-project-lite", -] - [[package]] name = "http-body" version = "1.0.0" @@ -1584,7 +1490,7 @@ dependencies = [ "bytes", "futures-core", "http 1.1.0", - "http-body 1.0.0", + "http-body", "pin-project-lite", ] @@ -1600,30 +1506,6 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" -[[package]] -name = "hyper" -version = "0.14.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80" -dependencies = [ - "bytes", - "futures-channel", - "futures-core", - "futures-util", - "h2 0.3.26", - "http 0.2.12", - "http-body 0.4.6", - "httparse", - "httpdate", - "itoa", - "pin-project-lite", - "socket2", - "tokio", - "tower-service", - "tracing", - "want", -] - [[package]] name = "hyper" version = "1.4.1" @@ -1633,9 +1515,9 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2 0.4.5", + "h2", "http 1.1.0", - "http-body 1.0.0", + "http-body", "httparse", "httpdate", "itoa", @@ -1645,25 +1527,13 @@ dependencies = [ "want", ] -[[package]] -name = "hyper-timeout" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbb958482e8c7be4bc3cf272a766a2b0bf1a6755e7a6ae777f017a31d11b13b1" -dependencies = [ - "hyper 0.14.28", - "pin-project-lite", - "tokio", - "tokio-io-timeout", -] - [[package]] name = "hyper-timeout" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3203a961e5c83b6f5498933e78b6b263e208c197b63e9c6c53cc82ffd3f63793" dependencies = [ - "hyper 1.4.1", + "hyper", "hyper-util", "pin-project-lite", "tokio", @@ -1680,8 +1550,8 @@ dependencies = [ "futures-channel", "futures-util", "http 1.1.0", - "http-body 1.0.0", - "hyper 1.4.1", + "http-body", + "hyper", "pin-project-lite", "socket2", "tokio", @@ -2169,9 +2039,9 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "opentelemetry" -version = "0.22.0" +version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "900d57987be3f2aeb70d385fff9b27fb74c5723cc9a52d904d4f9c807a0667bf" +checksum = "4c365a63eec4f55b7efeceb724f1336f26a9cf3427b70e59e2cd2a5b947fba96" dependencies = [ "futures-core", "futures-sink", @@ -2179,92 +2049,80 @@ dependencies = [ "once_cell", "pin-project-lite", "thiserror", - "urlencoding", ] [[package]] name = "opentelemetry-http" -version = "0.11.1" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7690dc77bf776713848c4faa6501157469017eaf332baccd4eb1cea928743d94" +checksum = "ad31e9de44ee3538fb9d64fe3376c1362f406162434609e79aea2a41a0af78ab" dependencies = [ "async-trait", "bytes", - "http 0.2.12", + "http 1.1.0", "opentelemetry", "reqwest", ] [[package]] name = "opentelemetry-otlp" -version = "0.15.0" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a016b8d9495c639af2145ac22387dcb88e44118e45320d9238fbf4e7889abcb" +checksum = "6b925a602ffb916fb7421276b86756027b37ee708f9dce2dbdcc51739f07e727" dependencies = [ "async-trait", "futures-core", - "http 0.2.12", + "http 1.1.0", "opentelemetry", "opentelemetry-http", "opentelemetry-proto", - "opentelemetry-semantic-conventions", "opentelemetry_sdk", - "prost 0.12.6", + "prost", "reqwest", "thiserror", "tokio", - "tonic 0.11.0", + "tonic", ] [[package]] name = "opentelemetry-proto" -version = "0.5.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a8fddc9b68f5b80dae9d6f510b88e02396f006ad48cac349411fbecc80caae4" +checksum = "30ee9f20bff9c984511a02f082dc8ede839e4a9bf15cc2487c8d6fea5ad850d9" dependencies = [ "opentelemetry", "opentelemetry_sdk", - "prost 0.12.6", - "tonic 0.11.0", + "prost", + "tonic", ] [[package]] name = "opentelemetry-semantic-conventions" -version = "0.14.0" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9ab5bd6c42fb9349dcf28af2ba9a0667f697f9bdcca045d39f2cec5543e2910" +checksum = "1cefe0543875379e47eb5f1e68ff83f45cc41366a92dfd0d073d513bf68e9a05" [[package]] name = "opentelemetry_sdk" -version = "0.22.1" +version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e90c7113be649e31e9a0f8b5ee24ed7a16923b322c3c5ab6367469c049d6b7e" +checksum = "692eac490ec80f24a17828d49b40b60f5aeaccdfe6a503f939713afd22bc28df" dependencies = [ "async-trait", - "crossbeam-channel", "futures-channel", "futures-executor", "futures-util", "glob", "once_cell", "opentelemetry", - "ordered-float", "percent-encoding", "rand", + "serde_json", "thiserror", "tokio", "tokio-stream", ] -[[package]] -name = "ordered-float" -version = "4.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a76df7075c7d4d01fdcb46c912dd17fba5b60c78ea480b475f2b6ab6f666584e" -dependencies = [ - "num-traits", -] - [[package]] name = "overload" version = "0.1.1" @@ -2485,16 +2343,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "prost" -version = "0.12.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "deb1435c188b76130da55f17a466d252ff7b1418b2ad3e037d127b94e3411f29" -dependencies = [ - "bytes", - "prost-derive 0.12.6", -] - [[package]] name = "prost" version = "0.13.1" @@ -2502,7 +2350,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e13db3d3fde688c61e2446b4d843bc27a7e8af269a69440c0308021dc92333cc" dependencies = [ "bytes", - "prost-derive 0.13.1", + "prost-derive", ] [[package]] @@ -2519,26 +2367,13 @@ dependencies = [ "once_cell", "petgraph", "prettyplease", - "prost 0.13.1", + "prost", "prost-types", "regex", "syn 2.0.60", "tempfile", ] -[[package]] -name = "prost-derive" -version = "0.12.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81bddcdb20abf9501610992b6759a4c888aef7d1a7247ef75e2404275ac24af1" -dependencies = [ - "anyhow", - "itertools 0.12.1", - "proc-macro2", - "quote", - "syn 2.0.60", -] - [[package]] name = "prost-derive" version = "0.13.1" @@ -2558,7 +2393,7 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cee5168b05f49d4b0ca581206eb14a7b22fafd963efe729ac48eb03266e25cc2" dependencies = [ - "prost 0.13.1", + "prost", ] [[package]] @@ -2569,7 +2404,7 @@ checksum = "a8d84e2bee181b04c2bac339f2bfe818c46a99750488cc6728ce4181d5aa8299" dependencies = [ "chrono", "inventory", - "prost 0.13.1", + "prost", "serde", "serde_derive", "serde_json", @@ -2583,7 +2418,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a669d5acbe719010c6f62a64e6d7d88fdedc1fe46e419747949ecb6312e9b14" dependencies = [ "heck 0.5.0", - "prost 0.13.1", + "prost", "prost-build", "prost-types", "quote", @@ -2596,7 +2431,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "01ef068e9b82e654614b22e6b13699bd545b6c0e2e721736008b00b38aeb4f64" dependencies = [ "chrono", - "prost 0.13.1", + "prost", "prost-build", "prost-types", "prost-wkt", @@ -2766,19 +2601,20 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.11.27" +version = "0.12.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd67538700a17451e7cba03ac727fb961abb7607553461627b97de0b89cf4a62" +checksum = "c7d6d2a27d57148378eb5e111173f4276ad26340ecc5c49a4a2152167a2d6a37" dependencies = [ - "base64 0.21.7", + "base64 0.22.1", "bytes", - "encoding_rs", + "futures-channel", "futures-core", "futures-util", - "h2 0.3.26", - "http 0.2.12", - "http-body 0.4.6", - "hyper 0.14.28", + "http 1.1.0", + "http-body", + "http-body-util", + "hyper", + "hyper-util", "ipnet", "js-sys", "log", @@ -2789,8 +2625,7 @@ dependencies = [ "serde", "serde_json", "serde_urlencoded", - "sync_wrapper 0.1.2", - "system-configuration", + "sync_wrapper 1.0.1", "tokio", "tower-service", "url", @@ -3530,27 +3365,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" -[[package]] -name = "system-configuration" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" -dependencies = [ - "bitflags 1.3.2", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "tap" version = "1.0.1" @@ -3682,16 +3496,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "tokio-io-timeout" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30b74022ada614a1b4834de765f9bb43877f910cc8ce4be40e89042c9223a8bf" -dependencies = [ - "pin-project-lite", - "tokio", -] - [[package]] name = "tokio-macros" version = "2.4.0" @@ -3772,33 +3576,6 @@ dependencies = [ "winnow", ] -[[package]] -name = "tonic" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76c4eb7a4e9ef9d4763600161f12f5070b92a578e1b634db88a6887844c91a13" -dependencies = [ - "async-stream", - "async-trait", - "axum 0.6.20", - "base64 0.21.7", - "bytes", - "h2 0.3.26", - "http 0.2.12", - "http-body 0.4.6", - "hyper 0.14.28", - "hyper-timeout 0.4.1", - "percent-encoding", - "pin-project", - "prost 0.12.6", - "tokio", - "tokio-stream", - "tower", - "tower-layer", - "tower-service", - "tracing", -] - [[package]] name = "tonic" version = "0.12.1" @@ -3807,19 +3584,19 @@ checksum = "38659f4a91aba8598d27821589f5db7dddd94601e7a01b1e485a50e5484c7401" dependencies = [ "async-stream", "async-trait", - "axum 0.7.5", + "axum", "base64 0.22.1", "bytes", - "h2 0.4.5", + "h2", "http 1.1.0", - "http-body 1.0.0", + "http-body", "http-body-util", - "hyper 1.4.1", - "hyper-timeout 0.5.1", + "hyper", + "hyper-timeout", "hyper-util", "percent-encoding", "pin-project", - "prost 0.13.1", + "prost", "socket2", "tokio", "tokio-stream", @@ -3849,10 +3626,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1e10e6a96ee08b6ce443487d4368442d328d0e746f3681f81127f7dc41b4955" dependencies = [ "async-stream", - "prost 0.13.1", + "prost", "tokio", "tokio-stream", - "tonic 0.12.1", + "tonic", ] [[package]] @@ -3945,9 +3722,9 @@ dependencies = [ [[package]] name = "tracing-opentelemetry" -version = "0.23.0" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9be14ba1bbe4ab79e9229f7f89fab8d120b865859f10527f31c033e599d2284" +checksum = "a9784ed4da7d921bc8df6963f8c80a0e4ce34ba6ba76668acadd3edbd985ff3b" dependencies = [ "js-sys", "once_cell", @@ -4115,12 +3892,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "urlencoding" -version = "2.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" - [[package]] name = "utf-8" version = "0.7.6" @@ -4484,9 +4255,9 @@ dependencies = [ [[package]] name = "winreg" -version = "0.50.0" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" +checksum = "a277a57398d4bfa075df44f501a17cfdf8542d224f0d36095a2adc7aee4ef0a5" dependencies = [ "cfg-if", "windows-sys 0.48.0", diff --git a/Cargo.toml b/Cargo.toml index b77aa507..f5a73d60 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,13 +28,13 @@ sqlx = { version = "0.8", features = [ "runtime-tokio-rustls", "postgres", "rust thiserror = "1.0.63" uuid = { version = "1.10", features = ["serde", "v4"] } tracing = "0.1.40" -tracing-opentelemetry = "0.23.0" +tracing-opentelemetry = "0.25.0" tracing-subscriber = { version = "0.3.18", features = ["env-filter", "json"] } -opentelemetry = { version = "0.22.0" } -opentelemetry_sdk = { version = "0.22.1", features = ["rt-tokio"] } -opentelemetry-otlp = { version = "0.15.0", features = ["http-proto", "reqwest-client"] } -opentelemetry-http = "0.11.1" -opentelemetry-semantic-conventions = "0.14.0" +opentelemetry = { version = "0.24.0" } +opentelemetry_sdk = { version = "0.24.1", features = ["rt-tokio"] } +opentelemetry-otlp = { version = "0.17.0", features = ["http-proto", "reqwest-client"] } +opentelemetry-http = "0.13" +opentelemetry-semantic-conventions = "0.16.0" tokio = { version = "1.39", features = ["rt-multi-thread", "macros"] } tokio-stream = { version = "0.1.14", features = ["sync"] } serde = { version = "1.0.208", features = ["derive"] } diff --git a/cala-server/src/server/mod.rs b/cala-server/src/server/mod.rs index 6e4ad74d..94476a24 100644 --- a/cala-server/src/server/mod.rs +++ b/cala-server/src/server/mod.rs @@ -7,6 +7,7 @@ use axum_extra::headers::HeaderMap; use cala_ledger::{AtomicOperation, CalaLedger}; use std::sync::Arc; use tokio::sync::Mutex; +use tracing::instrument; use crate::{app::CalaApp, extension::*, graphql}; @@ -35,6 +36,7 @@ pub async fn run( Ok(()) } +#[instrument(name = "cala_server.graphql", skip_all, fields(error, error.level, error.message))] pub async fn graphql_handler( headers: HeaderMap, schema: Extension, graphql::CoreMutation, EmptySubscription>>, diff --git a/cala-tracing/src/lib.rs b/cala-tracing/src/lib.rs index 91ef7978..0ebcd18e 100644 --- a/cala-tracing/src/lib.rs +++ b/cala-tracing/src/lib.rs @@ -1,11 +1,11 @@ #![cfg_attr(feature = "fail-on-warnings", deny(warnings))] #![cfg_attr(feature = "fail-on-warnings", deny(clippy::all))] -use opentelemetry::{global, KeyValue}; +use opentelemetry::{trace::TracerProvider, KeyValue}; use opentelemetry_sdk::{ - propagation::TraceContextPropagator, - resource::{EnvResourceDetector, OsResourceDetector, ProcessResourceDetector}, - trace, Resource, + resource::{EnvResourceDetector, SdkProvidedResourceDetector}, + trace::Config, + Resource, }; use opentelemetry_semantic_conventions::resource::{SERVICE_NAME, SERVICE_NAMESPACE}; use serde::{Deserialize, Serialize}; @@ -29,13 +29,13 @@ impl Default for TracingConfig { } pub fn init_tracer(config: TracingConfig) -> anyhow::Result<()> { - global::set_text_map_propagator(TraceContextPropagator::new()); - let tracer = opentelemetry_otlp::new_pipeline() + let provider = opentelemetry_otlp::new_pipeline() .tracing() .with_exporter(opentelemetry_otlp::new_exporter().tonic()) - .with_trace_config(trace::config().with_resource(telemetry_resource(&config))) + .with_trace_config(Config::default().with_resource(telemetry_resource(&config))) .install_batch(opentelemetry_sdk::runtime::Tokio)?; - let telemetry = tracing_opentelemetry::layer().with_tracer(tracer); + let telemetry = + tracing_opentelemetry::layer().with_tracer(provider.tracer(config.service_name)); let fmt_layer = fmt::layer().json(); let filter_layer = EnvFilter::try_from_default_env() @@ -45,7 +45,7 @@ pub fn init_tracer(config: TracingConfig) -> anyhow::Result<()> { .with(filter_layer) .with(fmt_layer) .with(telemetry) - .try_init()?; + .init(); Ok(()) } @@ -55,8 +55,7 @@ fn telemetry_resource(config: &TracingConfig) -> Resource { Duration::from_secs(3), vec![ Box::new(EnvResourceDetector::new()), - Box::new(OsResourceDetector), - Box::new(ProcessResourceDetector), + Box::new(SdkProvidedResourceDetector), ], ) .merge(&Resource::new(vec![ @@ -74,24 +73,13 @@ pub fn insert_error_fields(level: tracing::Level, error: impl std::fmt::Display) #[cfg(feature = "http")] pub mod http { pub fn extract_tracing(headers: &axum_extra::headers::HeaderMap) { + use opentelemetry::propagation::text_map_propagator::TextMapPropagator; use opentelemetry_http::HeaderExtractor; + use opentelemetry_sdk::propagation::TraceContextPropagator; use tracing_opentelemetry::OpenTelemetrySpanExt; - // http in opentelemetry_http is not on the same version as in axum_extra - // Change this when opentelemetry_http has http >= v1.x - let mut map = http::HeaderMap::new(); - for (key, value) in headers.iter() { - if let Ok(key) = http::HeaderName::from_bytes(key.as_str().as_bytes()) { - if let Ok(s) = value.to_str() { - if let Ok(v) = http::HeaderValue::from_str(s) { - map.insert(key, v); - } - } - } - } - let extractor = HeaderExtractor(&map); - let ctx = opentelemetry::global::get_text_map_propagator(|propagator| { - propagator.extract(&extractor) - }); + let extractor = HeaderExtractor(headers); + let propagator = TraceContextPropagator::new(); + let ctx = propagator.extract(&extractor); tracing::Span::current().set_parent(ctx) } }