commit 9eb879e9f54d9bd02849baf1182f81ef82581dcc parent f8ca369a8b9b72ec867e5a3d705cd4f159d5cf2d Author: ling0x <ling0x@users.noreply.github.com> Date: Tue, 25 Aug 2026 18:33:26 +0100 distributed observability with axum otel and reqwest otel Diffstat:
170 files changed, 9004 insertions(+), 7375 deletions(-)
diff --git a/distributed_observability_in_rust/example_project/Architecture.md b/distributed_observability/Architecture.md diff --git a/distributed_observability/Cargo.lock b/distributed_observability/Cargo.lock @@ -0,0 +1,4033 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "ahash" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "aho-corasick" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c982642fa9e8606056828ee9a8505737230110bb1099153c79efe865c59d12ba" +dependencies = [ + "memchr", +] + +[[package]] +name = "allocator-api2" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anyhow" +version = "1.0.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61" + +[[package]] +name = "arraydeque" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d902e3d592a523def97af8f317b08ce16b7ab854c1985a0c671e6f15cebc236" + +[[package]] +name = "async-trait" +version = "0.1.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "atoi" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f28d99ec8bfea296261ca1af174f24225171fea9664ba9003cbebee704810528" +dependencies = [ + "num-traits", +] + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "autocfg" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" + +[[package]] +name = "aws-lc-rs" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce2b2dcc879c3bae0d371e77c99f2238400ef24ec001394befa67b6e543add9e" +dependencies = [ + "aws-lc-sys", + "zeroize", +] + +[[package]] +name = "aws-lc-sys" +version = "0.44.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f09fae7be8bb3174e05c6afdb34199e6dc0c7c04ba9fa237b1967adfbde27483" +dependencies = [ + "cc", + "cmake", + "dunce", + "fs_extra", + "pkg-config", +] + +[[package]] +name = "axum" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b098575ebe77cb6d14fc7f32749631a6e44edbef6b796f89b020e99ba20d425" +dependencies = [ + "axum-core", + "axum-macros", + "bytes", + "form_urlencoded", + "futures-util", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-util", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "serde_core", + "serde_json", + "serde_path_to_error", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tower", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "axum-core" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59446ce19cd142f8833f856eb31f3eb097812d1479ab224f54d72428ca21ea22" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "http-body-util", + "mime", + "pin-project-lite", + "sync_wrapper", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "axum-macros" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "604fde5e028fea851ce1d8570bbdc034bec850d157f7569d10f347d06808c05c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "axum-tracing-opentelemetry" +version = "0.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c938150bbecf4b43a24964bea0780f99d538b6654455e45b1784d410f122822" +dependencies = [ + "axum", + "futures-core", + "futures-util", + "http", + "opentelemetry", + "opentelemetry-semantic-conventions", + "pin-project-lite", + "tower", + "tracing", + "tracing-opentelemetry", + "tracing-opentelemetry-instrumentation-sdk", +] + +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "base64ct" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55248b47b0caf0546f7988906588779981c43bb1bc9d0c44087278f80cdb44ba" + +[[package]] +name = "bcrypt" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e65938ed058ef47d92cf8b346cc76ef48984572ade631927e9937b5ffc7662c7" +dependencies = [ + "base64 0.22.1", + "blowfish", + "getrandom 0.2.16", + "subtle", + "zeroize", +] + +[[package]] +name = "bigdecimal" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "560f42649de9fa436b73517378a147ec21f6c997a546581df4b4b31677828934" +dependencies = [ + "autocfg", + "libm", + "num-bigint", + "num-integer", + "num-traits", + "serde", +] + +[[package]] +name = "bitflags" +version = "2.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" +dependencies = [ + "serde_core", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "blowfish" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e412e2cd0f2b2d93e02543ceae7917b3c70331573df19ee046bcbc35e45e87d7" +dependencies = [ + "byteorder", + "cipher", +] + +[[package]] +name = "bumpalo" +version = "3.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b35204fbdc0b3f4446b89fc1ac2cf84a8a68971995d0bf2e925ec7cd960f9cb3" + +[[package]] +name = "cc" +version = "1.2.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97463e1064cb1b1c1384ad0a0b9c8abd0988e2a91f52606c80ef14aadb63e36" +dependencies = [ + "find-msvc-tools", + "jobserver", + "libc", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "cfg_aliases" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527" + +[[package]] +name = "chacha20" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d524456ba66e72eb8b115ff89e01e497f8e6d11d78b70b1aa13c0fbd97540a81" +dependencies = [ + "cfg-if", + "cpufeatures 0.3.0", + "rand_core 0.10.1", +] + +[[package]] +name = "chrono" +version = "0.4.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "145052bdd345b87320e369255277e3fb5152762ad123a901ef5c262dd38fe8d2" +dependencies = [ + "iana-time-zone", + "js-sys", + "num-traits", + "serde", + "wasm-bindgen", + "windows-link", +] + +[[package]] +name = "cipher" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +dependencies = [ + "crypto-common", + "inout", +] + +[[package]] +name = "cmake" +version = "0.1.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0f78a02292a74a88ac736019ab962ece0bc380e3f977bf72e376c5d78ff0678" +dependencies = [ + "cc", +] + +[[package]] +name = "combine" +version = "4.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba5a308b75df32fe02788e748662718f03fde005016435c444eea572398219fd" +dependencies = [ + "bytes", + "memchr", +] + +[[package]] +name = "concurrent-queue" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "config" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68578f196d2a33ff61b27fae256c3164f65e36382648e30666dde05b8cc9dfdf" +dependencies = [ + "async-trait", + "convert_case", + "json5", + "nom", + "pathdiff", + "ron", + "rust-ini", + "serde", + "serde_json", + "toml", + "yaml-rust2", +] + +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + +[[package]] +name = "const-random" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87e00182fe74b066627d63b85fd550ac2998d4b0bd86bfed477a0ae4c7c71359" +dependencies = [ + "const-random-macro", +] + +[[package]] +name = "const-random-macro" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9d839f2a20b0aee515dc581a6172f2321f96cab76c1a38a4c584a194955390e" +dependencies = [ + "getrandom 0.2.16", + "once_cell", + "tiny-keccak", +] + +[[package]] +name = "convert_case" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" +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" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2a6cd9ae233e7f62ba4e9353e81a88df7fc8a5987b8d445b4d90c879bd156f6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + +[[package]] +name = "cpufeatures" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b2a41393f66f16b0823bb79094d54ac5fbd34ab292ddafb9a0456ac9f87d201" +dependencies = [ + "libc", +] + +[[package]] +name = "crc" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9710d3b3739c2e349eb44fe848ad0b7c8cb1e42bd87ee49371df2f7acaf3e675" +dependencies = [ + "crc-catalog", +] + +[[package]] +name = "crc-catalog" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" + +[[package]] +name = "crossbeam-queue" +version = "0.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f58bbc28f91df819d0aa2a2c00cd19754769c2fad90579b3592b1c9ba7a3115" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" + +[[package]] +name = "crunchy" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" + +[[package]] +name = "crypto-common" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "der" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb" +dependencies = [ + "const-oid", + "pem-rfc7468", + "zeroize", +] + +[[package]] +name = "deranged" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ececcb659e7ba858fb4f10388c250a7252eb0a27373f1a72b8748afdd248e587" +dependencies = [ + "powerfmt", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "const-oid", + "crypto-common", + "subtle", +] + +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dlv-list" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "442039f5147480ba31067cb00ada1adae6892028e40e45fc5de7b7df6dcc1b5f" +dependencies = [ + "const-random", +] + +[[package]] +name = "dotenvy" +version = "0.15.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" + +[[package]] +name = "dunce" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" + +[[package]] +name = "either" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" +dependencies = [ + "serde", +] + +[[package]] +name = "encoding_rs" +version = "0.8.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "etcetera" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "136d1b5283a1ab77bd9257427ffd09d8667ced0570b6f938942bc7568ed5b943" +dependencies = [ + "cfg-if", + "home", + "windows-sys 0.48.0", +] + +[[package]] +name = "event-listener" +version = "5.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13b66accf52311f30a0db42147dadea9850cb48cd070028831ae5f5d4b856ab" +dependencies = [ + "concurrent-queue", + "parking", + "pin-project-lite", +] + +[[package]] +name = "find-msvc-tools" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a3076410a55c90011c298b04d0cfa770b00fa04e1e3c97d3f6c9de105a03844" + +[[package]] +name = "flume" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da0e4dd2a88388a1f4ccc7c9ce104604dab68d9f408dc34cd45823d5a9069095" +dependencies = [ + "futures-core", + "futures-sink", + "spin", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "fs_extra" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" + +[[package]] +name = "futures-channel" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" + +[[package]] +name = "futures-executor" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-intrusive" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d930c203dd0b6ff06e0201a4a2fe9149b43c684fd4420555b26d21b1a02956f" +dependencies = [ + "futures-core", + "lock_api", + "parking_lot", +] + +[[package]] +name = "futures-io" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" + +[[package]] +name = "futures-macro" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" + +[[package]] +name = "futures-task" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" + +[[package]] +name = "futures-util" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" +dependencies = [ + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi", + "wasm-bindgen", +] + +[[package]] +name = "getrandom" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" +dependencies = [ + "cfg-if", + "libc", + "r-efi 5.3.0", + "wasip2", +] + +[[package]] +name = "getrandom" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "r-efi 6.0.0", + "rand_core 0.10.1", + "wasm-bindgen", +] + +[[package]] +name = "h2" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3c0b69cfcb4e1b9f1bf2f53f95f766e4661169728ec61cd3fe5a0166f2d1386" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +dependencies = [ + "ahash", + "allocator-api2", +] + +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash", +] + +[[package]] +name = "hashbrown" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5419bdc4f6a9207fbeba6d11b604d481addf78ecd10c11ad51e76c2f6482748d" + +[[package]] +name = "hashlink" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8094feaf31ff591f651a2664fb9cfd92bba7a60ce3197265e9482ebe753c8f7" +dependencies = [ + "hashbrown 0.14.5", +] + +[[package]] +name = "hashlink" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7382cf6263419f2d8df38c55d7da83da5c18aef87fc7a7fc1fb1e344edfe14c1" +dependencies = [ + "hashbrown 0.15.5", +] + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hkdf" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" +dependencies = [ + "hmac", +] + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + +[[package]] +name = "home" +version = "0.5.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc627f471c528ff0c4a49e1d5e60450c8f6461dd6d10ba9dcd3a61d3dff7728d" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "http" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4a85d31aea989eead29a3aaf9e1115a180df8282431156e533de47660892565" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "http-range-header" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9171a2ea8a68358193d15dd5d70c1c10a2afc3e7e4c5bc92bc9f025cebd7359c" + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "hyper" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ab2d4f250c3d7b1c9fcdff1cece94ea4e2dfbec68614f7b87cb205f24ca9d11" +dependencies = [ + "atomic-waker", + "bytes", + "futures-channel", + "futures-core", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "pin-utils", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3c93eb611681b207e1fe55d5a71ecf91572ec8a6705cdb6857f7d8d5242cf58" +dependencies = [ + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", +] + +[[package]] +name = "hyper-timeout" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b90d566bffbce6a75bd8b09a05aa8c2cb1fabb6cb348f8840c9e4c90a0d83b0" +dependencies = [ + "hyper", + "hyper-util", + "pin-project-lite", + "tokio", + "tower-service", +] + +[[package]] +name = "hyper-util" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52e9a2a24dc5c6821e71a7030e1e14b7b632acac55c40e9d2e082c621261bb56" +dependencies = [ + "base64 0.22.1", + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "http", + "http-body", + "hyper", + "ipnet", + "libc", + "percent-encoding", + "pin-project-lite", + "socket2", + "system-configuration", + "tokio", + "tower-service", + "tracing", + "windows-registry", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33e57f83510bb73707521ebaffa789ec8caf86f9657cad665b092b581d40e9fb" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "icu_collections" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c6b649701667bbe825c3b7e6388cb521c23d88644678e83c0c4d0a621a34b43" +dependencies = [ + "displaydoc", + "potential_utf", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edba7861004dd3714265b4db54a3c390e880ab658fec5f7db895fae2046b5bb6" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f6c8828b67bf8908d82127b2054ea1b4427ff0230ee9141c54251934ab1b599" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7aedcccd01fc5fe81e6b489c15b247b8b0690feb23304303a9e560f37efc560a" + +[[package]] +name = "icu_properties" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e93fcd3157766c0c8da2f8cff6ce651a31f0810eaa1c51ec363ef790bbb5fb99" +dependencies = [ + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02845b3647bb045f1100ecd6480ff52f34c35f82d9880e029d329c21d1054899" + +[[package]] +name = "icu_provider" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85962cf0ce02e1e0a629cc34e7ca3e373ce20dda4c4d7294bbd0bf1fdb59e614" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acae9609540aa318d1bc588455225fb2085b9ed0c4f6bd0d9d5bcd86f1a0344" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "indexmap" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6717a8d2a5a929a1a2eb43a12812498ed141a0bcfb7e8f7844fbdbe4303bba9f" +dependencies = [ + "equivalent", + "hashbrown 0.16.0", +] + +[[package]] +name = "inout" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01" +dependencies = [ + "generic-array", +] + +[[package]] +name = "inventory" +version = "0.1.0" +dependencies = [ + "anyhow", + "axum", + "axum-tracing-opentelemetry", + "bigdecimal", + "chrono", + "config", + "dotenvy", + "opentelemetry", + "opentelemetry-otlp", + "opentelemetry_sdk", + "reqwest-middleware", + "reqwest-tracing", + "serde", + "serde_json", + "sqlx", + "thiserror", + "tokio", + "tower", + "tower-http", + "tracing", + "tracing-opentelemetry", + "tracing-subscriber", + "uuid", +] + +[[package]] +name = "ipnet" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130" + +[[package]] +name = "itertools" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" + +[[package]] +name = "jni" +version = "0.22.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5efd9a482cf3a427f00d6b35f14332adc7902ce91efb778580e180ff90fa3498" +dependencies = [ + "cfg-if", + "combine", + "jni-macros", + "jni-sys", + "log", + "simd_cesu8", + "thiserror", + "walkdir", + "windows-link", +] + +[[package]] +name = "jni-macros" +version = "0.22.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a00109accc170f0bdb141fed3e393c565b6f5e072365c3bd58f5b062591560a3" +dependencies = [ + "proc-macro2", + "quote", + "rustc_version", + "simd_cesu8", + "syn", +] + +[[package]] +name = "jni-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6377a88cb3910bee9b0fa88d4f42e1d2da8e79915598f65fb0c7ee14c878af2" +dependencies = [ + "jni-sys-macros", +] + +[[package]] +name = "jni-sys-macros" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38c0b942f458fe50cdac086d2f946512305e5631e720728f2a61aabcd47a6264" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "jobserver" +version = "0.1.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c00acbd29eabad4a2392fa0e921c874934dbbf4194312ad20f04a0ed67a3cb3" +dependencies = [ + "getrandom 0.4.3", + "libc", +] + +[[package]] +name = "js-sys" +version = "0.3.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b011eec8cc36da2aab2d5cff675ec18454fad408585853910a202391cf9f8e65" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + +[[package]] +name = "json5" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96b0db21af676c1ce64250b5f40f3ce2cf27e4e47cb91ed91eb6fe9350b430c1" +dependencies = [ + "pest", + "pest_derive", + "serde", +] + +[[package]] +name = "jsonwebtoken" +version = "9.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a87cc7a48537badeae96744432de36f4be2b4a34a05a5ef32e9dd8a1c169dde" +dependencies = [ + "base64 0.22.1", + "js-sys", + "pem", + "ring", + "serde", + "serde_json", + "simple_asn1", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +dependencies = [ + "spin", +] + +[[package]] +name = "libc" +version = "0.2.177" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976" + +[[package]] +name = "libm" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de" + +[[package]] +name = "libredox" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "416f7e718bdb06000964960ffa43b4335ad4012ae8b99060261aa4a8088d5ccb" +dependencies = [ + "bitflags", + "libc", + "redox_syscall", +] + +[[package]] +name = "libsqlite3-sys" +version = "0.30.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e99fb7a497b1e3339bc746195567ed8d3e24945ecd636e3619d20b9de9e9149" +dependencies = [ + "pkg-config", + "vcpkg", +] + +[[package]] +name = "litemap" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6373607a59f0be73a39b6fe456b8192fcc3585f602af20751600e974dd455e77" + +[[package]] +name = "lock_api" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432" + +[[package]] +name = "lru-slab" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154" + +[[package]] +name = "matchers" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1525a2a28c7f4fa0fc98bb91ae755d1e2d1505079e05539e35bc876b5d65ae9" +dependencies = [ + "regex-automata", +] + +[[package]] +name = "matchit" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3" + +[[package]] +name = "md-5" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" +dependencies = [ + "cfg-if", + "digest", +] + +[[package]] +name = "memchr" +version = "2.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "mime_guess" +version = "2.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e" +dependencies = [ + "mime", + "unicase", +] + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "mio" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69d83b0086dc8ecf3ce9ae2874b2d1290252e2a30720bea58a5c6639b0092873" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.61.2", +] + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "nu-ansi-term" +version = "0.50.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "num-bigint" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" +dependencies = [ + "num-integer", + "num-traits", +] + +[[package]] +name = "num-bigint-dig" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e661dda6640fad38e827a6d4a310ff4763082116fe217f279885c97f511bb0b7" +dependencies = [ + "lazy_static", + "libm", + "num-integer", + "num-iter", + "num-traits", + "rand 0.8.5", + "smallvec", + "zeroize", +] + +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", + "libm", +] + +[[package]] +name = "once_cell" +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" + +[[package]] +name = "openssl-probe" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe" + +[[package]] +name = "opentelemetry" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0142c63252a9e054e68a4c61a5778f7b14f576274d593f8ce883d191a099682" +dependencies = [ + "futures-core", + "futures-sink", + "js-sys", + "pin-project-lite", + "thiserror", + "tracing", +] + +[[package]] +name = "opentelemetry-http" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5683015d09e2df236ef005b17f6f196f0d5f6313c4fa43a7b6a53b52776e4331" +dependencies = [ + "async-trait", + "bytes", + "http", + "opentelemetry", + "reqwest", +] + +[[package]] +name = "opentelemetry-otlp" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9966929966d17620d7c316c643ba62631826e10021409357772d5eea84f62c35" +dependencies = [ + "http", + "opentelemetry", + "opentelemetry-http", + "opentelemetry-proto", + "opentelemetry_sdk", + "prost", + "reqwest", + "thiserror", + "tokio", + "tonic", + "tonic-types", +] + +[[package]] +name = "opentelemetry-proto" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56d658ba1faf63f7b9c492cfbe6e0ec365440a16132d3270c1065f7b33f1b638" +dependencies = [ + "opentelemetry", + "opentelemetry_sdk", + "prost", + "tonic", + "tonic-prost", +] + +[[package]] +name = "opentelemetry-semantic-conventions" +version = "0.32.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c913ac17a6c451661ee255f4625d143e51647ae78ebd969b75e41c4442f4fe47" + +[[package]] +name = "opentelemetry_sdk" +version = "0.32.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b59f80e1ac4d5ff7a2db8fb6c80badb7f0f3f858211fba08dd9aaec750894f9" +dependencies = [ + "futures-channel", + "futures-executor", + "futures-util", + "opentelemetry", + "percent-encoding", + "portable-atomic", + "rand 0.9.5", + "thiserror", +] + +[[package]] +name = "ordered-multimap" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49203cdcae0030493bad186b28da2fa25645fa276a51b6fec8010d281e02ef79" +dependencies = [ + "dlv-list", + "hashbrown 0.14.5", +] + +[[package]] +name = "orders" +version = "0.1.0" +dependencies = [ + "anyhow", + "axum", + "axum-tracing-opentelemetry", + "bigdecimal", + "chrono", + "config", + "dotenvy", + "opentelemetry", + "opentelemetry-otlp", + "opentelemetry_sdk", + "reqwest", + "reqwest-middleware", + "reqwest-tracing", + "serde", + "serde_json", + "sqlx", + "thiserror", + "tokio", + "tower", + "tower-http", + "tracing", + "tracing-opentelemetry", + "tracing-subscriber", + "uuid", +] + +[[package]] +name = "otelmart" +version = "0.1.0" +dependencies = [ + "anyhow", + "axum", + "axum-tracing-opentelemetry", + "bcrypt", + "chrono", + "config", + "dotenvy", + "jsonwebtoken", + "opentelemetry", + "opentelemetry-otlp", + "opentelemetry_sdk", + "reqwest", + "reqwest-middleware", + "reqwest-tracing", + "serde", + "serde_json", + "sqlx", + "thiserror", + "tokio", + "tower", + "tower-http", + "tracing", + "tracing-opentelemetry", + "tracing-subscriber", + "urlencoding", + "uuid", +] + +[[package]] +name = "parking" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" + +[[package]] +name = "parking_lot" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-link", +] + +[[package]] +name = "pathdiff" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df94ce210e5bc13cb6651479fa48d14f601d9858cfe0467f43ae157023b938d3" + +[[package]] +name = "pem" +version = "3.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d30c53c26bc5b31a98cd02d20f25a7c8567146caf63ed593a9d87b2775291be" +dependencies = [ + "base64 0.22.1", + "serde_core", +] + +[[package]] +name = "pem-rfc7468" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" +dependencies = [ + "base64ct", +] + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "pest" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "989e7521a040efde50c3ab6bbadafbe15ab6dc042686926be59ac35d74607df4" +dependencies = [ + "memchr", + "ucd-trie", +] + +[[package]] +name = "pest_derive" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "187da9a3030dbafabbbfb20cb323b976dc7b7ce91fcd84f2f74d6e31d378e2de" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49b401d98f5757ebe97a26085998d6c0eecec4995cad6ab7fc30ffdf4b052843" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pest_meta" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72f27a2cfee9f9039c4d86faa5af122a0ac3851441a34865b8a043b46be0065a" +dependencies = [ + "pest", + "sha2", +] + +[[package]] +name = "pin-project" +version = "1.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2466b2336ed02bcdca6b294417127b90ec92038d1d5c4fbeac971a922e0e0924" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c96395f0a926bc13b1c17622aaddda1ecb55d49c8f1bf9777e4d877800a43f8b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkcs1" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8ffb9f10fa047879315e6625af03c164b16962a5368d724ed16323b68ace47f" +dependencies = [ + "der", + "pkcs8", + "spki", +] + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "pkg-config" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" + +[[package]] +name = "portable-atomic" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85" + +[[package]] +name = "potential_utf" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b73949432f5e2a09657003c25bca5e19a0e9c84f8058ca374f49e0ebe605af77" +dependencies = [ + "zerovec", +] + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "proc-macro2" +version = "1.0.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "products" +version = "0.1.0" +dependencies = [ + "anyhow", + "axum", + "axum-tracing-opentelemetry", + "bigdecimal", + "chrono", + "config", + "dotenvy", + "opentelemetry", + "opentelemetry-otlp", + "opentelemetry_sdk", + "reqwest-middleware", + "reqwest-tracing", + "serde", + "serde_json", + "sqlx", + "thiserror", + "tokio", + "tower", + "tower-http", + "tracing", + "tracing-opentelemetry", + "tracing-subscriber", + "uuid", +] + +[[package]] +name = "prost" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "528ac67416ff8646872a3c02cad9cc4ee5dc9f9540c9b10771855c95cb2e5ae1" +dependencies = [ + "bytes", + "prost-derive", +] + +[[package]] +name = "prost-derive" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b570b25f7617e43d59005d0990ccb79e950a423952cea19671b7a876da390adf" +dependencies = [ + "anyhow", + "itertools", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "prost-types" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f94967dc7688f3054c7fac87473ffae4cc4c3904800e2d9f5b857246d8963b0a" +dependencies = [ + "prost", +] + +[[package]] +name = "quinn" +version = "0.11.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c1a41e437b6bbd489372cd4971de128e85c855f56c57f283d20ff016cf7c0a8" +dependencies = [ + "bytes", + "cfg_aliases", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-proto" +version = "0.11.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04759210543be93709136e28212294a659ef5001836ff4eab4d663e4529bba83" +dependencies = [ + "aws-lc-rs", + "bytes", + "getrandom 0.4.3", + "lru-slab", + "rand 0.10.2", + "rand_pcg", + "ring", + "rustc-hash", + "rustls", + "rustls-pki-types", + "slab", + "thiserror", + "tinyvec", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-udp" +version = "0.5.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35a133f956daabe89a61a685c2649f13d82d5aa4bd5d12d1277e1072a21c0694" +dependencies = [ + "cfg_aliases", + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + +[[package]] +name = "quote" +version = "1.0.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" + +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha 0.3.1", + "rand_core 0.6.4", +] + +[[package]] +name = "rand" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9ef1d0d795eb7d84685bca4f72f3649f064e6641543d3a8c415898726a57b41" +dependencies = [ + "rand_chacha 0.9.0", + "rand_core 0.9.5", +] + +[[package]] +name = "rand" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7f5fa3a058cd35567ef9bfa5e75732bee0f9e4c55fa90477bef2dfcdbc4be80" +dependencies = [ + "chacha20", + "getrandom 0.4.3", + "rand_core 0.10.1", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_chacha" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" +dependencies = [ + "ppv-lite86", + "rand_core 0.9.5", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom 0.2.16", +] + +[[package]] +name = "rand_core" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c" +dependencies = [ + "getrandom 0.3.4", +] + +[[package]] +name = "rand_core" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69" + +[[package]] +name = "rand_pcg" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "caa0f4137e1c0a72f4c651489402276c8e8e1cf081f3b0ba156d2cbeef09e86a" +dependencies = [ + "rand_core 0.10.1", +] + +[[package]] +name = "redox_syscall" +version = "0.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" +dependencies = [ + "bitflags", +] + +[[package]] +name = "regex-automata" +version = "0.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad8553b9b26413251cbf30e620595c7a41b3887f03da04579c0e6b0d6a06b4b2" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4" + +[[package]] +name = "reqwest" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "219c5811de6525e5416c7d5d53bb656d3afdbc6c5af816e0802bcfa42dbdc1c3" +dependencies = [ + "base64 0.22.1", + "bytes", + "encoding_rs", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-util", + "js-sys", + "log", + "mime", + "percent-encoding", + "pin-project-lite", + "quinn", + "rustls", + "rustls-pki-types", + "rustls-platform-verifier", + "serde", + "serde_json", + "sync_wrapper", + "tokio", + "tokio-rustls", + "tower", + "tower-http", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + +[[package]] +name = "reqwest-middleware" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07bc3f1384cffa4f274dad2d4ddd73aed32fed8f786d96c6be8aa4e5fd3c3b58" +dependencies = [ + "anyhow", + "async-trait", + "http", + "reqwest", + "serde", + "thiserror", + "tower-service", +] + +[[package]] +name = "reqwest-tracing" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e5af0cd6fc3d3c8f703d597af70b6e4e62432c63157b49419fa1ffaf481702" +dependencies = [ + "anyhow", + "async-trait", + "getrandom 0.2.16", + "http", + "matchit", + "opentelemetry", + "reqwest", + "reqwest-middleware", + "tracing", + "tracing-opentelemetry", +] + +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.16", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "ron" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b91f7eff05f748767f183df4320a63d6936e9c6107d97c9e6bdd9784f4289c94" +dependencies = [ + "base64 0.21.7", + "bitflags", + "serde", + "serde_derive", +] + +[[package]] +name = "rsa" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40a0376c50d0358279d9d643e4bf7b7be212f1f4ff1da9070a7b54d22ef75c88" +dependencies = [ + "const-oid", + "digest", + "num-bigint-dig", + "num-integer", + "num-traits", + "pkcs1", + "pkcs8", + "rand_core 0.6.4", + "signature", + "spki", + "subtle", + "zeroize", +] + +[[package]] +name = "rust-ini" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e0698206bcb8882bf2a9ecb4c1e7785db57ff052297085a6efd4fe42302068a" +dependencies = [ + "cfg-if", + "ordered-multimap", +] + +[[package]] +name = "rustc-hash" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d" + +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + +[[package]] +name = "rustls" +version = "0.23.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "533f54bc6a7d4f647e46ad909549eda97bf5afc1585190ef692b4286b198bd8f" +dependencies = [ + "aws-lc-rs", + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-native-certs" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dab5152771c58876a2146916e53e35057e1a4dfa2b9df0f0305b07f611fdea4d" +dependencies = [ + "openssl-probe", + "rustls-pki-types", + "schannel", + "security-framework", +] + +[[package]] +name = "rustls-pki-types" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94182ad936a0c91c324cd46c6511b9510ed16af436d7b5bab34beab0afd55f7a" +dependencies = [ + "web-time", + "zeroize", +] + +[[package]] +name = "rustls-platform-verifier" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26d1e2536ce4f35f4846aa13bff16bd0ff40157cdb14cc056c7b14ba41233ba0" +dependencies = [ + "core-foundation 0.10.1", + "core-foundation-sys", + "jni", + "log", + "once_cell", + "rustls", + "rustls-native-certs", + "rustls-platform-verifier-android", + "rustls-webpki", + "security-framework", + "security-framework-sys", + "webpki-root-certs", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls-platform-verifier-android" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f87165f0995f63a9fbeea62b64d10b4d9d8e78ec6d7d51fb2125fda7bb36788f" + +[[package]] +name = "rustls-webpki" +version = "0.103.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ffdfa2f5286e2247234e03f680868ac2815974dc39e00ea15adc445d0aafe52" +dependencies = [ + "aws-lc-rs", + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + +[[package]] +name = "ryu" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "schannel" +version = "0.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "891d81b926048e76efe18581bf793546b4c0eaf8448d72be8de2bbee5fd166e1" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "security-framework" +version = "3.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3297343eaf830f66ede390ea39da1d462b6b0c1b000f420d0a83f898bbbe6ef" +dependencies = [ + "bitflags", + "core-foundation 0.10.1", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc1f0cbffaac4852523ce30d8bd3c5cdc873501d96ff467ca09b6767bb8cd5c0" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "semver" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" + +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.145" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "402a6f66d8c709116cf22f558eab210f5a50187f702eb4d7e5ef38d9a7f1c79c" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", + "serde_core", +] + +[[package]] +name = "serde_path_to_error" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10a9ff822e371bb5403e391ecd83e182e0e77ba7f6fe0160b795797109d1b457" +dependencies = [ + "itoa", + "serde", + "serde_core", +] + +[[package]] +name = "serde_spanned" +version = "0.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf41e0cfaf7226dca15e8197172c295a782857fcb97fad1808a166870dee75a3" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if", + "cpufeatures 0.2.17", + "digest", +] + +[[package]] +name = "sha2" +version = "0.10.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" +dependencies = [ + "cfg-if", + "cpufeatures 0.2.17", + "digest", +] + +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "signal-hook-registry" +version = "1.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2a4719bff48cee6b39d12c020eeb490953ad2443b7055bd0b21fca26bd8c28b" +dependencies = [ + "libc", +] + +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest", + "rand_core 0.6.4", +] + +[[package]] +name = "simd_cesu8" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11031e251abf8611c80f460e19dbdeb54a66db918e49c65a7065b46ac7aec520" +dependencies = [ + "rustc_version", + "simdutf8", +] + +[[package]] +name = "simdutf8" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e" + +[[package]] +name = "simple_asn1" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "297f631f50729c8c99b84667867963997ec0b50f32b2a7dbcab828ef0541e8bb" +dependencies = [ + "num-bigint", + "num-traits", + "thiserror", + "time", +] + +[[package]] +name = "slab" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a2ae44ef20feb57a68b23d846850f861394c2e02dc425a50098ae8c90267589" + +[[package]] +name = "smallvec" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" +dependencies = [ + "serde", +] + +[[package]] +name = "socket2" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17129e116933cf371d018bb80ae557e889637989d8638274fb25622827b03881" +dependencies = [ + "libc", + "windows-sys 0.60.2", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] + +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "sqlx" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fefb893899429669dcdd979aff487bd78f4064e5e7907e4269081e0ef7d97dc" +dependencies = [ + "sqlx-core", + "sqlx-macros", + "sqlx-mysql", + "sqlx-postgres", + "sqlx-sqlite", +] + +[[package]] +name = "sqlx-core" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee6798b1838b6a0f69c007c133b8df5866302197e404e8b6ee8ed3e3a5e68dc6" +dependencies = [ + "base64 0.22.1", + "bigdecimal", + "bytes", + "chrono", + "crc", + "crossbeam-queue", + "either", + "event-listener", + "futures-core", + "futures-intrusive", + "futures-io", + "futures-util", + "hashbrown 0.15.5", + "hashlink 0.10.0", + "indexmap", + "log", + "memchr", + "once_cell", + "percent-encoding", + "rustls", + "serde", + "serde_json", + "sha2", + "smallvec", + "thiserror", + "tokio", + "tokio-stream", + "tracing", + "url", + "uuid", + "webpki-roots 0.26.11", +] + +[[package]] +name = "sqlx-macros" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2d452988ccaacfbf5e0bdbc348fb91d7c8af5bee192173ac3636b5fb6e6715d" +dependencies = [ + "proc-macro2", + "quote", + "sqlx-core", + "sqlx-macros-core", + "syn", +] + +[[package]] +name = "sqlx-macros-core" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19a9c1841124ac5a61741f96e1d9e2ec77424bf323962dd894bdb93f37d5219b" +dependencies = [ + "dotenvy", + "either", + "heck", + "hex", + "once_cell", + "proc-macro2", + "quote", + "serde", + "serde_json", + "sha2", + "sqlx-core", + "sqlx-mysql", + "sqlx-postgres", + "sqlx-sqlite", + "syn", + "tokio", + "url", +] + +[[package]] +name = "sqlx-mysql" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa003f0038df784eb8fecbbac13affe3da23b45194bd57dba231c8f48199c526" +dependencies = [ + "atoi", + "base64 0.22.1", + "bigdecimal", + "bitflags", + "byteorder", + "bytes", + "chrono", + "crc", + "digest", + "dotenvy", + "either", + "futures-channel", + "futures-core", + "futures-io", + "futures-util", + "generic-array", + "hex", + "hkdf", + "hmac", + "itoa", + "log", + "md-5", + "memchr", + "once_cell", + "percent-encoding", + "rand 0.8.5", + "rsa", + "serde", + "sha1", + "sha2", + "smallvec", + "sqlx-core", + "stringprep", + "thiserror", + "tracing", + "uuid", + "whoami", +] + +[[package]] +name = "sqlx-postgres" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db58fcd5a53cf07c184b154801ff91347e4c30d17a3562a635ff028ad5deda46" +dependencies = [ + "atoi", + "base64 0.22.1", + "bigdecimal", + "bitflags", + "byteorder", + "chrono", + "crc", + "dotenvy", + "etcetera", + "futures-channel", + "futures-core", + "futures-util", + "hex", + "hkdf", + "hmac", + "home", + "itoa", + "log", + "md-5", + "memchr", + "num-bigint", + "once_cell", + "rand 0.8.5", + "serde", + "serde_json", + "sha2", + "smallvec", + "sqlx-core", + "stringprep", + "thiserror", + "tracing", + "uuid", + "whoami", +] + +[[package]] +name = "sqlx-sqlite" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2d12fe70b2c1b4401038055f90f151b78208de1f9f89a7dbfd41587a10c3eea" +dependencies = [ + "atoi", + "chrono", + "flume", + "futures-channel", + "futures-core", + "futures-executor", + "futures-intrusive", + "futures-util", + "libsqlite3-sys", + "log", + "percent-encoding", + "serde", + "serde_urlencoded", + "sqlx-core", + "thiserror", + "tracing", + "url", + "uuid", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "stringprep" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4df3d392d81bd458a8a621b8bffbd2302a12ffe288a9d931670948749463b1" +dependencies = [ + "unicode-bidi", + "unicode-normalization", + "unicode-properties", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.110" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a99801b5bd34ede4cf3fc688c5919368fea4e4814a4664359503e6015b280aea" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" +dependencies = [ + "futures-core", +] + +[[package]] +name = "synstructure" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags", + "core-foundation 0.9.4", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "thiserror" +version = "2.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f63587ca0f12b72a0600bcba1d40081f830876000bb46dd2337a3051618f4fc8" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "thread_local" +version = "1.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ad99c4c6d32803332c548b1af0540b357b3f5fc0be8f6c6bfe8b2e6ae784070" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "time" +version = "0.3.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e7d9e3bb61134e77bde20dd4825b97c010155709965fedf0f49bb138e52a9d" +dependencies = [ + "deranged", + "itoa", + "num-conv", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40868e7c1d2f0b8d73e4a8c7f0ff63af4f6d19be117e90bd73eb1d62cf831c6b" + +[[package]] +name = "time-macros" +version = "0.2.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30cfb0125f12d9c277f35663a0a33f8c30190f4e4574868a330595412d34ebf3" +dependencies = [ + "num-conv", + "time-core", +] + +[[package]] +name = "tiny-keccak" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +dependencies = [ + "crunchy", +] + +[[package]] +name = "tinystr" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42d3e9c45c09de15d06dd8acf5f4e0e399e85927b7f00711024eb7ae10fa4869" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tinyvec" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa5fdc3bce6191a1dbc8c02d5c8bffcf557bafa17c124c5264a458f1b0613fa" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff360e02eab121e0bc37a2d3b4d4dc622e6eda3a8e5253d5435ecf5bd4c68408" +dependencies = [ + "bytes", + "libc", + "mio", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.61.2", +] + +[[package]] +name = "tokio-macros" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af407857209536a95c8e56f8231ef2c2e2aff839b22e07a1ffcbc617e9db9fa5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1729aa945f29d91ba541258c8df89027d5792d85a8841fb65e8bf0f4ede4ef61" +dependencies = [ + "rustls", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eca58d7bba4a75707817a2c44174253f9236b2d5fbd055602e9d5c07c139a047" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2efa149fe76073d6e8fd97ef4f4eca7b67f599660115591483572e406e165594" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "toml" +version = "0.8.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc1beb996b9d83529a9e75c17a1686767d148d70663143c7854d8b4a09ced362" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.22.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "toml_write", + "winnow", +] + +[[package]] +name = "toml_write" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801" + +[[package]] +name = "tonic" +version = "0.14.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac2a5518c70fa84342385732db33fb3f44bc4cc748936eb5833d2df34d6445ef" +dependencies = [ + "async-trait", + "base64 0.22.1", + "bytes", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-timeout", + "hyper-util", + "percent-encoding", + "pin-project", + "sync_wrapper", + "tokio", + "tokio-stream", + "tower", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tonic-prost" +version = "0.14.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50849f68853be452acf590cde0b146665b8d507b3b8af17261df47e02c209ea0" +dependencies = [ + "bytes", + "prost", + "tonic", +] + +[[package]] +name = "tonic-types" +version = "0.14.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73ab1b02061f83d519bba3caa167f88f261ef05720ab8ebc954ade70de3348e8" +dependencies = [ + "prost", + "prost-types", + "tonic", +] + +[[package]] +name = "tower" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d039ad9159c98b70ecfd540b2573b97f7f52c3e8d9f8ad57a24b916a536975f9" +dependencies = [ + "futures-core", + "futures-util", + "indexmap", + "pin-project-lite", + "slab", + "sync_wrapper", + "tokio", + "tokio-util", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-http" +version = "0.6.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cfcf7e2740e6fc6d4d688b4ef00650406bb94adf4731e43c096c3a19fe40840" +dependencies = [ + "bitflags", + "bytes", + "futures-core", + "futures-util", + "http", + "http-body", + "http-body-util", + "http-range-header", + "httpdate", + "mime", + "mime_guess", + "percent-encoding", + "pin-project-lite", + "tokio", + "tokio-util", + "tower", + "tower-layer", + "tower-service", + "url", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "log", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-opentelemetry" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adbc64cba7137545b8044cb1fe9814f7aacf3c6b5f9b45be8bb5db538befdb26" +dependencies = [ + "js-sys", + "opentelemetry", + "smallvec", + "tracing", + "tracing-core", + "tracing-log", + "tracing-subscriber", + "web-time", +] + +[[package]] +name = "tracing-opentelemetry-instrumentation-sdk" +version = "0.38.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a10464b0f9cac62a3e26c08c7c9b93c5ae62f5165792b2e7e90c52940eaabef5" +dependencies = [ + "http", + "opentelemetry", + "opentelemetry-semantic-conventions", + "tracing", + "tracing-opentelemetry", +] + +[[package]] +name = "tracing-serde" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "704b1aeb7be0d0a84fc9828cae51dab5970fee5088f83d1dd7ee6f6246fc6ff1" +dependencies = [ + "serde", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7f578e5945fb242538965c2d0b04418d38ec25c79d160cd279bf0731c8d319" +dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex-automata", + "serde", + "serde_json", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", + "tracing-serde", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "typenum" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" + +[[package]] +name = "ucd-trie" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971" + +[[package]] +name = "unicase" +version = "2.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75b844d17643ee918803943289730bec8aac480150456169e647ed0b576ba539" + +[[package]] +name = "unicode-bidi" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c1cb5db39152898a79168971543b1cb5020dff7fe43c8dc468b0885f5e29df5" + +[[package]] +name = "unicode-ident" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" + +[[package]] +name = "unicode-normalization" +version = "0.1.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fd4f6878c9cb28d874b009da9e8d183b5abc80117c40bbd187a1fde336be6e8" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-properties" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7df058c713841ad818f1dc5d3fd88063241cc61f49f5fbea4b951e8cf5a8d71d" + +[[package]] +name = "unicode-segmentation" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08bc136a29a3d1758e07a9cca267be308aeebf5cfd5a10f3f67ab2097683ef5b" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + +[[package]] +name = "urlencoding" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + +[[package]] +name = "uuid" +version = "1.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f87b8aa10b915a06587d0dec516c282ff295b475d94abf425d62b57710070a2" +dependencies = [ + "getrandom 0.3.4", + "js-sys", + "serde", + "wasm-bindgen", +] + +[[package]] +name = "valuable" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "wasip2" +version = "1.0.1+wasi-0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7" +dependencies = [ + "wit-bindgen", +] + +[[package]] +name = "wasite" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b" + +[[package]] +name = "wasm-bindgen" +version = "0.2.105" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da95793dfc411fbbd93f5be7715b0578ec61fe87cb1a42b12eb625caa5c5ea60" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "551f88106c6d5e7ccc7cd9a16f312dd3b5d36ea8b4954304657d5dfba115d4a0" +dependencies = [ + "cfg-if", + "js-sys", + "once_cell", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.105" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04264334509e04a7bf8690f2384ef5265f05143a4bff3889ab7a3269adab59c2" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.105" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "420bc339d9f322e562942d52e115d57e950d12d88983a14c79b86859ee6c7ebc" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.105" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76f218a38c84bcb33c25ec7059b07847d465ce0e0a76b995e134a45adcb6af76" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "web-sys" +version = "0.3.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a1f95c0d03a47f4ae1f7a64643a6bb97465d9b740f0fa8f90ea33915c99a9a1" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki-root-certs" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b96554aa2acc8ccdb7e1c9a58a7a68dd5d13bccc69cd124cb09406db612a1c9b" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "webpki-roots" +version = "0.26.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "521bc38abb08001b01866da9f51eb7c5d647a19260e00054a8c7fd5f9e57f7a9" +dependencies = [ + "webpki-roots 1.0.4", +] + +[[package]] +name = "webpki-roots" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2878ef029c47c6e8cf779119f20fcf52bde7ad42a731b2a304bc221df17571e" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "whoami" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d4a4db5077702ca3015d3d02d74974948aba2ad9e12ab7df718ee64ccd7e97d" +dependencies = [ + "libredox", + "wasite", +] + +[[package]] +name = "winapi-util" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" +dependencies = [ + "windows-sys 0.48.0", +] + +[[package]] +name = "windows-core" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.59.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-registry" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02752bf7fbdcce7f2a27a742f798510f3e5ad88dbe84871e5168e2120c3d5720" +dependencies = [ + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-result" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets 0.53.5", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm 0.52.6", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.53.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" +dependencies = [ + "windows-link", + "windows_aarch64_gnullvm 0.53.1", + "windows_aarch64_msvc 0.53.1", + "windows_i686_gnu 0.53.1", + "windows_i686_gnullvm 0.53.1", + "windows_i686_msvc 0.53.1", + "windows_x86_64_gnu 0.53.1", + "windows_x86_64_gnullvm 0.53.1", + "windows_x86_64_msvc 0.53.1", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_i686_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" + +[[package]] +name = "winnow" +version = "0.7.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21a0236b59786fed61e2a80582dd500fe61f18b5dca67a4a067d0bc9039339cf" +dependencies = [ + "memchr", +] + +[[package]] +name = "wit-bindgen" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59" + +[[package]] +name = "writeable" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9" + +[[package]] +name = "yaml-rust2" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8902160c4e6f2fb145dbe9d6760a75e3c9522d8bf796ed7047c85919ac7115f8" +dependencies = [ + "arraydeque", + "encoding_rs", + "hashlink 0.8.4", +] + +[[package]] +name = "yoke" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72d6e5c6afb84d73944e5cedb052c4680d5657337201555f9f2a16b7406d4954" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b659052874eb698efe5b9e8cf382204678a0086ebf46982b79d6ca3182927e5d" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zerocopy" +version = "0.8.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0894878a5fa3edfd6da3f88c4805f4c8558e2b996227a3d864f47fe11e38282c" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88d2b8d9c68ad2b9e4340d7832716a4d21a22a1154777ad56ea55c51a9cf3831" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zerofrom" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50cc42e0333e05660c3587f3bf9d0478688e15d870fab3346451ce7f8c9fbea5" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zeroize" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0" + +[[package]] +name = "zerotrie" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a59c17a5562d507e4b54960e8569ebee33bee890c70aa3fe7b97e85a9fd7851" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c28719294829477f525be0186d13efa9a3c602f7ec202ca9e353d310fb9a002" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eadce39539ca5cb3985590102671f2567e659fca9666581ad3411d59207951f3" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/distributed_observability/Cargo.toml b/distributed_observability/Cargo.toml @@ -0,0 +1,109 @@ +[workspace] +resolver = "2" +members = ["otelmart", "products", "inventory", "orders"] + +[workspace.package] +version = "0.1.0" +edition = "2021" +authors = ["OpenTel Book Team"] +license = "MIT OR Apache-2.0" + +[workspace.lints.clippy] +# Pedantic lints for better code quality +pedantic = { level = "warn", priority = -1 } +# Allow some pedantic lints that are too noisy +module_name_repetitions = "allow" +missing_errors_doc = "allow" +missing_panics_doc = "allow" +must_use_candidate = "allow" + +# Style preferences +enum_glob_use = "warn" +unwrap_used = "warn" +expect_used = "warn" + +# Correctness +semicolon_if_nothing_returned = "warn" +inconsistent_struct_constructor = "warn" + +[workspace.dependencies] +# Web framework +axum = "0.8.7" +tokio = { version = "1.48.0", features = ["full"] } +tower = "0.5.2" +tower-http = { version = "0.6.6", features = ["cors"] } + +# Database +sqlx = { version = "0.8.6", features = [ + "runtime-tokio-rustls", + "postgres", + "chrono", + "uuid", + "json", + "migrate", + "bigdecimal", +] } + +# Redis +redis = { version = "0.32.7", features = ["tokio-comp", "connection-manager"] } + +# Serialization +serde = { version = "1.0.228", features = ["derive"] } +serde_json = "1.0.145" + +# Utilities +chrono = { version = "0.4.42", features = ["serde"] } +uuid = { version = "1.18.1", features = ["v4", "serde"] } +rust_decimal = { version = "1.39.0", features = ["serde"] } +bigdecimal = { version = "0.4.9", features = ["serde"] } +anyhow = "1.0.100" +thiserror = "2.0.17" + +# Configuration +toml = "0.9.8" +config = "0.14" +dotenvy = "0.15" + +# HTTP client +reqwest = { version = "0.13.4", features = ["json"] } + +# Security +bcrypt = "0.15" +jsonwebtoken = "9" + +# URL encoding +urlencoding = "2" + +# Random number generation +rand = "0.9.2" + +# Telemetry / Observability +# +# Core tracing ecosystem +tracing = "0.1.44" +tracing-subscriber = { version = "0.3.22", features = ["env-filter", "json"] } + +# OpenTelemetry core +opentelemetry = "0.32.0" +opentelemetry_sdk = "0.32.1" + +# OTLP exporter (sends traces to collectors/backends) +opentelemetry-otlp = { version = "0.32.0", features = ["grpc-tonic"] } + +# Bridge between tracing and OpenTelemetry +tracing-opentelemetry = "0.33.0" + +# HTTP instrumentation (server + client) +axum-tracing-opentelemetry = "0.38.0" +reqwest-middleware = { version = "0.5.2", features = ["json"] } +reqwest-tracing = { version = "0.7.1", features = ["opentelemetry_0_32"] } + +[profile.release] +opt-level = 3 +lto = true +codegen-units = 1 +strip = true + +[profile.dev] +opt-level = 0 +debug = true diff --git a/distributed_observability_in_rust/example_project/DOCKER_SETUP.md b/distributed_observability/DOCKER_SETUP.md diff --git a/distributed_observability_in_rust/example_project/client/angular.json b/distributed_observability/client/angular.json diff --git a/distributed_observability_in_rust/example_project/client/package-lock.json b/distributed_observability/client/package-lock.json diff --git a/distributed_observability_in_rust/example_project/client/package.json b/distributed_observability/client/package.json diff --git a/distributed_observability_in_rust/example_project/client/proxy.conf.js b/distributed_observability/client/proxy.conf.js diff --git a/distributed_observability_in_rust/example_project/client/src/app.html b/distributed_observability/client/src/app.html diff --git a/distributed_observability_in_rust/example_project/client/src/app.scss b/distributed_observability/client/src/app.scss diff --git a/distributed_observability_in_rust/example_project/client/src/app.ts b/distributed_observability/client/src/app.ts diff --git a/distributed_observability_in_rust/example_project/client/src/cart/cart.component.html b/distributed_observability/client/src/cart/cart.component.html diff --git a/distributed_observability_in_rust/example_project/client/src/cart/cart.component.scss b/distributed_observability/client/src/cart/cart.component.scss diff --git a/distributed_observability_in_rust/example_project/client/src/cart/cart.component.ts b/distributed_observability/client/src/cart/cart.component.ts diff --git a/distributed_observability_in_rust/example_project/client/src/cart/checkout.component.html b/distributed_observability/client/src/cart/checkout.component.html diff --git a/distributed_observability_in_rust/example_project/client/src/cart/checkout.component.scss b/distributed_observability/client/src/cart/checkout.component.scss diff --git a/distributed_observability_in_rust/example_project/client/src/cart/checkout.component.ts b/distributed_observability/client/src/cart/checkout.component.ts diff --git a/distributed_observability_in_rust/example_project/client/src/cart/credit-card.component.ts b/distributed_observability/client/src/cart/credit-card.component.ts diff --git a/distributed_observability_in_rust/example_project/client/src/components/busy/busy.component.html b/distributed_observability/client/src/components/busy/busy.component.html diff --git a/distributed_observability_in_rust/example_project/client/src/components/busy/busy.component.scss b/distributed_observability/client/src/components/busy/busy.component.scss diff --git a/distributed_observability_in_rust/example_project/client/src/components/busy/busy.component.ts b/distributed_observability/client/src/components/busy/busy.component.ts diff --git a/distributed_observability_in_rust/example_project/client/src/components/busy/busy.decorator.ts b/distributed_observability/client/src/components/busy/busy.decorator.ts diff --git a/distributed_observability_in_rust/example_project/client/src/components/busy/busy.service.ts b/distributed_observability/client/src/components/busy/busy.service.ts diff --git a/distributed_observability_in_rust/example_project/client/src/components/click-outside.directive.ts b/distributed_observability/client/src/components/click-outside.directive.ts diff --git a/distributed_observability_in_rust/example_project/client/src/global.d.ts b/distributed_observability/client/src/global.d.ts diff --git a/distributed_observability_in_rust/example_project/client/src/header/header.component.html b/distributed_observability/client/src/header/header.component.html diff --git a/distributed_observability_in_rust/example_project/client/src/header/header.component.scss b/distributed_observability/client/src/header/header.component.scss diff --git a/distributed_observability_in_rust/example_project/client/src/header/header.component.ts b/distributed_observability/client/src/header/header.component.ts diff --git a/distributed_observability_in_rust/example_project/client/src/header/search.component.html b/distributed_observability/client/src/header/search.component.html diff --git a/distributed_observability_in_rust/example_project/client/src/header/search.component.scss b/distributed_observability/client/src/header/search.component.scss diff --git a/distributed_observability_in_rust/example_project/client/src/header/search.component.ts b/distributed_observability/client/src/header/search.component.ts diff --git a/distributed_observability_in_rust/example_project/client/src/header/user-profile.component.html b/distributed_observability/client/src/header/user-profile.component.html diff --git a/distributed_observability_in_rust/example_project/client/src/header/user-profile.component.scss b/distributed_observability/client/src/header/user-profile.component.scss diff --git a/distributed_observability_in_rust/example_project/client/src/header/user-profile.component.ts b/distributed_observability/client/src/header/user-profile.component.ts diff --git a/distributed_observability_in_rust/example_project/client/src/index.html b/distributed_observability/client/src/index.html diff --git a/distributed_observability_in_rust/example_project/client/src/main.ts b/distributed_observability/client/src/main.ts diff --git a/distributed_observability_in_rust/example_project/client/src/products/paginate.component.html b/distributed_observability/client/src/products/paginate.component.html diff --git a/distributed_observability_in_rust/example_project/client/src/products/paginate.component.scss b/distributed_observability/client/src/products/paginate.component.scss diff --git a/distributed_observability_in_rust/example_project/client/src/products/paginate.component.ts b/distributed_observability/client/src/products/paginate.component.ts diff --git a/distributed_observability_in_rust/example_project/client/src/products/product-details.component.html b/distributed_observability/client/src/products/product-details.component.html diff --git a/distributed_observability_in_rust/example_project/client/src/products/product-details.component.scss b/distributed_observability/client/src/products/product-details.component.scss diff --git a/distributed_observability_in_rust/example_project/client/src/products/product-details.component.ts b/distributed_observability/client/src/products/product-details.component.ts diff --git a/distributed_observability_in_rust/example_project/client/src/products/product.component.html b/distributed_observability/client/src/products/product.component.html diff --git a/distributed_observability_in_rust/example_project/client/src/products/product.component.scss b/distributed_observability/client/src/products/product.component.scss diff --git a/distributed_observability_in_rust/example_project/client/src/products/product.component.ts b/distributed_observability/client/src/products/product.component.ts diff --git a/distributed_observability_in_rust/example_project/client/src/products/products-list.component.html b/distributed_observability/client/src/products/products-list.component.html diff --git a/distributed_observability_in_rust/example_project/client/src/products/products-list.component.scss b/distributed_observability/client/src/products/products-list.component.scss diff --git a/distributed_observability_in_rust/example_project/client/src/products/products-list.component.ts b/distributed_observability/client/src/products/products-list.component.ts diff --git a/distributed_observability_in_rust/example_project/client/src/products/products.routes.ts b/distributed_observability/client/src/products/products.routes.ts diff --git a/distributed_observability_in_rust/example_project/client/src/products/products.service.ts b/distributed_observability/client/src/products/products.service.ts diff --git a/distributed_observability_in_rust/example_project/client/src/root.config.ts b/distributed_observability/client/src/root.config.ts diff --git a/distributed_observability_in_rust/example_project/client/src/root.routes.ts b/distributed_observability/client/src/root.routes.ts diff --git a/distributed_observability_in_rust/example_project/client/src/services/cart.service.ts b/distributed_observability/client/src/services/cart.service.ts diff --git a/distributed_observability_in_rust/example_project/client/src/services/notification.component.ts b/distributed_observability/client/src/services/notification.component.ts diff --git a/distributed_observability_in_rust/example_project/client/src/services/notification.service.ts b/distributed_observability/client/src/services/notification.service.ts diff --git a/distributed_observability_in_rust/example_project/client/src/services/order.service.ts b/distributed_observability/client/src/services/order.service.ts diff --git a/distributed_observability_in_rust/example_project/client/src/styles.scss b/distributed_observability/client/src/styles.scss diff --git a/distributed_observability_in_rust/example_project/client/tsconfig.app.json b/distributed_observability/client/tsconfig.app.json diff --git a/distributed_observability_in_rust/example_project/client/tsconfig.json b/distributed_observability/client/tsconfig.json diff --git a/distributed_observability_in_rust/example_project/client/tsconfig.spec.json b/distributed_observability/client/tsconfig.spec.json diff --git a/distributed_observability/docker-compose.yml b/distributed_observability/docker-compose.yml @@ -0,0 +1,224 @@ +services: + # ============================================================ + # Otel Collector + # ============================================================ + otel-collector: + image: otel/opentelemetry-collector-contrib:latest + container_name: otel-collector + command: ["--config=/etc/otel-collector-config.yaml"] + volumes: + - ./otel-collector-config.yaml:/etc/otel-collector-config.yaml + ports: + - "4317:4317" + - "4318:4318" + depends_on: + jaeger: + condition: service_healthy + networks: + - app-network + + # ============================================================ + # Jaeger + # ============================================================ + jaeger: + image: jaegertracing/all-in-one:latest + container_name: jaeger + environment: + - COLLECTOR_OTLP_ENABLED=true + ports: + # OTLP ports are NOT published: the collector owns 4317/4318 on the host. + # Jaeger still receives OTLP on 4317 over app-network. + - "16686:16686" + healthcheck: + test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:14269/"] + interval: 5s + timeout: 3s + retries: 12 + start_period: 10s + networks: + - app-network + + # ============================================================ + # Database Service + # ============================================================ + # PostgreSQL with automatic schema initialization + postgres: + image: postgres:17-alpine + container_name: opentel-postgres + environment: + - POSTGRES_USER=opentel_user + - POSTGRES_PASSWORD=opentel_pass + - POSTGRES_DB=opentel_db + ports: + - "5433:5432" + volumes: + - postgres_data:/var/lib/postgresql/data + # Schema initialization scripts run automatically on first startup + - ./schemas/init:/docker-entrypoint-initdb.d + healthcheck: + test: ["CMD-SHELL", "pg_isready -U opentel_user -d opentel_db"] + interval: 10s + timeout: 5s + retries: 5 + start_period: 30s + networks: + - app-network + restart: unless-stopped + + # ============================================================ + # Products Service + # ============================================================ + # RESTful API for product catalog (runs migrations on startup) + products: + build: + context: . + dockerfile: products/Dockerfile + container_name: products-service + ports: + - "3001:3001" + environment: + - APP_DATABASE_URL=postgres://opentel_user:opentel_pass@postgres:5432/opentel_db + - OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4317 + - OTEL_SERVICE_NAME=products + - RUST_LOG=info,otel::tracing=trace + depends_on: + postgres: + condition: service_healthy + otel-collector: + condition: service_started + networks: + - app-network + restart: unless-stopped + + # ============================================================ + # Inventory Service + # ============================================================ + # RESTful API for inventory and pricing management (runs migrations on startup) + inventory: + build: + context: . + dockerfile: inventory/Dockerfile + container_name: inventory-service + ports: + - "3002:3002" + environment: + - APP_DATABASE_URL=postgres://opentel_user:opentel_pass@postgres:5432/opentel_db + - OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4317 + - OTEL_SERVICE_NAME=inventory + - RUST_LOG=info,otel::tracing=trace + depends_on: + postgres: + condition: service_healthy + otel-collector: + condition: service_started + networks: + - app-network + restart: unless-stopped + + # ============================================================ + # Orders Service + # ============================================================ + # RESTful API for order management, checkout, and shipment tracking (runs migrations on startup) + orders: + build: + context: . + dockerfile: orders/Dockerfile + container_name: orders-service + ports: + - "3003:3003" + environment: + - APP_DATABASE_URL=postgres://opentel_user:opentel_pass@postgres:5432/opentel_db + - OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4317 + - OTEL_SERVICE_NAME=orders + - RUST_LOG=info,otel::tracing=trace + depends_on: + postgres: + condition: service_healthy + otel-collector: + condition: service_started + networks: + - app-network + restart: unless-stopped + + # ============================================================ + # Data Ingestion Service + # ============================================================ + # Loads initial data after products service runs migrations + # Note: Waits 10s after products starts to ensure migrations complete + data-ingestion: + build: + context: ./schemas + dockerfile: data/Dockerfile + container_name: data-ingestion + environment: + - DB_HOST=postgres + - DB_PORT=5432 + - DB_NAME=opentel_db + - DB_USER=opentel_user + - DB_PASSWORD=opentel_pass + - WAIT_TIME=10 + depends_on: + postgres: + condition: service_healthy + products: + condition: service_started + networks: + - app-network + restart: "no" # Run once and exit + + # ============================================================ + # OtelMart Service + # ============================================================ + # Main e-commerce application (Rust backend + Angular frontend) + otelmart: + build: + context: . + dockerfile: otelmart/Dockerfile + container_name: otelmart + ports: + - "4200:4200" + environment: + - APP_DATABASE__URL=postgres://opentel_user:opentel_pass@postgres:5432/opentel_db + - APP_SERVICES__PRODUCTS_HOST=products + - APP_SERVICES__PRODUCTS_PORT=3001 + - APP_SERVICES__INVENTORY_HOST=inventory + - APP_SERVICES__INVENTORY_PORT=3002 + - APP_SERVICES__ORDERS_HOST=orders + - APP_SERVICES__ORDERS_PORT=3003 + - APP_SERVICES__INVENTORY_SERVICE_URL=http://inventory:3002 + - APP_SERVICES__ORDERS_SERVICE_URL=http://orders:3003 + - OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4317 + - OTEL_SERVICE_NAME=otelmart + - RUST_LOG=info,otel::tracing=trace + extra_hosts: + - "host.docker.internal:host-gateway" + depends_on: + postgres: + condition: service_healthy + data-ingestion: + condition: service_completed_successfully + products: + condition: service_started + inventory: + condition: service_started + orders: + condition: service_started + otel-collector: + condition: service_started + networks: + - app-network + restart: unless-stopped + +# ============================================================ +# Networks +# ============================================================ +networks: + app-network: + driver: bridge + +# ============================================================ +# Volumes +# ============================================================ +volumes: + postgres_data: + name: opentel_postgres_data diff --git a/distributed_observability/inventory/Cargo.toml b/distributed_observability/inventory/Cargo.toml @@ -0,0 +1,56 @@ +[package] +name = "inventory" +version.workspace = true +edition.workspace = true +authors.workspace = true + +[lints] +workspace = true + +[dependencies] +# Async runtime +tokio = { workspace = true } + +# Web framework +axum = { workspace = true } +tower = { workspace = true } +tower-http = { workspace = true } + +# Database +sqlx = { workspace = true } + +# Serialization +serde = { workspace = true } +serde_json = { workspace = true } + +# Utilities +uuid = { workspace = true } +chrono = { workspace = true } +anyhow = { workspace = true } +thiserror = { workspace = true } +bigdecimal = { workspace = true } + +# Configuration +config = { workspace = true } +dotenvy = { workspace = true } + +# Telemetry / Observability +# +# Core tracing ecosystem +tracing = { workspace = true } +tracing-subscriber = { workspace = true } + +# OpenTelemetry core +opentelemetry = { workspace = true } +opentelemetry_sdk = { workspace = true } + +# OTLP exporter (sends traces to collectors/backends) +opentelemetry-otlp = { workspace = true } + +# Bridge between tracing and OpenTelemetry +tracing-opentelemetry = { workspace = true } + +# HTTP instrumentation (server + client) +axum-tracing-opentelemetry = { workspace = true } +reqwest-middleware = { workspace = true } +reqwest-tracing = { workspace = true } diff --git a/distributed_observability_in_rust/example_project/inventory/Dockerfile b/distributed_observability/inventory/Dockerfile diff --git a/distributed_observability_in_rust/example_project/inventory/config.docker.toml b/distributed_observability/inventory/config.docker.toml diff --git a/distributed_observability_in_rust/example_project/inventory/config.toml b/distributed_observability/inventory/config.toml diff --git a/distributed_observability_in_rust/example_project/inventory/src/config.rs b/distributed_observability/inventory/src/config.rs diff --git a/distributed_observability_in_rust/example_project/inventory/src/db/mod.rs b/distributed_observability/inventory/src/db/mod.rs diff --git a/distributed_observability/inventory/src/handlers/inventory.rs b/distributed_observability/inventory/src/handlers/inventory.rs @@ -0,0 +1,367 @@ +//! Inventory/stock management API handlers +//! +//! This module contains the HTTP request handlers for inventory-related endpoints. + +use axum::{ + extract::{Path, Query, State}, + http::StatusCode, + response::{IntoResponse, Json}, +}; +use sqlx::{PgPool, Postgres, QueryBuilder, Row}; +use tracing::instrument; +use uuid::Uuid; + +use crate::models::{ + ConfirmSaleRequest, InventoryQueryParams, InventoryResponse, InventoryWithPricing, + ReleaseStockRequest, ReserveStockRequest, StockOperationResponse, UpdateStockRequest, +}; +use crate::utils::{calculate_pagination, calculate_total_pages, internal_error, not_found_error}; + +/// List inventory with pagination and filtering +/// +/// # Endpoint +/// `GET /inventory` +/// +/// # Query Parameters +/// - `page` (default: 1) - Page number (1-indexed) +/// - `page_size` (default: 20, max: 100) - Items per page +/// - `stock_status` - Filter by status ('in_stock', 'low_stock', 'out_of_stock') +/// - `product_uuid` - Filter by specific product +/// - `min_stock` / `max_stock` - Filter by available quantity range +#[instrument( + name = "list_inventory", + skip(pool), + fields( + page = params.page, + page_size = params.page_size, + stock_status = ?params.stock_status + ) +)] +pub async fn list_inventory( + State(pool): State<PgPool>, + Query(params): Query<InventoryQueryParams>, +) -> impl IntoResponse { + // Apply pagination defaults and constraints + let (page, page_size, offset) = calculate_pagination(params.page, params.page_size); + + // Build count query with QueryBuilder for safe parameter binding + let mut count_builder: QueryBuilder<Postgres> = + QueryBuilder::new("SELECT COUNT(*) FROM v_product_inventory_pricing"); + + let mut has_filters = false; + + // Apply filters to count query + if let Some(ref status) = params.stock_status { + count_builder.push(if has_filters { " AND " } else { " WHERE " }); + has_filters = true; + count_builder.push("stock_status = "); + count_builder.push_bind(status); + } + + if let Some(product_uuid) = params.product_uuid { + count_builder.push(if has_filters { " AND " } else { " WHERE " }); + has_filters = true; + count_builder.push("product_uuid = "); + count_builder.push_bind(product_uuid); + } + + if let Some(min_stock) = params.min_stock { + count_builder.push(if has_filters { " AND " } else { " WHERE " }); + has_filters = true; + count_builder.push("available_quantity >= "); + count_builder.push_bind(min_stock); + } + + if let Some(max_stock) = params.max_stock { + count_builder.push(if has_filters { " AND " } else { " WHERE " }); + count_builder.push("available_quantity <= "); + count_builder.push_bind(max_stock); + } + + // Execute count query + let total_count: i64 = match count_builder.build_query_scalar().fetch_one(&pool).await { + Ok(count) => count, + Err(e) => { + return internal_error("Failed to count inventory", e.to_string()); + } + }; + + // Build main query with same filters + let mut query_builder: QueryBuilder<Postgres> = + QueryBuilder::new("SELECT * FROM v_product_inventory_pricing"); + + let mut has_filters = false; + + // Apply same filters to main query + if let Some(ref status) = params.stock_status { + query_builder.push(if has_filters { " AND " } else { " WHERE " }); + has_filters = true; + query_builder.push("stock_status = "); + query_builder.push_bind(status); + } + + if let Some(product_uuid) = params.product_uuid { + query_builder.push(if has_filters { " AND " } else { " WHERE " }); + has_filters = true; + query_builder.push("product_uuid = "); + query_builder.push_bind(product_uuid); + } + + if let Some(min_stock) = params.min_stock { + query_builder.push(if has_filters { " AND " } else { " WHERE " }); + has_filters = true; + query_builder.push("available_quantity >= "); + query_builder.push_bind(min_stock); + } + + if let Some(max_stock) = params.max_stock { + query_builder.push(if has_filters { " AND " } else { " WHERE " }); + query_builder.push("available_quantity <= "); + query_builder.push_bind(max_stock); + } + + // Add ordering and pagination + query_builder.push(" ORDER BY stock_status DESC, available_quantity ASC LIMIT "); + query_builder.push_bind(page_size); + query_builder.push(" OFFSET "); + query_builder.push_bind(offset); + + // Execute main query + let inventory: Vec<InventoryWithPricing> = + match query_builder.build_query_as().fetch_all(&pool).await { + Ok(inventory) => inventory, + Err(e) => { + return internal_error("Failed to fetch inventory", e.to_string()); + } + }; + + let total_pages = calculate_total_pages(total_count, page_size); + + let response = InventoryResponse { + inventory, + total_count, + page, + page_size, + total_pages, + }; + + (StatusCode::OK, Json(response)).into_response() +} + +/// Get inventory for a specific product by UUID +/// +/// # Endpoint +/// `GET /inventory/{product_uuid}` +#[instrument( + name = "get_inventory_by_product", + skip(pool), + fields(product.uuid = %product_uuid) +)] +pub async fn get_inventory_by_product( + State(pool): State<PgPool>, + Path(product_uuid): Path<Uuid>, +) -> impl IntoResponse { + let result = sqlx::query_as::<_, InventoryWithPricing>( + r#" + SELECT * FROM v_product_inventory_pricing + WHERE product_uuid = $1 + "#, + ) + .bind(product_uuid) + .fetch_optional(&pool) + .await; + + match result { + Ok(Some(inventory)) => (StatusCode::OK, Json(inventory)).into_response(), + Ok(None) => not_found_error( + "Inventory not found for product", + serde_json::json!({"product_uuid": product_uuid.to_string()}), + ), + Err(e) => internal_error("Failed to fetch inventory", e.to_string()), + } +} + +/// Update stock quantity for a product +/// +/// # Endpoint +/// `PUT /inventory/{product_uuid}` +#[instrument( + name = "update_stock", + skip(pool, request), + fields( + product.uuid = %product_uuid, + quantity = request.quantity + ) +)] +pub async fn update_stock( + State(pool): State<PgPool>, + Path(product_uuid): Path<Uuid>, + Json(request): Json<UpdateStockRequest>, +) -> impl IntoResponse { + let result = sqlx::query( + r#" + UPDATE product_inventory + SET stock_quantity = $1, + reorder_level = COALESCE($2, reorder_level), + reorder_quantity = COALESCE($3, reorder_quantity), + last_restocked_at = CURRENT_TIMESTAMP + WHERE product_uuid = $4 + RETURNING available_quantity + "#, + ) + .bind(request.quantity) + .bind(request.reorder_level) + .bind(request.reorder_quantity) + .bind(product_uuid) + .fetch_optional(&pool) + .await; + + match result { + Ok(Some(row)) => { + let available_quantity: Option<i32> = row.get("available_quantity"); + ( + StatusCode::OK, + Json(StockOperationResponse { + success: true, + message: "Stock updated successfully".to_string(), + product_uuid, + available_quantity, + }), + ) + .into_response() + } + Ok(None) => not_found_error( + "Product not found in inventory", + serde_json::json!({"product_uuid": product_uuid.to_string()}), + ), + Err(e) => internal_error("Failed to update stock", e.to_string()), + } +} + +/// Reserve stock for an order +/// +/// # Endpoint +/// `POST /inventory/reserve` +#[instrument( + name = "reserve_stock", + skip(pool), + fields( + product.uuid = %request.product_uuid, + quantity = request.quantity + ) +)] +pub async fn reserve_stock( + State(pool): State<PgPool>, + Json(request): Json<ReserveStockRequest>, +) -> impl IntoResponse { + let result = sqlx::query_scalar::<_, bool>(r#"SELECT reserve_stock($1, $2)"#) + .bind(request.product_uuid) + .bind(request.quantity) + .fetch_one(&pool) + .await; + + match result { + Ok(success) => { + if success { + ( + StatusCode::OK, + Json(StockOperationResponse { + success: true, + message: format!("Reserved {} units", request.quantity), + product_uuid: request.product_uuid, + available_quantity: None, + }), + ) + .into_response() + } else { + ( + StatusCode::CONFLICT, + Json(StockOperationResponse { + success: false, + message: "Insufficient stock available".to_string(), + product_uuid: request.product_uuid, + available_quantity: None, + }), + ) + .into_response() + } + } + Err(e) => internal_error("Failed to reserve stock", e.to_string()), + } +} + +/// Release reserved stock +/// +/// # Endpoint +/// `POST /inventory/release` +#[instrument( + name = "release_stock", + skip(pool), + fields( + product.uuid = %request.product_uuid, + quantity = request.quantity + ) +)] +pub async fn release_stock( + State(pool): State<PgPool>, + Json(request): Json<ReleaseStockRequest>, +) -> impl IntoResponse { + let result = sqlx::query(r#"SELECT release_stock($1, $2)"#) + .bind(request.product_uuid) + .bind(request.quantity) + .execute(&pool) + .await; + + match result { + Ok(_) => ( + StatusCode::OK, + Json(StockOperationResponse { + success: true, + message: format!("Released {} units", request.quantity), + product_uuid: request.product_uuid, + available_quantity: None, + }), + ) + .into_response(), + Err(e) => internal_error("Failed to release stock", e.to_string()), + } +} + +/// Confirm a sale and decrease stock +/// +/// # Endpoint +/// `POST /inventory/confirm-sale` +#[instrument( + name = "confirm_sale", + skip(pool), + fields( + product.uuid = %request.product_uuid, + order.uuid = %request.order_uuid, + quantity = request.quantity + ) +)] +pub async fn confirm_sale( + State(pool): State<PgPool>, + Json(request): Json<ConfirmSaleRequest>, +) -> impl IntoResponse { + let result = sqlx::query(r#"SELECT confirm_stock_sale($1, $2, $3)"#) + .bind(request.product_uuid) + .bind(request.quantity) + .bind(request.order_uuid) + .execute(&pool) + .await; + + match result { + Ok(_) => ( + StatusCode::OK, + Json(StockOperationResponse { + success: true, + message: format!("Confirmed sale of {} units", request.quantity), + product_uuid: request.product_uuid, + available_quantity: None, + }), + ) + .into_response(), + Err(e) => internal_error("Failed to confirm sale", e.to_string()), + } +} diff --git a/distributed_observability_in_rust/example_project/inventory/src/handlers/mod.rs b/distributed_observability/inventory/src/handlers/mod.rs diff --git a/distributed_observability/inventory/src/handlers/pricing.rs b/distributed_observability/inventory/src/handlers/pricing.rs @@ -0,0 +1,210 @@ +//! Pricing API handlers +//! +//! This module contains the HTTP request handlers for pricing-related endpoints. + +use axum::{ + extract::{Path, Query, State}, + http::StatusCode, + response::{IntoResponse, Json}, +}; +use sqlx::{PgPool, Postgres, QueryBuilder}; +use tracing::instrument; +use uuid::Uuid; + +use crate::models::{PricingQueryParams, PricingResponse, ProductPricing, UpdatePricingRequest}; +use crate::utils::{calculate_pagination, calculate_total_pages, internal_error, not_found_error}; + +/// List pricing with pagination and filtering +/// +/// # Endpoint +/// `GET /pricing` +/// +/// # Query Parameters +/// - `page` (default: 1) - Page number (1-indexed) +/// - `page_size` (default: 20, max: 100) - Items per page +/// - `product_uuid` - Filter by specific product +/// - `min_price` / `max_price` - Filter by price range +/// - `has_discount` - Filter by discount presence +#[instrument(name = "list_pricing", skip(pool, params))] +pub async fn list_pricing( + State(pool): State<PgPool>, + Query(params): Query<PricingQueryParams>, +) -> impl IntoResponse { + // Apply pagination defaults and constraints + let (page, page_size, offset) = calculate_pagination(params.page, params.page_size); + + // Build count query with QueryBuilder for safe parameter binding + let mut count_builder: QueryBuilder<Postgres> = + QueryBuilder::new("SELECT COUNT(*) FROM product_pricing WHERE is_active = true"); + + // Apply filters to count query (all use AND since WHERE is_active is already present) + if let Some(product_uuid) = params.product_uuid { + count_builder.push(" AND product_uuid = "); + count_builder.push_bind(product_uuid); + } + + if let Some(ref min_price) = params.min_price { + count_builder.push(" AND final_price >= "); + count_builder.push_bind(min_price); + } + + if let Some(ref max_price) = params.max_price { + count_builder.push(" AND final_price <= "); + count_builder.push_bind(max_price); + } + + if let Some(has_discount) = params.has_discount { + if has_discount { + count_builder.push(" AND discount_percentage > 0"); + } else { + count_builder.push(" AND (discount_percentage IS NULL OR discount_percentage = 0)"); + } + } + + // Execute count query + let total_count: i64 = match count_builder.build_query_scalar().fetch_one(&pool).await { + Ok(count) => count, + Err(e) => { + return internal_error("Failed to count pricing", e.to_string()); + } + }; + + // Build main query with same filters + let mut query_builder: QueryBuilder<Postgres> = + QueryBuilder::new("SELECT * FROM product_pricing WHERE is_active = true"); + + // Apply same filters to main query (all use AND since WHERE is_active is already present) + if let Some(product_uuid) = params.product_uuid { + query_builder.push(" AND product_uuid = "); + query_builder.push_bind(product_uuid); + } + + if let Some(ref min_price) = params.min_price { + query_builder.push(" AND final_price >= "); + query_builder.push_bind(min_price); + } + + if let Some(ref max_price) = params.max_price { + query_builder.push(" AND final_price <= "); + query_builder.push_bind(max_price); + } + + if let Some(has_discount) = params.has_discount { + if has_discount { + query_builder.push(" AND discount_percentage > 0"); + } else { + query_builder.push(" AND (discount_percentage IS NULL OR discount_percentage = 0)"); + } + } + + // Add ordering and pagination + query_builder.push(" ORDER BY updated_at DESC LIMIT "); + query_builder.push_bind(page_size); + query_builder.push(" OFFSET "); + query_builder.push_bind(offset); + + // Execute main query + let pricing: Vec<ProductPricing> = match query_builder.build_query_as().fetch_all(&pool).await { + Ok(pricing) => pricing, + Err(e) => { + return internal_error("Failed to fetch pricing", e.to_string()); + } + }; + + let total_pages = calculate_total_pages(total_count, page_size); + + let response = PricingResponse { + pricing, + total_count, + page, + page_size, + total_pages, + }; + + (StatusCode::OK, Json(response)).into_response() +} + +/// Get pricing for a specific product by UUID +/// +/// # Endpoint +/// `GET /pricing/{product_uuid}` +#[instrument(name = "get_pricing_by_product", skip(pool), fields(product.uuid = %product_uuid))] +pub async fn get_pricing_by_product( + State(pool): State<PgPool>, + Path(product_uuid): Path<Uuid>, +) -> impl IntoResponse { + let result = sqlx::query_as::<_, ProductPricing>( + r#" + SELECT * FROM product_pricing + WHERE product_uuid = $1 AND is_active = true + "#, + ) + .bind(product_uuid) + .fetch_optional(&pool) + .await; + + match result { + Ok(Some(pricing)) => (StatusCode::OK, Json(pricing)).into_response(), + Ok(None) => not_found_error( + "Pricing not found for product", + serde_json::json!({"product_uuid": product_uuid.to_string()}), + ), + Err(e) => internal_error("Failed to fetch pricing", e.to_string()), + } +} + +/// Create or update pricing for a product +/// +/// # Endpoint +/// `PUT /pricing/{product_uuid}` +#[instrument(name = "upsert_pricing", skip(pool, request), fields(product.uuid = %product_uuid))] +pub async fn upsert_pricing( + State(pool): State<PgPool>, + Path(product_uuid): Path<Uuid>, + Json(request): Json<UpdatePricingRequest>, +) -> impl IntoResponse { + // First, deactivate existing active pricing + if let Err(e) = sqlx::query( + r#" + UPDATE product_pricing + SET is_active = false + WHERE product_uuid = $1 AND is_active = true + "#, + ) + .bind(product_uuid) + .execute(&pool) + .await + { + eprintln!("Error deactivating old pricing: {}", e); + } + + // Insert new pricing + let result = sqlx::query_as::<_, ProductPricing>( + r#" + INSERT INTO product_pricing ( + product_uuid, + final_price, + initial_price, + currency, + price_valid_from, + price_valid_until, + is_active + ) + VALUES ($1, $2, $3, $4, $5, $6, true) + RETURNING * + "#, + ) + .bind(product_uuid) + .bind(request.final_price) + .bind(request.initial_price) + .bind(request.currency.unwrap_or_else(|| "USD".to_string())) + .bind(request.price_valid_from) + .bind(request.price_valid_until) + .fetch_one(&pool) + .await; + + match result { + Ok(pricing) => (StatusCode::OK, Json(pricing)).into_response(), + Err(e) => internal_error("Failed to update pricing", e.to_string()), + } +} diff --git a/distributed_observability/inventory/src/main.rs b/distributed_observability/inventory/src/main.rs @@ -0,0 +1,131 @@ +//! Inventory Service +//! +//! A microservice for managing product inventory, stock levels, and pricing. +//! +//! # Features +//! - Product inventory management (stock levels, reservations) +//! - Pricing management with discounts +//! - Stock reservation for orders +//! - Inventory transaction audit trail +//! - PostgreSQL database with inventory schema +//! - CORS enabled for web client access +//! +//! # API Endpoints +//! ## Inventory +//! - `GET /inventory` - List inventory with filters and pagination +//! - `GET /inventory/{product_uuid}` - Get inventory for a specific product +//! - `PUT /inventory/{product_uuid}` - Update stock quantity +//! - `POST /inventory/reserve` - Reserve stock for an order +//! - `POST /inventory/release` - Release reserved stock +//! - `POST /inventory/confirm-sale` - Confirm sale and decrease stock +//! +//! ## Pricing +//! - `GET /pricing` - List pricing with filters and pagination +//! - `GET /pricing/{product_uuid}` - Get pricing for a specific product +//! - `PUT /pricing/{product_uuid}` - Create or update pricing +//! +//! # Configuration +//! The service is configured via: +//! - Environment variables (loaded from .env if present) +//! - config.toml file +//! +//! # Database +//! Uses the `inventory` schema in PostgreSQL with automatic search path configuration. +//! Migrations are run automatically on startup. + +mod config; +mod db; +mod handlers; +mod models; +mod telemetry; +mod utils; + +use anyhow::Result; +use axum::{ + routing::{get, post, put}, + Router, +}; +use axum_tracing_opentelemetry::middleware::{OtelAxumLayer, OtelInResponseLayer}; +use std::net::SocketAddr; +use tower_http::cors::CorsLayer; +use tracing::info; + +use config::Config; +use db::Database; + +#[tokio::main] +async fn main() -> Result<()> { + // Load environment variables from .env file if present + dotenvy::dotenv().ok(); + + // Initialize telemetry (tracing + OpenTelemetry) + let tracer_provider = telemetry::init_telemetry("inventory"); + + // Load configuration from config.toml + let config = Config::load()?; + + // Log startup information using tracing macros + info!( + port = config.server.port, + database_url = %config.database.url, + "Starting Inventory Service" + ); + + // Initialize database connection pool + let db = Database::new(&config.database.url, config.database.max_connections).await?; + + // Build the application router with all endpoints + let app = Router::new() + // Inventory endpoints + .route("/inventory", get(handlers::list_inventory)) + .route( + "/inventory/{product_uuid}", + get(handlers::get_inventory_by_product), + ) + .route("/inventory/{product_uuid}", put(handlers::update_stock)) + .route("/inventory/reserve", post(handlers::reserve_stock)) + .route("/inventory/release", post(handlers::release_stock)) + .route("/inventory/confirm-sale", post(handlers::confirm_sale)) + // Pricing endpoints + .route("/pricing", get(handlers::list_pricing)) + .route( + "/pricing/{product_uuid}", + get(handlers::get_pricing_by_product), + ) + .route("/pricing/{product_uuid}", put(handlers::upsert_pricing)) + // Include trace context as header into the response + .layer(OtelInResponseLayer::default()) + // Start OpenTelemetry trace on incoming request + .layer(OtelAxumLayer::default()) + // Enable CORS for all routes + .layer(CorsLayer::permissive()) + // Add database pool to application state + .with_state(db.pool().clone()); + + // Create socket address from configuration + let addr = SocketAddr::from(([0, 0, 0, 0], config.server.port)); + + // Log API documentation + info!(address = %addr, "Inventory Service listening"); + info!("Available endpoints:"); + info!(" Inventory:"); + info!(" GET /inventory - List inventory (with pagination & filters)"); + info!(" GET /inventory/{{product_uuid}} - Get inventory for product"); + info!(" PUT /inventory/{{product_uuid}} - Update stock quantity"); + info!(" POST /inventory/reserve - Reserve stock for order"); + info!(" POST /inventory/release - Release reserved stock"); + info!(" POST /inventory/confirm-sale - Confirm sale and decrease stock"); + info!(" Pricing:"); + info!(" GET /pricing - List pricing (with pagination & filters)"); + info!(" GET /pricing/{{product_uuid}} - Get pricing for product"); + info!(" PUT /pricing/{{product_uuid}} - Create or update pricing"); + + // Start the HTTP server + let listener = tokio::net::TcpListener::bind(addr).await?; + axum::serve(listener, app).await?; + + // Shutdown telemetry on exit (flush pending spans) + telemetry::shutdown_telemetry(tracer_provider); + + Ok(()) +} diff --git a/distributed_observability_in_rust/example_project/inventory/src/models/inventory.rs b/distributed_observability/inventory/src/models/inventory.rs diff --git a/distributed_observability_in_rust/example_project/inventory/src/models/mod.rs b/distributed_observability/inventory/src/models/mod.rs diff --git a/distributed_observability_in_rust/example_project/inventory/src/models/pricing.rs b/distributed_observability/inventory/src/models/pricing.rs diff --git a/distributed_observability/inventory/src/telemetry.rs b/distributed_observability/inventory/src/telemetry.rs @@ -0,0 +1,92 @@ +//! Telemetry initialization for the Inventory service. +//! +//! This module configures OpenTelemetry tracing with OTLP export to Jaeger. +//! It sets up a layered tracing subscriber that outputs both to stdout and +//! sends spans to the configured OTLP endpoint. + +use opentelemetry::global; +use opentelemetry::trace::TracerProvider as _; +use opentelemetry_otlp::WithExportConfig; +use opentelemetry_sdk::{propagation::TraceContextPropagator, trace::SdkTracerProvider, Resource}; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter}; + +/// Initializes the telemetry pipeline for the service. +/// +/// This function sets up: +/// - An OTLP exporter that sends traces to Jaeger (via OTEL_EXPORTER_OTLP_ENDPOINT) +/// - A tracing subscriber with environment-based filtering (RUST_LOG) +/// - Console output for local debugging +/// +/// # Arguments +/// * `service_name` - The name of this service, used to identify traces in Jaeger +/// +/// # Returns +/// * `SdkTracerProvider` - The tracer provider, which should be kept alive and +/// shut down gracefully when the application exits +/// +/// # Panics +/// Panics if the OTLP exporter or tracing subscriber cannot be initialized. +pub fn init_telemetry(service_name: &str) -> SdkTracerProvider { + // Set up W3C Trace Context propagator for cross-service trace correlation + global::set_text_map_propagator(TraceContextPropagator::new()); + + // Get the OTLP endpoint from environment, defaulting to localhost for local dev + let otlp_endpoint = std::env::var("OTEL_EXPORTER_OTLP_ENDPOINT") + .unwrap_or_else(|_| "http://localhost:4317".to_string()); + + // Create the OTLP exporter configured to send traces via gRPC + let exporter = opentelemetry_otlp::SpanExporter::builder() + .with_tonic() + .with_endpoint(&otlp_endpoint) + .build() + .expect("Failed to create OTLP exporter"); + + // Build the tracer provider with the exporter and service resource + let provider = SdkTracerProvider::builder() + .with_batch_exporter(exporter) + .with_resource( + Resource::builder_empty() + .with_service_name(service_name.to_string()) + .build(), + ) + .build(); + + // Create a tracer from the provider for the OpenTelemetry layer + let tracer = provider.tracer(service_name.to_string()); + + // Create the OpenTelemetry tracing layer + let otel_layer = tracing_opentelemetry::layer().with_tracer(tracer); + + // Create an environment filter for log levels (defaults to "info") + // Include otel::tracing=trace to allow axum-tracing-opentelemetry spans through + let env_filter = EnvFilter::try_from_default_env() + .unwrap_or_else(|_| EnvFilter::new("info,otel::tracing=trace")); + + // Create a formatting layer for console output + let fmt_layer = tracing_subscriber::fmt::layer() + .with_target(true) + .with_thread_ids(false) + .compact(); + + // Combine all layers into a subscriber and set it as the global default + tracing_subscriber::registry() + .with(env_filter) + .with(fmt_layer) + .with(otel_layer) + .init(); + + provider +} + +/// Shuts down the telemetry pipeline gracefully. +/// +/// This ensures all pending spans are flushed to the OTLP endpoint +/// before the application exits. +/// +/// # Arguments +/// * `provider` - The tracer provider returned from `init_telemetry` +pub fn shutdown_telemetry(provider: SdkTracerProvider) { + if let Err(e) = provider.shutdown() { + eprintln!("Failed to shutdown tracer provider: {e}"); + } +} diff --git a/distributed_observability_in_rust/example_project/inventory/src/utils.rs b/distributed_observability/inventory/src/utils.rs diff --git a/distributed_observability/orders/Cargo.toml b/distributed_observability/orders/Cargo.toml @@ -0,0 +1,59 @@ +[package] +name = "orders" +version.workspace = true +edition.workspace = true +authors.workspace = true + +[lints] +workspace = true + +[dependencies] +# Async runtime +tokio = { workspace = true } + +# Web framework +axum = { workspace = true } +tower = { workspace = true } +tower-http = { workspace = true } + +# Database +sqlx = { workspace = true } + +# Serialization +serde = { workspace = true } +serde_json = { workspace = true } + +# Utilities +uuid = { workspace = true } +chrono = { workspace = true } +anyhow = { workspace = true } +thiserror = { workspace = true } +bigdecimal = { workspace = true } + +# Configuration +config = { workspace = true } +dotenvy = { workspace = true } + +# HTTP client +reqwest = { workspace = true } + +# Telemetry / Observability +# +# Core tracing ecosystem +tracing = { workspace = true } +tracing-subscriber = { workspace = true } + +# OpenTelemetry core +opentelemetry = { workspace = true } +opentelemetry_sdk = { workspace = true } + +# OTLP exporter (sends traces to collectors/backends) +opentelemetry-otlp = { workspace = true } + +# Bridge between tracing and OpenTelemetry +tracing-opentelemetry = { workspace = true } + +# HTTP instrumentation (server + client) +axum-tracing-opentelemetry = { workspace = true } +reqwest-middleware = { workspace = true } +reqwest-tracing = { workspace = true } diff --git a/distributed_observability_in_rust/example_project/orders/Dockerfile b/distributed_observability/orders/Dockerfile diff --git a/distributed_observability_in_rust/example_project/orders/config.docker.toml b/distributed_observability/orders/config.docker.toml diff --git a/distributed_observability_in_rust/example_project/orders/config.toml b/distributed_observability/orders/config.toml diff --git a/distributed_observability_in_rust/example_project/orders/src/config.rs b/distributed_observability/orders/src/config.rs diff --git a/distributed_observability_in_rust/example_project/orders/src/db/mod.rs b/distributed_observability/orders/src/db/mod.rs diff --git a/distributed_observability_in_rust/example_project/orders/src/handlers/mod.rs b/distributed_observability/orders/src/handlers/mod.rs diff --git a/distributed_observability/orders/src/handlers/orders.rs b/distributed_observability/orders/src/handlers/orders.rs @@ -0,0 +1,930 @@ +//! Order management API handlers + +use axum::{ + extract::{Path, Query, State}, + http::StatusCode, + response::{IntoResponse, Json}, +}; +use bigdecimal::BigDecimal; +use sqlx::{PgPool, Row}; +use tracing::instrument; +use uuid::Uuid; + +use crate::models::{CreateOrderRequest, OrderComplete, OrderQueryParams, OrdersResponse}; +use crate::AppState; + +/// Product detail response from products service +#[derive(Debug, serde::Deserialize)] +struct ProductDetail { + product_name: String, + final_price: BigDecimal, + is_active: bool, +} + +/// Request to reserve stock in inventory service +#[derive(Debug, serde::Serialize)] +struct ReserveStockRequest { + product_uuid: Uuid, + quantity: i32, +} + +/// Request to release reserved stock in inventory service +#[derive(Debug, serde::Serialize)] +struct ReleaseStockRequest { + product_uuid: Uuid, + quantity: i32, +} + +/// Request to confirm sale in inventory service +#[derive(Debug, serde::Serialize)] +struct ConfirmSaleRequest { + product_uuid: Uuid, + quantity: i32, + order_uuid: Uuid, +} + +/// Response from inventory stock operations +#[derive(Debug, serde::Deserialize)] +struct StockOperationResponse { + success: bool, + message: String, + available_quantity: Option<i32>, +} + +/// Release reserved stock for a product in the inventory service +/// +/// Calls the inventory service to release previously reserved stock. +/// Used for rollback when order creation fails. +async fn release_stock(state: &AppState, product_uuid: Uuid, quantity: i32) { + let url = format!("{}/inventory/release", state.inventory_service_url()); + + let request_body = ReleaseStockRequest { + product_uuid, + quantity, + }; + + let response = state + .http_client() + .post(&url) + .json(&request_body) + .send() + .await; + + match response { + Ok(resp) => { + if resp.status().is_success() { + eprintln!( + "Successfully released {} units of stock for product {}", + quantity, product_uuid + ); + } else { + eprintln!( + "Failed to release stock for product {}: status {}", + product_uuid, + resp.status() + ); + } + } + Err(e) => { + eprintln!( + "Error calling inventory service to release stock for product {}: {}", + product_uuid, e + ); + } + } +} + +/// Release all reserved stock (for rollback scenarios) +/// +/// Iterates through all reserved items and releases their stock. +/// Logs errors but doesn't fail - this is a best-effort cleanup. +async fn release_all_reserved_stock(state: &AppState, reserved_items: &[(Uuid, i32)]) { + if reserved_items.is_empty() { + return; + } + + eprintln!( + "Rolling back stock reservations for {} items", + reserved_items.len() + ); + + for (product_uuid, quantity) in reserved_items { + release_stock(state, *product_uuid, *quantity).await; + } +} + +/// Confirm a sale with the inventory service +/// +/// Calls the inventory service to confirm the sale and convert reserved stock to sold. +/// This is called after an order is successfully created and committed. +async fn confirm_sale( + state: &AppState, + product_uuid: Uuid, + quantity: i32, + order_uuid: Uuid, +) -> Result<(), String> { + let url = format!("{}/inventory/confirm-sale", state.inventory_service_url()); + + let request_body = ConfirmSaleRequest { + product_uuid, + quantity, + order_uuid, + }; + + let response = state + .http_client() + .post(&url) + .json(&request_body) + .send() + .await + .map_err(|e| format!("Failed to call inventory service: {}", e))?; + + if response.status().is_success() { + Ok(()) + } else { + Err(format!( + "Inventory service returned error status: {}", + response.status() + )) + } +} + +/// Confirm all sales for order items +/// +/// Iterates through all order items and confirms the sale with inventory service. +/// Logs errors but doesn't fail the order since it's already committed. +async fn confirm_all_sales(state: &AppState, order_uuid: Uuid, items: &[(Uuid, i32)]) { + if items.is_empty() { + return; + } + + println!( + "Confirming sales with inventory service for {} items in order {}", + items.len(), + order_uuid + ); + + for (product_uuid, quantity) in items { + match confirm_sale(state, *product_uuid, *quantity, order_uuid).await { + Ok(_) => { + println!( + "Successfully confirmed sale of {} units for product {} in order {}", + quantity, product_uuid, order_uuid + ); + } + Err(e) => { + // Log error but don't fail - order is already committed + eprintln!( + "Failed to confirm sale for product {} in order {}: {}", + product_uuid, order_uuid, e + ); + eprintln!("WARNING: Stock reservation remains in place. Manual intervention may be required."); + } + } + } +} + +/// Reserve stock for a product in the inventory service +/// +/// Calls the inventory service to reserve stock for an order. +/// Returns error if insufficient stock is available. +async fn reserve_stock( + state: &AppState, + product_uuid: Uuid, + quantity: i32, +) -> Result<StockOperationResponse, axum::response::Response> { + let url = format!("{}/inventory/reserve", state.inventory_service_url()); + + let request_body = ReserveStockRequest { + product_uuid, + quantity, + }; + + let response = match state + .http_client() + .post(&url) + .json(&request_body) + .send() + .await + { + Ok(resp) => resp, + Err(e) => { + eprintln!("Failed to call inventory service: {}", e); + return Err(( + StatusCode::SERVICE_UNAVAILABLE, + Json(serde_json::json!({ + "error": "Inventory service unavailable", + "details": e.to_string() + })), + ) + .into_response()); + } + }; + + match response.status() { + reqwest::StatusCode::OK => { + let stock_response: StockOperationResponse = match response.json().await { + Ok(r) => r, + Err(e) => { + eprintln!("Failed to parse inventory response: {}", e); + return Err(( + StatusCode::INTERNAL_SERVER_ERROR, + Json(serde_json::json!({ + "error": "Failed to parse inventory response", + "details": e.to_string() + })), + ) + .into_response()); + } + }; + + if !stock_response.success { + return Err(( + StatusCode::CONFLICT, + Json(serde_json::json!({ + "error": "Insufficient stock", + "product_uuid": product_uuid.to_string(), + "requested_quantity": quantity, + "available_quantity": stock_response.available_quantity, + "message": stock_response.message + })), + ) + .into_response()); + } + + Ok(stock_response) + } + reqwest::StatusCode::CONFLICT => { + // Inventory service returned 409 - insufficient stock + let error_response: serde_json::Value = response.json().await.unwrap_or_else(|_| { + serde_json::json!({ + "error": "Insufficient stock", + "product_uuid": product_uuid.to_string() + }) + }); + + Err((StatusCode::CONFLICT, Json(error_response)).into_response()) + } + status => { + eprintln!("Inventory service returned status: {}", status); + Err(( + StatusCode::INTERNAL_SERVER_ERROR, + Json(serde_json::json!({ + "error": "Failed to reserve stock", + "status": status.as_u16() + })), + ) + .into_response()) + } + } +} + +/// Validate that a product exists and is available +/// +/// Calls the products service to verify the product exists and is active. +/// Returns the product details for further validation (price, stock, etc.) +async fn validate_product( + state: &AppState, + product_uuid: Uuid, +) -> Result<ProductDetail, axum::response::Response> { + let url = format!("{}/products/{}", state.products_service_url(), product_uuid); + + let response = match state.http_client().get(&url).send().await { + Ok(resp) => resp, + Err(e) => { + eprintln!("Failed to call products service: {}", e); + return Err(( + StatusCode::SERVICE_UNAVAILABLE, + Json(serde_json::json!({ + "error": "Products service unavailable", + "details": e.to_string() + })), + ) + .into_response()); + } + }; + + match response.status() { + reqwest::StatusCode::OK => { + let product: ProductDetail = match response.json().await { + Ok(p) => p, + Err(e) => { + eprintln!("Failed to parse product response: {}", e); + return Err(( + StatusCode::INTERNAL_SERVER_ERROR, + Json(serde_json::json!({ + "error": "Failed to parse product data", + "details": e.to_string() + })), + ) + .into_response()); + } + }; + + // Verify product is active + if !product.is_active { + return Err(( + StatusCode::BAD_REQUEST, + Json(serde_json::json!({ + "error": "Product is not available", + "product_uuid": product_uuid.to_string(), + "product_name": product.product_name + })), + ) + .into_response()); + } + + Ok(product) + } + reqwest::StatusCode::NOT_FOUND => Err(( + StatusCode::BAD_REQUEST, + Json(serde_json::json!({ + "error": "Product not found", + "product_uuid": product_uuid.to_string() + })), + ) + .into_response()), + status => { + eprintln!("Products service returned status: {}", status); + Err(( + StatusCode::INTERNAL_SERVER_ERROR, + Json(serde_json::json!({ + "error": "Failed to validate product", + "status": status.as_u16() + })), + ) + .into_response()) + } + } +} + +/// Create a new order +/// +/// # Endpoint +/// `POST /orders` +/// +/// Creates a new order with items, shipping address, and payment info. +/// Automatically generates order number and calculates totals. +#[instrument( + name = "create_order", + skip(state, request), + fields( + customer_email = %request.customer_email, + item_count = request.items.len() + ) +)] +pub async fn create_order( + State(state): State<AppState>, + Json(request): Json<CreateOrderRequest>, +) -> impl IntoResponse { + // Validate all products exist, are available, and have correct prices + for item in &request.items { + let product = match validate_product(&state, item.product_uuid).await { + Ok(product) => product, + Err(response) => { + // Product validation failed - return error immediately + return response; + } + }; + + // Validate price matches actual product price (prevent price manipulation) + if item.unit_price != product.final_price { + return ( + StatusCode::BAD_REQUEST, + Json(serde_json::json!({ + "error": "Price mismatch", + "product_uuid": item.product_uuid.to_string(), + "product_name": product.product_name, + "submitted_price": item.unit_price.to_string(), + "actual_price": product.final_price.to_string(), + "message": "The submitted price does not match the current product price" + })), + ) + .into_response(); + } + } + + // Reserve stock for all items + // Track reserved items so we can release them if something fails + let mut reserved_items: Vec<(Uuid, i32)> = Vec::new(); + + for item in &request.items { + match reserve_stock(&state, item.product_uuid, item.quantity).await { + Ok(_) => { + reserved_items.push((item.product_uuid, item.quantity)); + } + Err(response) => { + // Stock reservation failed - release any already reserved stock + release_all_reserved_stock(&state, &reserved_items).await; + return response; + } + } + } + + // Start a transaction + let mut tx = match state.pool().begin().await { + Ok(tx) => tx, + Err(e) => { + eprintln!("Failed to start transaction: {}", e); + // Release reserved stock before returning error + release_all_reserved_stock(&state, &reserved_items).await; + return ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(serde_json::json!({ + "error": "Failed to start transaction", + "details": e.to_string() + })), + ) + .into_response(); + } + }; + + // Calculate subtotal from items + let subtotal: BigDecimal = request + .items + .iter() + .map(|item| &item.unit_price * BigDecimal::from(item.quantity)) + .sum(); + + // Simple tax calculation (8% for demo) + let tax_amount = &subtotal * BigDecimal::from(8) / BigDecimal::from(100); + + // Flat shipping rate for demo + let shipping_amount = BigDecimal::from(10); + + let total = &subtotal + &tax_amount + &shipping_amount; + + // Generate order number + let order_number: String = match sqlx::query_scalar("SELECT generate_order_number()") + .fetch_one(&mut *tx) + .await + { + Ok(num) => num, + Err(e) => { + eprintln!("Failed to generate order number: {}", e); + // Release reserved stock before returning error + release_all_reserved_stock(&state, &reserved_items).await; + return ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(serde_json::json!({ + "error": "Failed to generate order number", + "details": e.to_string() + })), + ) + .into_response(); + } + }; + + // Insert order + let order_result = sqlx::query( + r#" + INSERT INTO orders ( + order_number, customer_email, customer_phone, + subtotal, tax_amount, shipping_amount, total, + status, payment_status + ) + VALUES ($1, $2, $3, $4, $5, $6, $7, 'pending', 'pending') + RETURNING id, uuid + "#, + ) + .bind(&order_number) + .bind(&request.customer_email) + .bind(&request.customer_phone) + .bind(&subtotal) + .bind(&tax_amount) + .bind(&shipping_amount) + .bind(&total) + .fetch_one(&mut *tx) + .await; + + let (order_id, order_uuid): (i32, Uuid) = match order_result { + Ok(row) => (row.get("id"), row.get("uuid")), + Err(e) => { + eprintln!("Failed to create order: {}", e); + let _ = tx.rollback().await; + // Release reserved stock before returning error + release_all_reserved_stock(&state, &reserved_items).await; + return ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(serde_json::json!({ + "error": "Failed to create order", + "details": e.to_string() + })), + ) + .into_response(); + } + }; + + // Insert order items + for item in &request.items { + let total_price = &item.unit_price * BigDecimal::from(item.quantity); + if let Err(e) = sqlx::query( + r#" + INSERT INTO order_items ( + order_id, product_uuid, product_name, product_sku, + quantity, unit_price, total_price + ) + VALUES ($1, $2, $3, $4, $5, $6, $7) + "#, + ) + .bind(order_id) + .bind(item.product_uuid) + .bind(&item.product_name) + .bind(&item.product_sku) + .bind(item.quantity) + .bind(&item.unit_price) + .bind(&total_price) + .execute(&mut *tx) + .await + { + eprintln!("Failed to insert order item: {}", e); + let _ = tx.rollback().await; + // Release reserved stock before returning error + release_all_reserved_stock(&state, &reserved_items).await; + return ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(serde_json::json!({ + "error": "Failed to insert order item", + "details": e.to_string() + })), + ) + .into_response(); + } + } + + // Insert shipping address + if let Err(e) = sqlx::query( + r#" + INSERT INTO shipping_addresses ( + order_id, first_name, last_name, address_line1, address_line2, + city, state, postal_code, country, phone + ) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) + "#, + ) + .bind(order_id) + .bind(&request.shipping_address.first_name) + .bind(&request.shipping_address.last_name) + .bind(&request.shipping_address.address_line1) + .bind(&request.shipping_address.address_line2) + .bind(&request.shipping_address.city) + .bind(&request.shipping_address.state) + .bind(&request.shipping_address.postal_code) + .bind(&request.shipping_address.country) + .bind(&request.shipping_address.phone) + .execute(&mut *tx) + .await + { + eprintln!("Failed to insert shipping address: {}", e); + let _ = tx.rollback().await; + // Release reserved stock before returning error + release_all_reserved_stock(&state, &reserved_items).await; + return ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(serde_json::json!({ + "error": "Failed to insert shipping address", + "details": e.to_string() + })), + ) + .into_response(); + } + + // Generate payment reference + let payment_reference: String = match sqlx::query_scalar("SELECT generate_payment_reference()") + .fetch_one(&mut *tx) + .await + { + Ok(ref_id) => ref_id, + Err(e) => { + eprintln!("Failed to generate payment reference: {}", e); + let _ = tx.rollback().await; + // Release reserved stock before returning error + release_all_reserved_stock(&state, &reserved_items).await; + return ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(serde_json::json!({ + "error": "Failed to generate payment reference", + "details": e.to_string() + })), + ) + .into_response(); + } + }; + + // Insert payment + // NOTE: Payment is simulated - in production, this would call a payment gateway + // If payment fails, we need to release reserved stock + if let Err(e) = sqlx::query( + r#" + INSERT INTO payments ( + order_id, payment_method, amount, status, + payment_reference, card_last4, card_brand, processed_at + ) + VALUES ($1, $2, $3, 'paid', $4, $5, $6, CURRENT_TIMESTAMP) + "#, + ) + .bind(order_id) + .bind(&request.payment.payment_method) + .bind(&total) + .bind(&payment_reference) + .bind(&request.payment.card_last4) + .bind(&request.payment.card_brand) + .execute(&mut *tx) + .await + { + eprintln!("Failed to insert payment: {}", e); + let _ = tx.rollback().await; + // Payment failed - release reserved stock + release_all_reserved_stock(&state, &reserved_items).await; + return ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(serde_json::json!({ + "error": "Failed to process payment", + "details": e.to_string() + })), + ) + .into_response(); + } + + // Update order payment status + if let Err(e) = sqlx::query( + r#" + UPDATE orders + SET payment_status = 'paid', status = 'processing' + WHERE id = $1 + "#, + ) + .bind(order_id) + .execute(&mut *tx) + .await + { + eprintln!("Failed to update order status: {}", e); + let _ = tx.rollback().await; + // Release reserved stock before returning error + release_all_reserved_stock(&state, &reserved_items).await; + return ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(serde_json::json!({ + "error": "Failed to update order status", + "details": e.to_string() + })), + ) + .into_response(); + } + + // Commit transaction + if let Err(e) = tx.commit().await { + eprintln!("Failed to commit transaction: {}", e); + // Transaction commit failed - release reserved stock + release_all_reserved_stock(&state, &reserved_items).await; + return ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(serde_json::json!({ + "error": "Failed to commit transaction", + "details": e.to_string() + })), + ) + .into_response(); + } + + // Transaction committed successfully! + // Now confirm the sale with inventory service to convert reserved stock to sold + confirm_all_sales(&state, order_uuid, &reserved_items).await; + + ( + StatusCode::CREATED, + Json(serde_json::json!({ + "success": true, + "order_number": order_number, + "order_uuid": order_uuid, + "message": "Order created successfully" + })), + ) + .into_response() +} + +/// List orders with pagination and filtering +/// +/// # Endpoint +/// `GET /orders` +/// +/// Supports two modes: +/// 1. Authenticated user: Requires X-User-Email header, returns all orders for that user +/// 2. Guest user: Requires both email and order_number query params, returns single order +#[instrument( + name = "list_orders", + skip(state, headers), + fields( + page = params.page, + page_size = params.page_size + ) +)] +pub async fn list_orders( + State(state): State<AppState>, + headers: axum::http::HeaderMap, + Query(params): Query<OrderQueryParams>, +) -> impl IntoResponse { + // Check for authenticated user via X-User-Email header + let user_email = headers + .get("X-User-Email") + .and_then(|h| h.to_str().ok()) + .map(String::from); + + if let Some(email) = user_email { + // Authenticated user: return all their orders + return list_user_orders(state.pool(), &email, ¶ms).await; + } + + // Guest user: require both email and order_number + match (¶ms.customer_email, ¶ms.order_number) { + (Some(email), Some(order_number)) => { + get_guest_order(state.pool(), email, order_number).await + } + _ => ( + StatusCode::BAD_REQUEST, + Json(serde_json::json!({ + "error": "Guest users must provide both 'customer_email' and 'order_number' query parameters" + })), + ) + .into_response(), + } +} + +/// List all orders for an authenticated user +async fn list_user_orders( + pool: &PgPool, + user_email: &str, + params: &OrderQueryParams, +) -> axum::response::Response { + let page = params.page.unwrap_or(1).max(1); + let page_size = params.page_size.unwrap_or(20).clamp(1, 100); + let offset = (page - 1) * page_size; + + let mut query = String::from("SELECT * FROM v_orders_complete WHERE customer_email = $1"); + let mut count_query = + String::from("SELECT COUNT(*) FROM v_orders_complete WHERE customer_email = $1"); + + // Apply additional filters if provided + if let Some(ref status) = params.status { + let filter = format!(" AND status = '{}'", status.replace('\'', "''")); + query.push_str(&filter); + count_query.push_str(&filter); + } + + if let Some(ref payment_status) = params.payment_status { + let filter = format!( + " AND payment_status = '{}'", + payment_status.replace('\'', "''") + ); + query.push_str(&filter); + count_query.push_str(&filter); + } + + query.push_str(&format!( + " ORDER BY ordered_at DESC LIMIT {} OFFSET {}", + page_size, offset + )); + + // Execute count query + let total_count: (i64,) = match sqlx::query_as(&count_query) + .bind(user_email) + .fetch_one(pool) + .await + { + Ok(count) => count, + Err(e) => { + eprintln!("Database error counting orders: {}", e); + return ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(serde_json::json!({ + "error": "Failed to count orders", + "details": e.to_string() + })), + ) + .into_response(); + } + }; + + // Execute main query + let orders: Vec<OrderComplete> = match sqlx::query_as(&query) + .bind(user_email) + .fetch_all(pool) + .await + { + Ok(orders) => orders, + Err(e) => { + eprintln!("Database error fetching orders: {}", e); + return ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(serde_json::json!({ + "error": "Failed to fetch orders", + "details": e.to_string() + })), + ) + .into_response(); + } + }; + + let total_pages = ((total_count.0 as f64) / (page_size as f64)).ceil() as i32; + + let response = OrdersResponse { + orders, + total_count: total_count.0, + page, + page_size, + total_pages, + }; + + (StatusCode::OK, Json(response)).into_response() +} + +/// Get a single order for a guest user +async fn get_guest_order( + pool: &PgPool, + email: &str, + order_number: &str, +) -> axum::response::Response { + let result = sqlx::query_as::<_, OrderComplete>( + r#" + SELECT * FROM v_orders_complete + WHERE customer_email = $1 AND order_number = $2 + "#, + ) + .bind(email) + .bind(order_number) + .fetch_optional(pool) + .await; + + match result { + Ok(Some(order)) => { + // Return as single-item list for consistency + let response = OrdersResponse { + orders: vec![order], + total_count: 1, + page: 1, + page_size: 1, + total_pages: 1, + }; + (StatusCode::OK, Json(response)).into_response() + } + Ok(None) => ( + StatusCode::NOT_FOUND, + Json(serde_json::json!({ + "error": "Order not found or email does not match" + })), + ) + .into_response(), + Err(e) => { + eprintln!("Database error fetching order: {}", e); + ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(serde_json::json!({ + "error": "Failed to fetch order", + "details": e.to_string() + })), + ) + .into_response() + } + } +} + +/// Get order details by UUID +/// +/// # Endpoint +/// `GET /orders/{uuid}` +pub async fn get_order_by_id( + State(state): State<AppState>, + Path(uuid): Path<Uuid>, +) -> impl IntoResponse { + let result = sqlx::query_as::<_, OrderComplete>( + r#" + SELECT * FROM v_orders_complete WHERE eid = $1 + "#, + ) + .bind(uuid) + .fetch_optional(state.pool()) + .await; + + match result { + Ok(Some(order)) => (StatusCode::OK, Json(order)).into_response(), + Ok(None) => ( + StatusCode::NOT_FOUND, + Json(serde_json::json!({ + "error": "Order not found", + "uuid": uuid.to_string() + })), + ) + .into_response(), + Err(e) => { + eprintln!("Database error fetching order: {}", e); + ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(serde_json::json!({ + "error": "Failed to fetch order", + "details": e.to_string() + })), + ) + .into_response() + } + } +} diff --git a/distributed_observability/orders/src/handlers/shipments.rs b/distributed_observability/orders/src/handlers/shipments.rs @@ -0,0 +1,246 @@ +//! Shipment tracking API handlers + +use axum::{ + extract::{Path, State}, + http::StatusCode, + response::{IntoResponse, Json}, +}; +use tracing::instrument; +use uuid::Uuid; + +use crate::models::{CreateShipmentRequest, Shipment, UpdateShipmentStatusRequest}; +use crate::AppState; + +/// Create a shipment for an order +/// +/// # Endpoint +/// `POST /orders/{order_uuid}/shipment` +#[instrument(name = "create_shipment", skip(state, request), fields(order.uuid = %order_uuid))] +pub async fn create_shipment( + State(state): State<AppState>, + Path(order_uuid): Path<Uuid>, + Json(request): Json<CreateShipmentRequest>, +) -> impl IntoResponse { + // Get order_id from UUID + let order_id: Option<i32> = match sqlx::query_scalar("SELECT id FROM orders WHERE uuid = $1") + .bind(order_uuid) + .fetch_optional(state.pool()) + .await + { + Ok(id) => id, + Err(e) => { + eprintln!("Database error fetching order: {}", e); + return ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(serde_json::json!({ + "error": "Failed to fetch order", + "details": e.to_string() + })), + ) + .into_response(); + } + }; + + let order_id = match order_id { + Some(id) => id, + None => { + return ( + StatusCode::NOT_FOUND, + Json(serde_json::json!({ + "error": "Order not found", + "order_uuid": order_uuid.to_string() + })), + ) + .into_response(); + } + }; + + // Create shipment + let result = sqlx::query_as::<_, Shipment>( + r#" + INSERT INTO shipments ( + order_id, carrier, tracking_number, + estimated_delivery_date, status, shipped_at + ) + VALUES ($1, $2, $3, $4, 'shipped', CURRENT_TIMESTAMP) + RETURNING * + "#, + ) + .bind(order_id) + .bind(&request.carrier) + .bind(&request.tracking_number) + .bind(request.estimated_delivery_date) + .fetch_one(state.pool()) + .await; + + match result { + Ok(shipment) => { + // Update order status to shipped + let _ = sqlx::query("UPDATE orders SET status = 'shipped' WHERE id = $1") + .bind(order_id) + .execute(state.pool()) + .await; + + (StatusCode::CREATED, Json(shipment)).into_response() + } + Err(e) => { + eprintln!("Database error creating shipment: {}", e); + ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(serde_json::json!({ + "error": "Failed to create shipment", + "details": e.to_string() + })), + ) + .into_response() + } + } +} + +/// Update shipment status +/// +/// # Endpoint +/// `PUT /orders/{order_uuid}/shipment/status` +#[instrument(name = "update_shipment_status", skip(state, request), fields(order.uuid = %order_uuid))] +pub async fn update_shipment_status( + State(state): State<AppState>, + Path(order_uuid): Path<Uuid>, + Json(request): Json<UpdateShipmentStatusRequest>, +) -> impl IntoResponse { + // Start transaction + let mut tx = match state.pool().begin().await { + Ok(tx) => tx, + Err(e) => { + eprintln!("Failed to start transaction: {}", e); + return ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(serde_json::json!({ + "error": "Failed to start transaction", + "details": e.to_string() + })), + ) + .into_response(); + } + }; + + // Get order_id + let order_id: Option<i32> = match sqlx::query_scalar("SELECT id FROM orders WHERE uuid = $1") + .bind(order_uuid) + .fetch_optional(&mut *tx) + .await + { + Ok(id) => id, + Err(e) => { + eprintln!("Database error fetching order: {}", e); + let _ = tx.rollback().await; + return ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(serde_json::json!({ + "error": "Failed to fetch order", + "details": e.to_string() + })), + ) + .into_response(); + } + }; + + let order_id = match order_id { + Some(id) => id, + None => { + let _ = tx.rollback().await; + return ( + StatusCode::NOT_FOUND, + Json(serde_json::json!({ + "error": "Order not found", + "order_uuid": order_uuid.to_string() + })), + ) + .into_response(); + } + }; + + // Update shipment + let query = if request.status == "delivered" { + sqlx::query( + r#" + UPDATE shipments + SET status = $1, actual_delivery_date = $2, delivered_at = CURRENT_TIMESTAMP + WHERE order_id = $3 + RETURNING id + "#, + ) + .bind(&request.status) + .bind(request.actual_delivery_date) + .bind(order_id) + } else { + sqlx::query( + r#" + UPDATE shipments + SET status = $1 + WHERE order_id = $2 + RETURNING id + "#, + ) + .bind(&request.status) + .bind(order_id) + }; + + let result = query.fetch_optional(&mut *tx).await; + + match result { + Ok(Some(_)) => { + // Update order status if delivered + if request.status == "delivered" { + let _ = sqlx::query("UPDATE orders SET status = 'delivered' WHERE id = $1") + .bind(order_id) + .execute(&mut *tx) + .await; + } + + if let Err(e) = tx.commit().await { + eprintln!("Failed to commit transaction: {}", e); + return ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(serde_json::json!({ + "error": "Failed to commit transaction", + "details": e.to_string() + })), + ) + .into_response(); + } + + ( + StatusCode::OK, + Json(serde_json::json!({ + "success": true, + "message": "Shipment status updated", + "status": request.status + })), + ) + .into_response() + } + Ok(None) => { + let _ = tx.rollback().await; + ( + StatusCode::NOT_FOUND, + Json(serde_json::json!({ + "error": "Shipment not found for order", + "order_uuid": order_uuid.to_string() + })), + ) + .into_response() + } + Err(e) => { + eprintln!("Database error updating shipment: {}", e); + let _ = tx.rollback().await; + ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(serde_json::json!({ + "error": "Failed to update shipment", + "details": e.to_string() + })), + ) + .into_response() + } + } +} diff --git a/distributed_observability/orders/src/main.rs b/distributed_observability/orders/src/main.rs @@ -0,0 +1,175 @@ +//! Orders Service +//! +//! A microservice for managing customer orders, payments, and shipping. +//! +//! # Features +//! - Order creation with guest checkout +//! - Order management and status tracking +//! - Payment processing (simulated) +//! - Shipping address management +//! - Shipment tracking +//! - PostgreSQL database with orders schema +//! - CORS enabled for web client access +//! +//! # API Endpoints +//! ## Orders +//! - `POST /orders` - Create a new order (payment must succeed or order fails) +//! - `GET /orders` - List orders with filters and pagination +//! - `GET /orders/{uuid}` - Get complete order details (includes payment & shipment) +//! +//! ## Shipments (Internal - used by scheduler) +//! - `POST /orders/{uuid}/shipment` - Create shipment (sets order status to 'shipped') +//! - `PUT /orders/{uuid}/shipment/status` - Update shipment status (sets order status to 'delivered' when complete) +//! +//! # Configuration +//! The service is configured via: +//! - Environment variables (loaded from .env if present) +//! - config.toml file +//! +//! # Database +//! Uses the `orders` schema in PostgreSQL with automatic search path configuration. +//! Migrations are run automatically on startup. + +mod config; +mod db; +mod handlers; +mod models; +mod telemetry; + +use anyhow::Result; +use axum::{ + routing::{get, post, put}, + Router, +}; +use axum_tracing_opentelemetry::middleware::{OtelAxumLayer, OtelInResponseLayer}; +use std::net::SocketAddr; +use tower_http::cors::CorsLayer; +use tracing::info; + +use config::Config; +use db::Database; + +/// Application state shared across handlers +#[derive(Clone)] +pub struct AppState { + db_pool: sqlx::PgPool, + http_client: reqwest_middleware::ClientWithMiddleware, + products_service_url: String, + inventory_service_url: String, +} + +impl AppState { + /// Get the database pool + pub fn pool(&self) -> &sqlx::PgPool { + &self.db_pool + } + + /// Get the HTTP client + pub fn http_client(&self) -> &reqwest_middleware::ClientWithMiddleware { + &self.http_client + } + + /// Get the products service URL + pub fn products_service_url(&self) -> &str { + &self.products_service_url + } + + /// Get the inventory service URL + pub fn inventory_service_url(&self) -> &str { + &self.inventory_service_url + } +} + +#[tokio::main] +async fn main() -> Result<()> { + // Load environment variables from .env file if present + dotenvy::dotenv().ok(); + + // Initialize telemetry (tracing + OpenTelemetry) + let tracer_provider = telemetry::init_telemetry("orders"); + + // Load configuration from config.toml + let config = Config::load()?; + + // Log startup information using tracing macros + info!( + port = config.server.port, + database_url = %config.database.url, + products_service = format!("{}:{}", config.services.products_host, config.services.products_port), + inventory_service = format!("{}:{}", config.services.inventory_host, config.services.inventory_port), + "Starting Orders Service" + ); + + // Initialize database connection pool + let db = Database::new(&config.database.url, config.database.max_connections).await?; + + // Create HTTP client with tracing middleware for automatic + // span creation and trace context propagation + let reqwest_client = reqwest::Client::builder() + .timeout(std::time::Duration::from_secs( + config.http_client.timeout_secs, + )) + .build()?; + let http_client = reqwest_middleware::ClientBuilder::new(reqwest_client) + .with(reqwest_tracing::TracingMiddleware::< + reqwest_tracing::SpanBackendWithUrl, + >::new()) + .build(); + + // Create application state + let state = AppState { + db_pool: db.pool().clone(), + http_client, + products_service_url: config.services.products_service_url(), + inventory_service_url: config.services.inventory_service_url(), + }; + + // Build the application router with all endpoints + let app = Router::new() + // Order endpoints + .route("/orders", post(handlers::create_order)) + .route("/orders", get(handlers::list_orders)) + .route("/orders/{uuid}", get(handlers::get_order_by_id)) + // Shipment endpoints (internal - used by scheduler) + .route( + "/orders/{order_uuid}/shipment", + post(handlers::create_shipment), + ) + .route( + "/orders/{order_uuid}/shipment/status", + put(handlers::update_shipment_status), + ) + // Include trace context as header into the response + .layer(OtelInResponseLayer::default()) + // Start OpenTelemetry trace on incoming request + .layer(OtelAxumLayer::default()) + // Enable CORS for all routes + .layer(CorsLayer::permissive()) + // Add application state + .with_state(state); + + // Create socket address from configuration + let addr = SocketAddr::from(([0, 0, 0, 0], config.server.port)); + + // Log API documentation + info!(address = %addr, "Orders Service listening"); + info!("Available endpoints:"); + info!(" Orders:"); + info!(" POST /orders - Create new order (payment must succeed)"); + info!(" GET /orders - List orders (with pagination & filters)"); + info!(" GET /orders/{{uuid}} - Get complete order (includes payment & shipment)"); + info!(" Shipments (Internal - used by scheduler):"); + info!( + " POST /orders/{{uuid}}/shipment - Create shipment (sets status='shipped')" + ); + info!(" PUT /orders/{{uuid}}/shipment/status - Update shipment (sets status='delivered' when complete)"); + // + // Start the HTTP server + let listener = tokio::net::TcpListener::bind(addr).await?; + axum::serve(listener, app).await?; + + // Shutdown telemetry on exit (flush pending spans) + telemetry::shutdown_telemetry(tracer_provider); + + Ok(()) +} diff --git a/distributed_observability_in_rust/example_project/orders/src/models/mod.rs b/distributed_observability/orders/src/models/mod.rs diff --git a/distributed_observability_in_rust/example_project/orders/src/models/order.rs b/distributed_observability/orders/src/models/order.rs diff --git a/distributed_observability_in_rust/example_project/orders/src/models/shipment.rs b/distributed_observability/orders/src/models/shipment.rs diff --git a/distributed_observability/orders/src/telemetry.rs b/distributed_observability/orders/src/telemetry.rs @@ -0,0 +1,92 @@ +//! Telemetry initialization for the Inventory service. +//! +//! This module configures OpenTelemetry tracing with OTLP export to Jaeger. +//! It sets up a layered tracing subscriber that outputs both to stdout and +//! sends spans to the configured OTLP endpoint. + +use opentelemetry::global; +use opentelemetry::trace::TracerProvider as _; +use opentelemetry_otlp::WithExportConfig; +use opentelemetry_sdk::{propagation::TraceContextPropagator, trace::SdkTracerProvider, Resource}; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter}; + +/// Initializes the telemetry pipeline for the service. +/// +/// This function sets up: +/// - An OTLP exporter that sends traces to Jaeger (via OTEL_EXPORTER_OTLP_ENDPOINT) +/// - A tracing subscriber with environment-based filtering (RUST_LOG) +/// - Console output for local debugging +/// +/// # Arguments +/// * `service_name` - The name of this service, used to identify traces in Jaeger +/// +/// # Returns +/// * `SdkTracerProvider` - The tracer provider, which should be kept alive and +/// shut down gracefully when the application exits +/// +/// # Panics +/// Panics if the OTLP exporter or tracing subscriber cannot be initialized. +pub fn init_telemetry(service_name: &str) -> SdkTracerProvider { + // Set up W3C Trace Context propagator for cross-service trace correlation + global::set_text_map_propagator(TraceContextPropagator::new()); + + // Get the OTLP endpoint from environment, defaulting to localhost for local dev + let otlp_endpoint = std::env::var("OTEL_EXPORTER_OTLP_ENDPOINT") + .unwrap_or_else(|_| "http://localhost:4317".to_string()); + + // Create the OTLP exporter configured to send traces via gRPC + let exporter = opentelemetry_otlp::SpanExporter::builder() + .with_tonic() + .with_endpoint(&otlp_endpoint) + .build() + .expect("Failed to create OTLP exporter"); + + // Build the tracer provider with the exporter and service resource + let provider = SdkTracerProvider::builder() + .with_batch_exporter(exporter) + .with_resource( + Resource::builder_empty() + .with_service_name(service_name.to_string()) + .build(), + ) + .build(); + + // Create a tracer from the provider for the OpenTelemetry layer + let tracer = provider.tracer(service_name.to_string()); + + // Create the OpenTelemetry tracing layer + let otel_layer = tracing_opentelemetry::layer().with_tracer(tracer); + + // Create an environment filter for log levels (defaults to "info") + // Include otel::tracing=trace to allow axum-tracing-opentelemetry spans through + let env_filter = EnvFilter::try_from_default_env() + .unwrap_or_else(|_| EnvFilter::new("info,otel::tracing=trace")); + + // Create a formatting layer for console output + let fmt_layer = tracing_subscriber::fmt::layer() + .with_target(true) + .with_thread_ids(false) + .compact(); + + // Combine all layers into a subscriber and set it as the global default + tracing_subscriber::registry() + .with(env_filter) + .with(fmt_layer) + .with(otel_layer) + .init(); + + provider +} + +/// Shuts down the telemetry pipeline gracefully. +/// +/// This ensures all pending spans are flushed to the OTLP endpoint +/// before the application exits. +/// +/// # Arguments +/// * `provider` - The tracer provider returned from `init_telemetry` +pub fn shutdown_telemetry(provider: SdkTracerProvider) { + if let Err(e) = provider.shutdown() { + eprintln!("Failed to shutdown tracer provider: {e}"); + } +} diff --git a/distributed_observability/otel-collector-config.yaml b/distributed_observability/otel-collector-config.yaml @@ -0,0 +1,27 @@ +receivers: + otlp: + protocols: + grpc: + endpoint: 0.0.0.0:4317 # accept traces from services + http: + endpoint: 0.0.0.0:4318 + +processors: + batch: + timeout: 5s + send_batch_size: 512 + +exporters: + otlp_grpc/jaeger: + endpoint: jaeger:4317 # Forward to Jaeger + tls: + insecure: true # No TLS in dev, use TLS in prod + debug: + verbosity: detailed + +service: + pipelines: + traces: + receivers: [otlp] + processors: [batch] + exporters: [otlp_grpc/jaeger, debug] diff --git a/distributed_observability/otelmart/Cargo.toml b/distributed_observability/otelmart/Cargo.toml @@ -0,0 +1,73 @@ +[package] +name = "otelmart" +version.workspace = true +edition.workspace = true +authors.workspace = true + +[lints] +workspace = true + +[dependencies] +# Async runtime +tokio = { workspace = true } + +# Web framework +axum = { workspace = true, features = ["macros"] } +tower = { workspace = true } +tower-http = { workspace = true, features = ["fs", "cors"] } + +# Database +sqlx = { workspace = true, features = [ + "runtime-tokio-rustls", + "postgres", + "uuid", + "chrono", + "migrate", +] } + +# Serialization +serde = { workspace = true } +serde_json = { workspace = true } + +# HTTP Client (for proxying) +reqwest = { workspace = true } + +# Security +bcrypt = { workspace = true } +jsonwebtoken = { workspace = true } + +# Utilities +uuid = { workspace = true } +chrono = { workspace = true } +anyhow = { workspace = true } +thiserror = { workspace = true } + +# Configuration +config = { workspace = true } +dotenvy = { workspace = true } + +# URL encoding +urlencoding = { workspace = true } + +# Telemetry / Observability +# +# Core tracing ecosystem +tracing = { workspace = true } +tracing-subscriber = { workspace = true } + +# OpenTelemetry core +opentelemetry = { workspace = true } +opentelemetry_sdk = { workspace = true } + +# OTLP exporter (sends traces to collectors/backends) +opentelemetry-otlp = { workspace = true } + +# Bridge between tracing and OpenTelemetry +tracing-opentelemetry = { workspace = true } + +# HTTP instrumentation (server + client) +axum-tracing-opentelemetry = { workspace = true } +reqwest-middleware = { workspace = true } +reqwest-tracing = { workspace = true } + +[dev-dependencies] diff --git a/distributed_observability/otelmart/Dockerfile b/distributed_observability/otelmart/Dockerfile @@ -0,0 +1,91 @@ +# ============================================================ +# Multi-stage Dockerfile for OtelMart Service + Angular Client +# ============================================================ + +# Stage 1: Build Angular Client +FROM node:20-alpine AS client-builder + +WORKDIR /app/client + +# Copy client package files +COPY client/package*.json ./ + +# Install dependencies +RUN npm ci + +# Copy client source +COPY client/ ./ + +# Build Angular app for production +RUN npm run build --configuration=production && \ + ls -la dist/ || echo "No dist directory" && \ + ls -la dist/*/browser || echo "No browser directory found" + +# Stage 2: Build Rust OtelMart Service +FROM rust:1-bookworm AS rust-builder + +WORKDIR /app + +# Install build dependencies +RUN apt-get update && \ + apt-get install -y pkg-config libssl-dev && \ + rm -rf /var/lib/apt/lists/* + +# Copy workspace Cargo files +COPY Cargo.toml Cargo.lock ./ + +# Copy otelmart service +COPY otelmart/Cargo.toml ./otelmart/ +COPY otelmart/src ./otelmart/src/ +COPY otelmart/config.toml ./otelmart/ +COPY otelmart/config.docker.toml ./otelmart/ + +# Copy products (required by workspace) +COPY products/Cargo.toml ./products/ +COPY products/src ./products/src/ + +# Copy inventory (required by workspace) +COPY inventory/Cargo.toml ./inventory/ +COPY inventory/src ./inventory/src/ + +# Copy orders (required by workspace) +COPY orders/Cargo.toml ./orders/ +COPY orders/src ./orders/src/ + +# Build the service (release mode) +WORKDIR /app +RUN cargo build --release + +# Stage 3: Runtime image +FROM debian:bookworm-slim + +WORKDIR /app + +# Install runtime dependencies +RUN apt-get update && \ + apt-get install -y ca-certificates libssl3 curl && \ + rm -rf /var/lib/apt/lists/* + +# Copy built binary from rust-builder +COPY --from=rust-builder /app/target/release/otelmart /app/otelmart + +# Copy config file (use docker config) +COPY --from=rust-builder /app/otelmart/config.docker.toml /app/config.toml + +# Copy built Angular app from client-builder +COPY --from=client-builder /app/client/dist /app/dist + +# Create non-root user +RUN useradd -m -u 1000 appuser && \ + chown -R appuser:appuser /app +USER appuser + +# Expose port +EXPOSE 4200 + +# Health check +HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ + CMD ["/usr/bin/curl", "-f", "http://localhost:4200/health"] + +# Run the service +CMD ["/app/otelmart"] diff --git a/distributed_observability_in_rust/example_project/otelmart/config.docker.toml b/distributed_observability/otelmart/config.docker.toml diff --git a/distributed_observability_in_rust/example_project/otelmart/config.toml b/distributed_observability/otelmart/config.toml diff --git a/distributed_observability_in_rust/example_project/otelmart/src/auth/mod.rs b/distributed_observability/otelmart/src/auth/mod.rs diff --git a/distributed_observability_in_rust/example_project/otelmart/src/config.rs b/distributed_observability/otelmart/src/config.rs diff --git a/distributed_observability_in_rust/example_project/otelmart/src/db/mod.rs b/distributed_observability/otelmart/src/db/mod.rs diff --git a/distributed_observability/otelmart/src/handlers/auth.rs b/distributed_observability/otelmart/src/handlers/auth.rs @@ -0,0 +1,139 @@ +use axum::{ + extract::State, + http::{header, StatusCode}, + response::IntoResponse, + Json, +}; +use serde::Serialize; +use tracing::instrument; + +use crate::{ + auth, + models::{LoginRequest, LoginResponse, RegisterRequest, UserResponse}, + AppState, +}; + +#[derive(Serialize)] +pub struct ErrorResponse { + pub error: String, +} + +#[instrument(name = "register", skip(state, req), fields(user.email = %req.email))] +pub async fn register( + State(state): State<AppState>, + Json(req): Json<RegisterRequest>, +) -> impl IntoResponse { + match auth::register_user(state.db.pool(), req).await { + Ok(user) => { + let response = UserResponse::from(user); + (StatusCode::CREATED, Json(response)).into_response() + } + Err(e) => ( + StatusCode::BAD_REQUEST, + Json(ErrorResponse { + error: e.to_string(), + }), + ) + .into_response(), + } +} + +#[instrument(name = "login", skip(state, req), fields(user.email = %req.email))] +pub async fn login( + State(state): State<AppState>, + Json(req): Json<LoginRequest>, +) -> impl IntoResponse { + match auth::login_user(state.db.pool(), req).await { + Ok((user, session)) => { + let response = LoginResponse { + token: session.session_token.clone(), + user: UserResponse::from(user), + expires_at: session.expires_at, + }; + + ( + StatusCode::OK, + [( + header::SET_COOKIE, + format!( + "session_token={}; HttpOnly; SameSite=Lax; Path=/; Max-Age={}", + session.session_token, + 7 * 24 * 60 * 60 + ), + )], + Json(response), + ) + .into_response() + } + Err(e) => ( + StatusCode::UNAUTHORIZED, + Json(ErrorResponse { + error: e.to_string(), + }), + ) + .into_response(), + } +} + +#[instrument(name = "logout", skip(state, headers))] +pub async fn logout( + State(state): State<AppState>, + headers: axum::http::HeaderMap, +) -> impl IntoResponse { + // Extract session token from cookie or Authorization header + let token = extract_token(&headers); + + if let Some(token) = token { + match auth::logout_user(state.db.pool(), &token).await { + Ok(_) => ( + StatusCode::OK, + [( + header::SET_COOKIE, + "session_token=; HttpOnly; SameSite=Lax; Path=/; Max-Age=0", + )], + Json(serde_json::json!({ "message": "Logged out successfully" })), + ) + .into_response(), + Err(e) => ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(ErrorResponse { + error: e.to_string(), + }), + ) + .into_response(), + } + } else { + ( + StatusCode::UNAUTHORIZED, + Json(ErrorResponse { + error: "No session token provided".to_string(), + }), + ) + .into_response() + } +} + +fn extract_token(headers: &axum::http::HeaderMap) -> Option<String> { + // Try to get from Authorization header + if let Some(auth_header) = headers.get(header::AUTHORIZATION) { + if let Ok(auth_str) = auth_header.to_str() { + if auth_str.starts_with("Bearer ") { + return Some(auth_str[7..].to_string()); + } + } + } + + // Try to get from Cookie header + if let Some(cookie_header) = headers.get(header::COOKIE) { + if let Ok(cookie_str) = cookie_header.to_str() { + for cookie in cookie_str.split(';') { + let cookie = cookie.trim(); + if cookie.starts_with("session_token=") { + return Some(cookie[14..].to_string()); + } + } + } + } + + None +} diff --git a/distributed_observability_in_rust/example_project/otelmart/src/handlers/health.rs b/distributed_observability/otelmart/src/handlers/health.rs diff --git a/distributed_observability_in_rust/example_project/otelmart/src/handlers/mod.rs b/distributed_observability/otelmart/src/handlers/mod.rs diff --git a/distributed_observability/otelmart/src/handlers/users.rs b/distributed_observability/otelmart/src/handlers/users.rs @@ -0,0 +1,656 @@ +use axum::{ + extract::{Path, State}, + http::StatusCode, + response::IntoResponse, + Json, +}; +use tracing::instrument; +use uuid::Uuid; + +use crate::{ + auth, + models::{AddAddressRequest, AddressResponse, UpdateProfileRequest, UserAddress}, + AppState, +}; + +use super::auth::ErrorResponse; + +#[instrument(name = "get_profile", skip(state, headers))] +pub async fn get_profile( + State(state): State<AppState>, + headers: axum::http::HeaderMap, +) -> impl IntoResponse { + let token = extract_token(&headers); + + if let Some(token) = token { + match auth::validate_session(state.db.pool(), &token).await { + Ok(Some(user)) => { + // Get user profile (if exists) + let profile = sqlx::query_as::< + _, + ( + uuid::Uuid, + Option<String>, + Option<chrono::NaiveDate>, + bool, + bool, + ), + >( + r#" + SELECT + uuid, + avatar_url, + date_of_birth, + email_notifications, + marketing_emails + FROM user_profiles + WHERE user_id = $1 + "#, + ) + .bind(user.id) + .fetch_optional(state.db.pool()) + .await; + + match profile { + Ok(Some(( + eid, + avatar_url, + date_of_birth, + email_notifications, + marketing_emails, + ))) => ( + StatusCode::OK, + Json(serde_json::json!({ + "user_id": user.uuid, + "email": user.email, + "first_name": user.first_name, + "last_name": user.last_name, + "phone": user.phone, + "is_verified": user.is_verified, + "profile_eid": eid, + "avatar_url": avatar_url, + "date_of_birth": date_of_birth, + "email_notifications": email_notifications, + "marketing_emails": marketing_emails, + })), + ) + .into_response(), + Ok(None) => { + // Return user data even if profile doesn't exist yet + ( + StatusCode::OK, + Json(serde_json::json!({ + "user_id": user.uuid, + "email": user.email, + "first_name": user.first_name, + "last_name": user.last_name, + "phone": user.phone, + "is_verified": user.is_verified, + "profile_eid": null, + "avatar_url": null, + "date_of_birth": null, + "email_notifications": true, + "marketing_emails": false, + })), + ) + .into_response() + } + Err(e) => ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(ErrorResponse { + error: e.to_string(), + }), + ) + .into_response(), + } + } + Ok(None) => ( + StatusCode::UNAUTHORIZED, + Json(ErrorResponse { + error: "Invalid or expired session".to_string(), + }), + ) + .into_response(), + Err(e) => ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(ErrorResponse { + error: e.to_string(), + }), + ) + .into_response(), + } + } else { + ( + StatusCode::UNAUTHORIZED, + Json(ErrorResponse { + error: "No session token provided".to_string(), + }), + ) + .into_response() + } +} + +#[instrument(name = "update_profile", skip(state, headers, req))] +pub async fn update_profile( + State(state): State<AppState>, + headers: axum::http::HeaderMap, + Json(req): Json<UpdateProfileRequest>, +) -> impl IntoResponse { + let token = extract_token(&headers); + + if let Some(token) = token { + match auth::validate_session(state.db.pool(), &token).await { + Ok(Some(user)) => { + // Check if profile exists + let profile_exists = + sqlx::query_as::<_, (i32,)>("SELECT id FROM user_profiles WHERE user_id = $1") + .bind(user.id) + .fetch_optional(state.db.pool()) + .await; + + match profile_exists { + Ok(Some(_)) => { + // Update existing profile + let result = sqlx::query_as::< + _, + ( + uuid::Uuid, + Option<String>, + Option<chrono::NaiveDate>, + bool, + bool, + ), + >( + r#" + UPDATE user_profiles + SET avatar_url = COALESCE($1, avatar_url), + date_of_birth = COALESCE($2, date_of_birth), + email_notifications = COALESCE($3, email_notifications), + marketing_emails = COALESCE($4, marketing_emails), + updated_at = NOW() + WHERE user_id = $5 + RETURNING + uuid, + avatar_url, + date_of_birth, + email_notifications, + marketing_emails + "#, + ) + .bind(&req.avatar_url) + .bind(&req.date_of_birth) + .bind(&req.email_notifications) + .bind(&req.marketing_emails) + .bind(user.id) + .fetch_one(state.db.pool()) + .await; + + match result { + Ok(( + eid, + avatar_url, + date_of_birth, + email_notifications, + marketing_emails, + )) => ( + StatusCode::OK, + Json(serde_json::json!({ + "eid": eid, + "avatar_url": avatar_url, + "date_of_birth": date_of_birth, + "email_notifications": email_notifications, + "marketing_emails": marketing_emails, + })), + ) + .into_response(), + Err(e) => ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(ErrorResponse { + error: e.to_string(), + }), + ) + .into_response(), + } + } + Ok(None) => { + // Create new profile + let result = sqlx::query_as::< + _, + ( + uuid::Uuid, + Option<String>, + Option<chrono::NaiveDate>, + bool, + bool, + ), + >( + r#" + INSERT INTO user_profiles ( + user_id, + avatar_url, + date_of_birth, + email_notifications, + marketing_emails + ) VALUES ($1, $2, $3, $4, $5) + RETURNING + uuid, + avatar_url, + date_of_birth, + email_notifications, + marketing_emails + "#, + ) + .bind(user.id) + .bind(&req.avatar_url) + .bind(&req.date_of_birth) + .bind(req.email_notifications.unwrap_or(true)) + .bind(req.marketing_emails.unwrap_or(false)) + .fetch_one(state.db.pool()) + .await; + + match result { + Ok(( + eid, + avatar_url, + date_of_birth, + email_notifications, + marketing_emails, + )) => ( + StatusCode::CREATED, + Json(serde_json::json!({ + "eid": eid, + "avatar_url": avatar_url, + "date_of_birth": date_of_birth, + "email_notifications": email_notifications, + "marketing_emails": marketing_emails, + })), + ) + .into_response(), + Err(e) => ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(ErrorResponse { + error: e.to_string(), + }), + ) + .into_response(), + } + } + Err(e) => ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(ErrorResponse { + error: e.to_string(), + }), + ) + .into_response(), + } + } + Ok(None) => ( + StatusCode::UNAUTHORIZED, + Json(ErrorResponse { + error: "Invalid or expired session".to_string(), + }), + ) + .into_response(), + Err(e) => ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(ErrorResponse { + error: e.to_string(), + }), + ) + .into_response(), + } + } else { + ( + StatusCode::UNAUTHORIZED, + Json(ErrorResponse { + error: "No session token provided".to_string(), + }), + ) + .into_response() + } +} + +#[instrument(name = "get_addresses", skip(state, headers))] +pub async fn get_addresses( + State(state): State<AppState>, + headers: axum::http::HeaderMap, +) -> impl IntoResponse { + let token = extract_token(&headers); + + if let Some(token) = token { + match auth::validate_session(state.db.pool(), &token).await { + Ok(Some(user)) => { + let addresses = sqlx::query_as::<_, UserAddress>( + r#" + SELECT * FROM user_addresses + WHERE user_id = $1 AND is_active = true + ORDER BY is_default DESC, created_at DESC + "#, + ) + .bind(user.id) + .fetch_all(state.db.pool()) + .await; + + match addresses { + Ok(addresses) => { + let response: Vec<AddressResponse> = + addresses.into_iter().map(AddressResponse::from).collect(); + + (StatusCode::OK, Json(response)).into_response() + } + Err(e) => ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(ErrorResponse { + error: e.to_string(), + }), + ) + .into_response(), + } + } + Ok(None) => ( + StatusCode::UNAUTHORIZED, + Json(ErrorResponse { + error: "Invalid or expired session".to_string(), + }), + ) + .into_response(), + Err(e) => ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(ErrorResponse { + error: e.to_string(), + }), + ) + .into_response(), + } + } else { + ( + StatusCode::UNAUTHORIZED, + Json(ErrorResponse { + error: "No session token provided".to_string(), + }), + ) + .into_response() + } +} + +#[instrument(name = "add_address", skip(state, headers, req))] +pub async fn add_address( + State(state): State<AppState>, + headers: axum::http::HeaderMap, + Json(req): Json<AddAddressRequest>, +) -> impl IntoResponse { + let token = extract_token(&headers); + + if let Some(token) = token { + match auth::validate_session(state.db.pool(), &token).await { + Ok(Some(user)) => { + let address = sqlx::query_as::<_, UserAddress>( + r#" + INSERT INTO user_addresses ( + user_id, address_type, address_label, + first_name, last_name, + address_line1, address_line2, + city, state, postal_code, country, + phone, is_default + ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13) + RETURNING * + "#, + ) + .bind(user.id) + .bind(&req.address_type) + .bind(&req.address_label) + .bind(&req.first_name) + .bind(&req.last_name) + .bind(&req.address_line1) + .bind(&req.address_line2) + .bind(&req.city) + .bind(&req.state) + .bind(&req.postal_code) + .bind(&req.country) + .bind(&req.phone) + .bind(req.is_default.unwrap_or(false)) + .fetch_one(state.db.pool()) + .await; + + match address { + Ok(address) => { + let response = AddressResponse::from(address); + (StatusCode::CREATED, Json(response)).into_response() + } + Err(e) => ( + StatusCode::BAD_REQUEST, + Json(ErrorResponse { + error: e.to_string(), + }), + ) + .into_response(), + } + } + Ok(None) => ( + StatusCode::UNAUTHORIZED, + Json(ErrorResponse { + error: "Invalid or expired session".to_string(), + }), + ) + .into_response(), + Err(e) => ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(ErrorResponse { + error: e.to_string(), + }), + ) + .into_response(), + } + } else { + ( + StatusCode::UNAUTHORIZED, + Json(ErrorResponse { + error: "No session token provided".to_string(), + }), + ) + .into_response() + } +} + +#[instrument(name = "update_address", skip(state, headers, req), fields(address.uuid = %id))] +pub async fn update_address( + State(state): State<AppState>, + headers: axum::http::HeaderMap, + Path(id): Path<Uuid>, + Json(req): Json<AddAddressRequest>, +) -> impl IntoResponse { + let token = extract_token(&headers); + + if let Some(token) = token { + match auth::validate_session(state.db.pool(), &token).await { + Ok(Some(user)) => { + // Update address only if it belongs to the user + let address = sqlx::query_as::<_, UserAddress>( + r#" + UPDATE user_addresses + SET address_type = $1, + address_label = $2, + first_name = $3, + last_name = $4, + address_line1 = $5, + address_line2 = $6, + city = $7, + state = $8, + postal_code = $9, + country = $10, + phone = $11, + is_default = $12, + updated_at = NOW() + WHERE uuid = $13 AND user_id = $14 AND is_active = true + RETURNING * + "#, + ) + .bind(&req.address_type) + .bind(&req.address_label) + .bind(&req.first_name) + .bind(&req.last_name) + .bind(&req.address_line1) + .bind(&req.address_line2) + .bind(&req.city) + .bind(&req.state) + .bind(&req.postal_code) + .bind(&req.country) + .bind(&req.phone) + .bind(req.is_default.unwrap_or(false)) + .bind(id) + .bind(user.id) + .fetch_optional(state.db.pool()) + .await; + + match address { + Ok(Some(address)) => { + let response = AddressResponse::from(address); + (StatusCode::OK, Json(response)).into_response() + } + Ok(None) => ( + StatusCode::NOT_FOUND, + Json(ErrorResponse { + error: "Address not found or access denied".to_string(), + }), + ) + .into_response(), + Err(e) => ( + StatusCode::BAD_REQUEST, + Json(ErrorResponse { + error: e.to_string(), + }), + ) + .into_response(), + } + } + Ok(None) => ( + StatusCode::UNAUTHORIZED, + Json(ErrorResponse { + error: "Invalid or expired session".to_string(), + }), + ) + .into_response(), + Err(e) => ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(ErrorResponse { + error: e.to_string(), + }), + ) + .into_response(), + } + } else { + ( + StatusCode::UNAUTHORIZED, + Json(ErrorResponse { + error: "No session token provided".to_string(), + }), + ) + .into_response() + } +} + +#[instrument(name = "delete_address", skip(state, headers), fields(address.uuid = %id))] +pub async fn delete_address( + State(state): State<AppState>, + headers: axum::http::HeaderMap, + Path(id): Path<Uuid>, +) -> impl IntoResponse { + let token = extract_token(&headers); + + if let Some(token) = token { + match auth::validate_session(state.db.pool(), &token).await { + Ok(Some(user)) => { + // Soft delete: set is_active to false + let result = sqlx::query( + r#" + UPDATE user_addresses + SET is_active = false, updated_at = NOW() + WHERE uuid = $1 AND user_id = $2 AND is_active = true + "#, + ) + .bind(id) + .bind(user.id) + .execute(state.db.pool()) + .await; + + match result { + Ok(result) => { + if result.rows_affected() > 0 { + ( + StatusCode::OK, + Json(serde_json::json!({ + "message": "Address deleted successfully" + })), + ) + .into_response() + } else { + ( + StatusCode::NOT_FOUND, + Json(ErrorResponse { + error: "Address not found or access denied".to_string(), + }), + ) + .into_response() + } + } + Err(e) => ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(ErrorResponse { + error: e.to_string(), + }), + ) + .into_response(), + } + } + Ok(None) => ( + StatusCode::UNAUTHORIZED, + Json(ErrorResponse { + error: "Invalid or expired session".to_string(), + }), + ) + .into_response(), + Err(e) => ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(ErrorResponse { + error: e.to_string(), + }), + ) + .into_response(), + } + } else { + ( + StatusCode::UNAUTHORIZED, + Json(ErrorResponse { + error: "No session token provided".to_string(), + }), + ) + .into_response() + } +} + +fn extract_token(headers: &axum::http::HeaderMap) -> Option<String> { + use axum::http::header; + + // Try to get from Authorization header + if let Some(auth_header) = headers.get(header::AUTHORIZATION) { + if let Ok(auth_str) = auth_header.to_str() { + if auth_str.starts_with("Bearer ") { + return Some(auth_str[7..].to_string()); + } + } + } + + // Try to get from Cookie header + if let Some(cookie_header) = headers.get(header::COOKIE) { + if let Ok(cookie_str) = cookie_header.to_str() { + for cookie in cookie_str.split(';') { + let cookie = cookie.trim(); + if cookie.starts_with("session_token=") { + return Some(cookie[14..].to_string()); + } + } + } + } + + None +} diff --git a/distributed_observability/otelmart/src/main.rs b/distributed_observability/otelmart/src/main.rs @@ -0,0 +1,216 @@ +mod auth; +mod config; +mod db; +mod handlers; +mod models; +mod proxy; +mod telemetry; + +use anyhow::Result; +use axum::{ + body::Body, + http::{Request, StatusCode, Uri}, + response::{IntoResponse, Response}, + routing::{get, post}, + Router, +}; +use axum_tracing_opentelemetry::middleware::{OtelAxumLayer, OtelInResponseLayer}; +use std::net::SocketAddr; +use std::path::PathBuf; +use tower::ServiceExt; +use tower_http::{cors::CorsLayer, services::ServeDir}; +use tracing::info; + +use config::Config; +use db::Database; + +#[derive(Clone)] +pub struct AppState { + db: Database, + http_client: reqwest_middleware::ClientWithMiddleware, + products_service_url: String, + inventory_service_url: String, + orders_service_url: String, + checkout_service_url: String, +} + +/// SPA fallback handler that serves static files or index.html +async fn spa_fallback_handler( + uri: Uri, + req: Request<Body>, + serve_dir: ServeDir, + static_dir: String, +) -> impl IntoResponse { + let path = uri.path(); + + // Check if the request is for an actual file (has an extension) + let has_extension = path.rfind('.').map_or(false, |dot_pos| { + let after_dot = &path[dot_pos + 1..]; + // Check if it looks like a file extension (not empty and no slashes after) + !after_dot.is_empty() && !after_dot.contains('/') + }); + + // If it's a file with an extension, try to serve it + if has_extension { + match serve_dir.oneshot(req).await { + Ok(res) => { + // If file was found (status is not 404), return it + if res.status() != StatusCode::NOT_FOUND { + return res.into_response(); + } + // Otherwise fall through to serve index.html + } + Err(_) => { + // Error serving file, fall through to index.html + } + } + } + + // For all other routes (SPA routes like /products, /checkout, etc.) + // or files that weren't found, serve index.html + let index_path = PathBuf::from(&static_dir).join("index.html"); + + match tokio::fs::read_to_string(&index_path).await { + Ok(contents) => Response::builder() + .status(StatusCode::OK) + .header("content-type", "text/html; charset=utf-8") + .body(Body::from(contents)) + .unwrap() + .into_response(), + Err(_) => Response::builder() + .status(StatusCode::NOT_FOUND) + .header("content-type", "text/html; charset=utf-8") + .body(Body::from( + "<h1>UI not built</h1><p>Please build the Angular application first.</p>", + )) + .unwrap() + .into_response(), + } +} + +#[tokio::main] +async fn main() -> Result<()> { + // Initialize telemetry (tracing + OpenTelemetry) + let tracer_provider = telemetry::init_telemetry("otelmart"); + + // Load configuration from config.toml + let config = Config::load()?; + + // Log startup information using tracing macros + info!( + port = config.server.port, + database_url = %config.database.url, + products_service = format!("{}:{}", config.services.products_host, config.services.products_port), + inventory_service = format!("{}:{}", config.services.inventory_host, config.services.inventory_port), + orders_service = format!("{}:{}", config.services.orders_host, config.services.orders_port), + static_dir = %config.server.static_dir, + "Starting OtelMart Service" + ); + + // Initialize database connection + let db = Database::new(&config.database.url, config.database.max_connections).await?; + + // Create HTTP client with tracing middleware for automatic + // span creation and trace context propagation + let reqwest_client = reqwest::Client::builder() + .timeout(std::time::Duration::from_secs( + config.http_client.timeout_secs, + )) + .build()?; + let http_client = reqwest_middleware::ClientBuilder::new(reqwest_client) + .with(reqwest_tracing::TracingMiddleware::< + reqwest_tracing::SpanBackendWithUrl, + >::new()) + .build(); + + // Create application state + let state = AppState { + db, + http_client, + products_service_url: config.services.products_service_url(), + inventory_service_url: config.services.inventory_service_url_computed(), + orders_service_url: config.services.orders_service_url_computed(), + checkout_service_url: config.services.checkout_service_url(), + }; + + // Build API router + let api_router = Router::new() + // Auth routes + .route("/auth/register", post(handlers::auth::register)) + .route("/auth/login", post(handlers::auth::login)) + .route("/auth/logout", post(handlers::auth::logout)) + // User routes + .route("/users/profile", get(handlers::users::get_profile)) + .route("/users/profile", post(handlers::users::update_profile)) + .route("/users/addresses", get(handlers::users::get_addresses)) + .route("/users/addresses", post(handlers::users::add_address)) + .route( + "/users/addresses/{id}", + post(handlers::users::update_address), + ) + .route( + "/users/addresses/{id}", + axum::routing::delete(handlers::users::delete_address), + ) + // This is a common pattern in API gateways to ensure all request paths are + // properly routed to the backend services + // Proxy all /products/* requests to products service + .route( + "/products", + axum::routing::any(proxy::products::proxy_products), + ) + .route( + "/products/{*path}", + axum::routing::any(proxy::products::proxy_products), + ) + // Proxy all /inventory/* requests to inventory service + .route( + "/inventory", + axum::routing::any(proxy::inventory::proxy_inventory), + ) + .route( + "/inventory/{*path}", + axum::routing::any(proxy::inventory::proxy_inventory), + ) + // Proxy all /orders/* requests to orders service + .route("/orders", axum::routing::any(proxy::orders::proxy_orders)) + .route( + "/orders/{*path}", + axum::routing::any(proxy::orders::proxy_orders), + ) + .with_state(state.clone()); + + // Create static file service + let static_dir = config.server.static_dir.clone(); + let serve_dir = ServeDir::new(&static_dir); + + // Build main router + let app = Router::new() + // Health check + .route("/health", get(handlers::health::health_check)) + // Mount API routes under /api prefix + .nest("/api", api_router) + // Fallback handler for SPA routing + .fallback(move |uri: Uri, req: Request<Body>| { + let static_dir = static_dir.clone(); + let serve_dir = serve_dir.clone(); + async move { spa_fallback_handler(uri, req, serve_dir, static_dir).await } + }) + // Include trace context as header into the response + .layer(OtelInResponseLayer::default()) + // Start OpenTelemetry trace on incoming request + .layer(OtelAxumLayer::default()) + .layer(CorsLayer::permissive()); + + // Start server + let addr = SocketAddr::from(([0, 0, 0, 0], config.server.port)); + println!("\nOtelMart Service listening on {}", addr); + + let listener = tokio::net::TcpListener::bind(addr).await?; + axum::serve(listener, app).await?; + + // Shutdown telemetry on exit (flush pending spans) + telemetry::shutdown_telemetry(tracer_provider); + + Ok(()) +} diff --git a/distributed_observability_in_rust/example_project/otelmart/src/models/address.rs b/distributed_observability/otelmart/src/models/address.rs diff --git a/distributed_observability_in_rust/example_project/otelmart/src/models/mod.rs b/distributed_observability/otelmart/src/models/mod.rs diff --git a/distributed_observability_in_rust/example_project/otelmart/src/models/session.rs b/distributed_observability/otelmart/src/models/session.rs diff --git a/distributed_observability_in_rust/example_project/otelmart/src/models/user.rs b/distributed_observability/otelmart/src/models/user.rs diff --git a/distributed_observability_in_rust/example_project/otelmart/src/proxy/inventory.rs b/distributed_observability/otelmart/src/proxy/inventory.rs diff --git a/distributed_observability/otelmart/src/proxy/mod.rs b/distributed_observability/otelmart/src/proxy/mod.rs @@ -0,0 +1,102 @@ +pub mod inventory; +pub mod orders; +pub mod products; + +use axum::{ + body::Body, + extract::Request, + http::{HeaderValue, StatusCode}, + response::{IntoResponse, Response}, +}; + +/// Generic proxy handler that forwards requests to a backend service +/// +/// This function handles: +/// - Path and query string forwarding +/// - Header forwarding (except Host header) +/// - Request body forwarding +/// - Response status, headers, and body forwarding +/// +/// # Arguments +/// * `service_url` - Base URL of the backend service (e.g., "http://products:3001") +/// * `req` - The incoming request to proxy +/// * `http_client` - HTTP client for making the proxy request +pub async fn proxy_request( + service_url: &str, + req: Request, + http_client: &reqwest_middleware::ClientWithMiddleware, +) -> impl IntoResponse { + // Extract the path after /api prefix + let path = req.uri().path(); + let forwarded_path = path.strip_prefix("/api").unwrap_or(path); + let query = req + .uri() + .query() + .map(|q| format!("?{}", q)) + .unwrap_or_default(); + + // Build target URL + let target_url = format!("{}{}{}", service_url, forwarded_path, query); + + // Extract method and headers + let method = req.method().clone(); + let headers = req.headers().clone(); + + // Extract body + let body_bytes = match axum::body::to_bytes(req.into_body(), usize::MAX).await { + Ok(bytes) => bytes, + Err(_) => { + return Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(Body::from("Failed to read request body")) + .unwrap(); + } + }; + + // Build request to backend service + let mut client_req = http_client.request(method, &target_url); + + // Forward headers (except Host header) + for (name, value) in headers.iter() { + if name != "host" { + if let Ok(val) = HeaderValue::from_bytes(value.as_bytes()) { + client_req = client_req.header(name.as_str(), val); + } + } + } + + // Add body if present + if !body_bytes.is_empty() { + client_req = client_req.body(body_bytes.to_vec()); + } + + // Send request to backend service + match client_req.send().await { + Ok(response) => { + let status = response.status(); + let mut builder = Response::builder().status(status); + + // Forward response headers + let resp_headers = response.headers().clone(); + for (name, value) in resp_headers.iter() { + if let Ok(val) = HeaderValue::from_bytes(value.as_bytes()) { + builder = builder.header(name.as_str(), val); + } + } + + // Get response body + match response.bytes().await { + Ok(body) => builder.body(Body::from(body)).unwrap(), + Err(_) => Response::builder() + .status(StatusCode::INTERNAL_SERVER_ERROR) + .body(Body::from("Failed to read response body")) + .unwrap(), + } + } + Err(_) => Response::builder() + .status(StatusCode::SERVICE_UNAVAILABLE) + .header("content-type", "application/json") + .body(Body::from(r#"{"error":"Service unavailable"}"#)) + .unwrap(), + } +} diff --git a/distributed_observability_in_rust/example_project/otelmart/src/proxy/orders.rs b/distributed_observability/otelmart/src/proxy/orders.rs diff --git a/distributed_observability_in_rust/example_project/otelmart/src/proxy/products.rs b/distributed_observability/otelmart/src/proxy/products.rs diff --git a/distributed_observability/otelmart/src/telemetry.rs b/distributed_observability/otelmart/src/telemetry.rs @@ -0,0 +1,92 @@ +//! Telemetry initialization for the OtelMart service. +//! +//! This module configures OpenTelemetry tracing with OTLP export to Jaeger. +//! It sets up a layered tracing subscriber that outputs both to stdout and +//! sends spans to the configured OTLP endpoint. + +use opentelemetry::global; +use opentelemetry::trace::TracerProvider as _; +use opentelemetry_otlp::WithExportConfig; +use opentelemetry_sdk::{propagation::TraceContextPropagator, trace::SdkTracerProvider, Resource}; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter}; + +/// Initializes the telemetry pipeline for the service. +/// +/// This function sets up: +/// - An OTLP exporter that sends traces to Jaeger (via OTEL_EXPORTER_OTLP_ENDPOINT) +/// - A tracing subscriber with environment-based filtering (RUST_LOG) +/// - Console output for local debugging +/// +/// # Arguments +/// * `service_name` - The name of this service, used to identify traces in Jaeger +/// +/// # Returns +/// * `SdkTracerProvider` - The tracer provider, which should be kept alive and +/// shut down gracefully when the application exits +/// +/// # Panics +/// Panics if the OTLP exporter or tracing subscriber cannot be initialized. +pub fn init_telemetry(service_name: &str) -> SdkTracerProvider { + // Set up W3C Trace Context propagator for cross-service trace correlation + global::set_text_map_propagator(TraceContextPropagator::new()); + + // Get the OTLP endpoint from environment, defaulting to localhost for local dev + let otlp_endpoint = std::env::var("OTEL_EXPORTER_OTLP_ENDPOINT") + .unwrap_or_else(|_| "http://localhost:4317".to_string()); + + // Create the OTLP exporter configured to send traces via gRPC + let exporter = opentelemetry_otlp::SpanExporter::builder() + .with_tonic() + .with_endpoint(&otlp_endpoint) + .build() + .expect("Failed to create OTLP exporter"); + + // Build the tracer provider with the exporter and service resource + let provider = SdkTracerProvider::builder() + .with_batch_exporter(exporter) + .with_resource( + Resource::builder_empty() + .with_service_name(service_name.to_string()) + .build(), + ) + .build(); + + // Create a tracer from the provider for the OpenTelemetry layer + let tracer = provider.tracer(service_name.to_string()); + + // Create the OpenTelemetry tracing layer + let otel_layer = tracing_opentelemetry::layer().with_tracer(tracer); + + // Create an environment filter for log levels (defaults to "info") + // Include otel::tracing=trace to allow axum-tracing-opentelemetry spans through + let env_filter = EnvFilter::try_from_default_env() + .unwrap_or_else(|_| EnvFilter::new("info,otel::tracing=trace")); + + // Create a formatting layer for console output + let fmt_layer = tracing_subscriber::fmt::layer() + .with_target(true) + .with_thread_ids(false) + .compact(); + + // Combine all layers into a subscriber and set it as the global default + tracing_subscriber::registry() + .with(env_filter) + .with(fmt_layer) + .with(otel_layer) + .init(); + + provider +} + +/// Shuts down the telemetry pipeline gracefully. +/// +/// This ensures all pending spans are flushed to the OTLP endpoint +/// before the application exits. +/// +/// # Arguments +/// * `provider` - The tracer provider returned from `init_telemetry` +pub fn shutdown_telemetry(provider: SdkTracerProvider) { + if let Err(e) = provider.shutdown() { + eprintln!("Failed to shutdown tracer provider: {e}"); + } +} diff --git a/distributed_observability/products/Cargo.toml b/distributed_observability/products/Cargo.toml @@ -0,0 +1,56 @@ +[package] +name = "products" +version.workspace = true +edition.workspace = true +authors.workspace = true + +[lints] +workspace = true + +[dependencies] +# Async runtime +tokio = { workspace = true } + +# Web framework +axum = { workspace = true } +tower = { workspace = true } +tower-http = { workspace = true } + +# Database +sqlx = { workspace = true } + +# Serialization +serde = { workspace = true } +serde_json = { workspace = true } + +# Utilities +uuid = { workspace = true } +chrono = { workspace = true } +anyhow = { workspace = true } +thiserror = { workspace = true } +bigdecimal = { workspace = true } + +# Configuration +config = { workspace = true } +dotenvy = { workspace = true } + +# Telemetry / Observability +# +# Core tracing ecosystem +tracing = { workspace = true } +tracing-subscriber = { workspace = true } + +# OpenTelemetry core +opentelemetry = { workspace = true } +opentelemetry_sdk = { workspace = true } + +# OTLP exporter (sends traces to collectors/backends) +opentelemetry-otlp = { workspace = true } + +# Bridge between tracing and OpenTelemetry +tracing-opentelemetry = { workspace = true } + +# HTTP instrumentation (server + client) +axum-tracing-opentelemetry = { workspace = true } +reqwest-middleware = { workspace = true } +reqwest-tracing = { workspace = true } diff --git a/distributed_observability_in_rust/example_project/products/Dockerfile b/distributed_observability/products/Dockerfile diff --git a/distributed_observability_in_rust/example_project/products/config.docker.toml b/distributed_observability/products/config.docker.toml diff --git a/distributed_observability_in_rust/example_project/products/config.toml b/distributed_observability/products/config.toml diff --git a/distributed_observability_in_rust/example_project/products/docker-compose.yml b/distributed_observability/products/docker-compose.yml diff --git a/distributed_observability_in_rust/example_project/products/src/config.rs b/distributed_observability/products/src/config.rs diff --git a/distributed_observability_in_rust/example_project/products/src/db/mod.rs b/distributed_observability/products/src/db/mod.rs diff --git a/distributed_observability_in_rust/example_project/products/src/handlers/mod.rs b/distributed_observability/products/src/handlers/mod.rs diff --git a/distributed_observability/products/src/handlers/products.rs b/distributed_observability/products/src/handlers/products.rs @@ -0,0 +1,393 @@ +//! Product API handlers +//! +//! This module contains the HTTP request handlers for product-related endpoints. +//! Handlers use sqlx for database queries with the products schema. + +use axum::{ + extract::{Path, Query, State}, + http::StatusCode, + response::{IntoResponse, Json}, +}; +use sqlx::{PgPool, Postgres, QueryBuilder}; +use tracing::instrument; +use uuid::Uuid; + +use crate::models::{ProductDetail, ProductQueryParams, ProductWithRating, ProductsResponse}; +use crate::utils::{calculate_pagination, calculate_total_pages, internal_error, not_found_error}; + +/// List products with pagination and filtering +/// +/// # Endpoint +/// `GET /products` +/// +/// # Query Parameters +/// - **Pagination:** +/// - `page` (default: 1) - Page number (1-indexed) +/// - `page_size` (default: 20, max: 100) - Items per page +/// +/// - **Filters:** +/// - `name` - Product name partial match (case-insensitive) +/// - `category_id` - Filter by category ID +/// - `brand` - Brand partial match (case-insensitive) +/// - `start_date` / `end_date` - Filter by update date range +/// - `rating_gt` / `rating_lt` / `rating_eq` - Rating filters +/// - `min_price` / `max_price` - Price range filters +/// +/// # Example +/// ``` +/// GET /products?page=2&page_size=50&brand=TechPro&min_price=100 +/// ``` +/// +/// # Response +/// Returns a `ProductsResponse` with products array and pagination metadata. +#[instrument( + name = "list_products", + skip(pool), + fields( + page = params.page, + page_size = params.page_size, + category_id = ?params.category_id, + brand = ?params.brand + ) +)] +pub async fn list_products( + State(pool): State<PgPool>, + Query(params): Query<ProductQueryParams>, +) -> impl IntoResponse { + // Apply pagination defaults and constraints + let (page, page_size, offset) = calculate_pagination(params.page, params.page_size); + + // Check if we have rating filters (determines count query strategy) + let has_rating_filters = + params.rating_gt.is_some() || params.rating_lt.is_some() || params.rating_eq.is_some(); + + // Build count query - optimized based on whether we have rating filters + let total_count = if has_rating_filters { + // Complex count: need to aggregate ratings and apply HAVING clause + match build_count_with_ratings(&pool, ¶ms).await { + Ok(count) => count, + Err(response) => return response, + } + } else { + // Simple count: no need for ratings JOIN or GROUP BY + match build_simple_count(&pool, ¶ms).await { + Ok(count) => count, + Err(response) => return response, + } + }; + + // Build main query with CTE for product data and ratings + let mut main_query = QueryBuilder::<Postgres>::new( + r#" + WITH product_data AS ( + SELECT + p.id, + p.uuid, + p.product_name, + p.brand, + p.description, + p.price, + p.initial_price, + p.discount, + p.stock_quantity, + p.image_url, + p.category_id, + c.name as category_name, + p.created_at, + p.updated_at, + COALESCE(AVG(r.rating)::FLOAT8, NULL) as average_rating, + COUNT(r.id)::BIGINT as rating_count + FROM products p + LEFT JOIN categories c ON p.category_id = c.id + LEFT JOIN ratings r ON p.id = r.product_id + WHERE p.deleted_at IS NULL AND p.is_active = true AND p.stock_quantity > 0 + GROUP BY p.id, p.uuid, p.product_name, p.brand, p.description, p.price, + p.initial_price, p.discount, p.stock_quantity, p.image_url, p.category_id, c.name, + p.created_at, p.updated_at + ) + SELECT * FROM product_data WHERE 1=1 + "#, + ); + + // Apply filters with safe parameter binding + apply_filters(&mut main_query, ¶ms); + + // Add ordering and pagination + main_query.push(" ORDER BY updated_at DESC LIMIT "); + main_query.push_bind(page_size); + main_query.push(" OFFSET "); + main_query.push_bind(offset); + + // Execute main query to fetch products + let products: Vec<ProductWithRating> = match main_query.build_query_as().fetch_all(&pool).await + { + Ok(products) => products, + Err(e) => { + return internal_error("Failed to fetch products", e.to_string()); + } + }; + + // Calculate total pages + let total_pages = calculate_total_pages(total_count, page_size); + + // Build response + let response = ProductsResponse { + products, + total_count, + page, + page_size, + total_pages, + }; + + (StatusCode::OK, Json(response)).into_response() +} + +/// Apply product filters to a query builder +/// +/// This helper function centralizes filter logic to avoid duplication across +/// count queries and main queries. +/// +/// # Arguments +/// * `query` - The QueryBuilder to apply filters to +/// * `params` - Query parameters containing filter values +/// * `column_prefix` - Prefix for column names ("p." for table alias, "" for CTE columns) +/// * `include_ratings` - Whether to include rating filters (only for main query on CTE) +fn apply_product_filters<'a>( + query: &mut QueryBuilder<'a, Postgres>, + params: &'a ProductQueryParams, + column_prefix: &str, + include_ratings: bool, +) { + // Name filter - case-insensitive partial match + if let Some(ref name) = params.name { + query.push(format!(" AND {}product_name ILIKE ", column_prefix).as_str()); + query.push_bind(format!("%{}%", name)); + } + + // Category filter - exact match + if let Some(category_id) = params.category_id { + query.push(format!(" AND {}category_id = ", column_prefix).as_str()); + query.push_bind(category_id); + } + + // Brand filter - case-insensitive partial match + if let Some(ref brand) = params.brand { + query.push(format!(" AND {}brand ILIKE ", column_prefix).as_str()); + query.push_bind(format!("%{}%", brand)); + } + + // Date range filters on updated_at + if let Some(start_date) = params.start_date { + query.push(format!(" AND {}updated_at >= ", column_prefix).as_str()); + query.push_bind(start_date); + } + + if let Some(end_date) = params.end_date { + query.push(format!(" AND {}updated_at <= ", column_prefix).as_str()); + query.push_bind(end_date); + } + + // Price range filters + if let Some(ref min_price) = params.min_price { + query.push(format!(" AND {}price >= ", column_prefix).as_str()); + query.push_bind(min_price); + } + + if let Some(ref max_price) = params.max_price { + query.push(format!(" AND {}price <= ", column_prefix).as_str()); + query.push_bind(max_price); + } + + // Rating filters (only for main query on CTE columns) + if include_ratings { + if let Some(rating_gt) = params.rating_gt { + query.push(" AND average_rating > "); + query.push_bind(rating_gt); + } + + if let Some(rating_lt) = params.rating_lt { + query.push(" AND average_rating < "); + query.push_bind(rating_lt); + } + + if let Some(rating_eq) = params.rating_eq { + query.push(" AND average_rating = "); + query.push_bind(rating_eq); + } + } +} + +/// Build simple count query without rating joins (faster) +async fn build_simple_count( + pool: &PgPool, + params: &ProductQueryParams, +) -> Result<i64, axum::response::Response> { + let mut count_builder = QueryBuilder::<Postgres>::new( + "SELECT COUNT(*) FROM products p WHERE p.deleted_at IS NULL AND p.is_active = true AND p.stock_quantity > 0" + ); + + // Apply non-rating filters using helper + apply_product_filters(&mut count_builder, params, "p.", false); + + match count_builder.build_query_scalar().fetch_one(pool).await { + Ok(count) => Ok(count), + Err(e) => Err(internal_error("Failed to count products", e.to_string())), + } +} + +/// Build count query with rating aggregation (for rating filters) +async fn build_count_with_ratings( + pool: &PgPool, + params: &ProductQueryParams, +) -> Result<i64, axum::response::Response> { + let mut count_builder = QueryBuilder::<Postgres>::new( + r#" + SELECT COUNT(DISTINCT p.id) FROM products p + LEFT JOIN ratings r ON p.id = r.product_id + WHERE p.deleted_at IS NULL AND p.is_active = true AND p.stock_quantity > 0 + "#, + ); + + // Apply non-rating filters to WHERE clause using helper + apply_product_filters(&mut count_builder, params, "p.", false); + + // Add GROUP BY for ratings aggregation + count_builder.push(" GROUP BY p.id"); + + // Apply rating filters with HAVING clause + let mut has_having = false; + + if let Some(rating_gt) = params.rating_gt { + count_builder.push(if has_having { " AND " } else { " HAVING " }); + has_having = true; + count_builder.push("AVG(r.rating) > "); + count_builder.push_bind(rating_gt); + } + + if let Some(rating_lt) = params.rating_lt { + count_builder.push(if has_having { " AND " } else { " HAVING " }); + has_having = true; + count_builder.push("AVG(r.rating) < "); + count_builder.push_bind(rating_lt); + } + + if let Some(rating_eq) = params.rating_eq { + count_builder.push(if has_having { " AND " } else { " HAVING " }); + count_builder.push("AVG(r.rating) = "); + count_builder.push_bind(rating_eq); + } + + // This returns a count of distinct products, but we need to wrap it in another SELECT COUNT(*) + // Actually, COUNT(DISTINCT p.id) already gives us the total count directly + match count_builder.build_query_scalar().fetch_one(pool).await { + Ok(count) => Ok(count), + Err(e) => Err(internal_error("Failed to count products", e.to_string())), + } +} + +/// Apply filters to the main query +fn apply_filters<'a>(query: &mut QueryBuilder<'a, Postgres>, params: &'a ProductQueryParams) { + // Use helper with empty prefix (CTE columns) and include ratings + apply_product_filters(query, params, "", true); +} + +/// Get detailed product information by UUID +/// +/// # Endpoint +/// `GET /products/{uuid}` +/// +/// # Path Parameters +/// - `uuid` - The product UUID +/// +/// # Response +/// Returns a `ProductDetail` with full product information including: +/// - All product fields (name, description, price, stock, etc.) +/// - Category information (name, uuid, slug) +/// - Aggregated rating data (average rating, review count) +/// - Additional metadata (timestamps, availability flags, etc.) +/// +/// # Errors +/// - `404 NOT FOUND` - Product not found or has been deleted +/// - `500 INTERNAL SERVER ERROR` - Database error +/// +/// # Example +/// ``` +/// GET /products/550e8400-e29b-41d4-a716-446655440000 +/// ``` +#[instrument( // Automatic span creation + name = "get_product_by_id", + skip(pool), // Don't log the entire AppState (too verbose) + fields(product.uuid = %uuid) // Attach product UUID as span attribute +)] +pub async fn get_product_by_id( + State(pool): State<PgPool>, + Path(uuid): Path<Uuid>, +) -> impl IntoResponse { + tracing::info!("Fetching product"); + + // Query product with all details, joined with category and aggregated ratings + // Uses LEFT JOINs to handle products without categories or ratings + let result = sqlx::query_as::<_, ProductDetail>( + r#" + SELECT + p.id, + p.uuid, + p.asin, + p.sku, + p.gtin, + p.product_name, + p.brand, + p.description, + p.url, + p.price, + p.initial_price, + p.discount, + p.currency, + p.stock_quantity, + p.sizes, + p.colors, + p.image_url, + p.available_for_delivery, + p.available_for_pickup, + p.free_returns, + p.is_active, + p.created_at, + p.updated_at, + p.data_timestamp, + p.category_id, + c.name as category_name, + c.uuid as category_uuid, + c.slug as category_slug, + COALESCE(AVG(r.rating)::FLOAT8, NULL) as average_rating, + COUNT(r.id)::BIGINT as rating_count, + CAST(p.id AS TEXT) as product_id_str, + get_root_category_name(p.category_id) as root_category_name, + p.deleted_at + FROM products p + LEFT JOIN categories c ON p.category_id = c.id + LEFT JOIN ratings r ON p.id = r.product_id + WHERE p.uuid = $1 AND p.deleted_at IS NULL + GROUP BY p.id, p.uuid, p.asin, p.sku, p.gtin, p.product_name, p.brand, p.description, + p.url, p.price, p.initial_price, p.discount, p.currency, p.stock_quantity, p.sizes, p.colors, p.image_url, + p.available_for_delivery, p.available_for_pickup, p.free_returns, + p.is_active, p.created_at, p.updated_at, p.data_timestamp, p.category_id, + p.deleted_at, c.name, c.uuid, c.slug + "#, + ) + .bind(uuid) + .fetch_optional(&pool) + .await; + + match result { + Ok(Some(mut product)) => { + // Set the string representation of the product ID + product.set_product_id(); + (StatusCode::OK, Json(product)).into_response() + } + Ok(None) => not_found_error( + "Product not found", + serde_json::json!({"uuid": uuid.to_string()}), + ), + Err(e) => internal_error("Failed to fetch product", e.to_string()), + } +} diff --git a/distributed_observability/products/src/handlers/ratings.rs b/distributed_observability/products/src/handlers/ratings.rs @@ -0,0 +1,171 @@ +//! Product rating API handlers +//! +//! This module handles creating and updating product ratings. +//! Enforces one rating per user per product using database upsert logic. + +use axum::{ + extract::{Path, State}, + http::StatusCode, + response::{IntoResponse, Json}, +}; +use sqlx::PgPool; +use tracing::instrument; +use uuid::Uuid; + +use crate::models::{Rating, RatingResponse, UpsertRatingRequest}; + +/// Create or update a user's rating for a product +/// +/// # Endpoint +/// `PUT /products/{id}/ratings` +/// +/// # Path Parameters +/// - `id` - The product ID to rate +/// +/// # Request Body +/// ```json +/// { +/// "user_id": "123e4567-e89b-12d3-a456-426614174000", +/// "rating": 5, +/// "review": "Great product!" +/// } +/// ``` +/// +/// # Behavior +/// - If the user has already rated this product, the existing rating is **updated** +/// - If not, a new rating is **created** +/// - This is enforced by a unique constraint on (product_id, user_id) +/// +/// # Validation +/// - Rating must be between 1-5 +/// - Product must exist and not be deleted +/// - User must exist in the users table +/// +/// # Response +/// Returns the created/updated rating with a message indicating the action taken. +/// +/// # Errors +/// - `400 BAD REQUEST` - Invalid rating value (not 1-5) or user doesn't exist +/// - `404 NOT FOUND` - Product doesn't exist +/// - `500 INTERNAL SERVER ERROR` - Database error +#[instrument( + name = "upsert_rating", + skip(pool, payload), + fields( + product.uuid = %product_id, + rating.value = payload.rating + ) +)] +pub async fn upsert_rating( + State(pool): State<PgPool>, + Path(product_id): Path<Uuid>, + Json(payload): Json<UpsertRatingRequest>, +) -> impl IntoResponse { + // Validate rating is within acceptable range (1-5 stars) + if !(1..=5).contains(&payload.rating) { + return ( + StatusCode::BAD_REQUEST, + Json(serde_json::json!({ + "error": "Invalid rating value", + "message": "Rating must be between 1 and 5" + })), + ) + .into_response(); + } + + // Verify the product exists and is not deleted + // Uses EXISTS for efficiency - only checks presence, doesn't fetch data + let product_exists: Option<(bool,)> = sqlx::query_as( + "SELECT EXISTS(SELECT 1 FROM products WHERE uuid = $1 AND deleted_at IS NULL)", + ) + .bind(product_id) + .fetch_optional(&pool) + .await + .ok() + .flatten(); + + if !product_exists.map(|x| x.0).unwrap_or(false) { + return ( + StatusCode::NOT_FOUND, + Json(serde_json::json!({ + "error": "Product not found", + "product_id": product_id + })), + ) + .into_response(); + } + + // Upsert the rating using PostgreSQL's ON CONFLICT clause + // This atomically either: + // 1. Inserts a new rating if none exists for this user-product pair + // 2. Updates the existing rating if one already exists + // + // The unique constraint on (product_id, user_id) ensures one rating per user per product + let result = sqlx::query_as::<_, Rating>( + r#" + INSERT INTO ratings (product_id, user_id, rating, review) + VALUES ($1, $2, $3, $4) + ON CONFLICT (product_id, user_id) + DO UPDATE SET + rating = EXCLUDED.rating, + review = EXCLUDED.review, + updated_at = NOW() + RETURNING id, uuid, product_id, user_id, rating, review, created_at, updated_at + "#, + ) + .bind(product_id) + .bind(payload.user_id) + .bind(payload.rating) + .bind(&payload.review) + .fetch_one(&pool) + .await; + + match result { + Ok(rating) => { + // Determine if this was an update or new insert + // If created_at != updated_at, the record was updated + let was_updated = rating.created_at != rating.updated_at; + let message = if was_updated { + "Rating updated successfully" + } else { + "Rating created successfully" + }; + + ( + StatusCode::OK, + Json(RatingResponse { + rating, + message: message.to_string(), + }), + ) + .into_response() + } + Err(e) => { + eprintln!("Database error upserting rating: {}", e); + + // Check for foreign key constraint violations + // This happens when user_id doesn't exist in the users table + let error_message = e.to_string(); + if error_message.contains("foreign key") || error_message.contains("violates") { + return ( + StatusCode::BAD_REQUEST, + Json(serde_json::json!({ + "error": "Invalid user_id", + "message": "User must be registered before rating products" + })), + ) + .into_response(); + } + + // Generic database error + ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(serde_json::json!({ + "error": "Failed to save rating", + "details": e.to_string() + })), + ) + .into_response() + } + } +} diff --git a/distributed_observability/products/src/main.rs b/distributed_observability/products/src/main.rs @@ -0,0 +1,102 @@ +//! Products Service +//! +//! A microservice for managing product catalog, details, and ratings. +//! +//! # Features +//! - Product listing with pagination and filtering +//! - Product detail retrieval +//! - Product rating/review management +//! - PostgreSQL database with products schema +//! - CORS enabled for web client access +//! +//! # API Endpoints +//! - `GET /products` - List products with filters and pagination +//! - `GET /products/{id}` - Get detailed product information +//! - `PUT /products/{id}/ratings` - Create or update a product rating +//! +//! # Configuration +//! The service is configured via: +//! - Environment variables (loaded from .env if present) +//! - config.toml file +//! +//! # Database +//! Uses the `products` schema in PostgreSQL with automatic search path configuration. +//! Migrations are run automatically on startup. + +mod config; +mod db; +mod handlers; +mod models; +mod telemetry; +mod utils; + +use anyhow::Result; +use axum::{ + routing::{get, put}, + Router, +}; +use axum_tracing_opentelemetry::middleware::{OtelAxumLayer, OtelInResponseLayer}; +use std::net::SocketAddr; +use tower_http::cors::CorsLayer; +use tracing::info; + +use config::Config; +use db::Database; + +#[tokio::main] +async fn main() -> Result<()> { + // Load environment variables from .env file if present + // This is optional - the service will work without it + dotenvy::dotenv().ok(); + + let tracer_provider = telemetry::init_telemetry("products"); + + // Load configuration from config.toml + let config = Config::load()?; + + // Print startup information + println!("Starting Products Service..."); + println!("Server port: {}", config.server.port); + println!("Database URL: {}", config.database.url); + + // Initialize database connection pool + // This sets the search path to the products schema for all connections + let db = Database::new(&config.database.url, config.database.max_connections).await?; + + // Build the application router with all endpoints + let app = Router::new() + // Product endpoints + .route("/products", get(handlers::list_products)) + .route("/products/{id}", get(handlers::get_product_by_id)) + // Rating endpoints + .route("/products/{id}/ratings", put(handlers::upsert_rating)) + // Enable CORS for all routes + // This allows the Angular frontend to make API calls + .layer(CorsLayer::permissive()) + // Add database pool to application state + // All handlers will have access to this via State extractor + .with_state(db.pool().clone()) + .layer(OtelInResponseLayer) + .layer(OtelAxumLayer::default()) + .layer(CorsLayer::permissive()); + + // Create socket address from configuration + let addr = SocketAddr::from(([0, 0, 0, 0], config.server.port)); + + // Print API documentation + info!(port = config.server.port, "Products Service listening on "); + info!("\nProducts Service listening on {}", addr); + info!("\nAvailable endpoints:"); + info!(" GET /products - List products (with pagination & filters)"); + info!(" GET /products/{{id}} - Get product details"); + info!(" PUT /products/{{id}}/ratings - Create/update product rating"); + + // Start the HTTP server + let listener = tokio::net::TcpListener::bind(addr).await?; + axum::serve(listener, app).await?; + + // Graceful shutdown telemetry + telemetry::shutdown_telemetry(tracer_provider); + + Ok(()) +} diff --git a/distributed_observability_in_rust/example_project/products/src/models/mod.rs b/distributed_observability/products/src/models/mod.rs diff --git a/distributed_observability_in_rust/example_project/products/src/models/product.rs b/distributed_observability/products/src/models/product.rs diff --git a/distributed_observability_in_rust/example_project/products/src/models/rating.rs b/distributed_observability/products/src/models/rating.rs diff --git a/distributed_observability/products/src/telemetry.rs b/distributed_observability/products/src/telemetry.rs @@ -0,0 +1,58 @@ +use opentelemetry::{global::set_text_map_propagator, trace::TracerProvider}; +use opentelemetry_otlp::{SpanExporter, WithExportConfig}; +use opentelemetry_sdk::{ + propagation::TraceContextPropagator, + trace::{RandomIdGenerator, SdkTracerProvider}, + Resource, +}; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter}; + +pub fn init_telemetry(service_name: &str) -> SdkTracerProvider { + // Cross service trace correlation + set_text_map_propagator(TraceContextPropagator::new()); + + let otlp_endpoint = std::env::var("OTEL_EXPORTER_OTLP_ENDPOINT") + .unwrap_or_else(|_| "http://localhost:4317".to_string()); + + let exporter = SpanExporter::builder() + .with_tonic() + .with_endpoint(&otlp_endpoint) + .build() + .expect("Failed to create OTLP exporter"); + + let provider = SdkTracerProvider::builder() + .with_batch_exporter(exporter) + .with_id_generator(RandomIdGenerator::default()) + .with_resource( + Resource::builder_empty() + .with_service_name(service_name.to_string()) + .build(), + ) + .build(); + + let tracer = provider.tracer(service_name.to_string()); + + let otel_layer = tracing_opentelemetry::layer().with_tracer(tracer); + + let env_filter = EnvFilter::try_from_default_env() + .unwrap_or_else(|_| EnvFilter::new("info,otel::tracing=trace")); + + let fmt_layer = tracing_subscriber::fmt::layer() + .with_target(true) + .with_thread_ids(false) + .compact(); + + tracing_subscriber::registry() + .with(env_filter) + .with(fmt_layer) + .with(otel_layer) + .init(); + + provider +} + +pub fn shutdown_telemetry(provider: SdkTracerProvider) { + if let Err(e) = provider.shutdown() { + eprintln!("Failed to shutdown tracer provider: {e}"); + } +} diff --git a/distributed_observability_in_rust/example_project/products/src/utils.rs b/distributed_observability/products/src/utils.rs diff --git a/distributed_observability_in_rust/example_project/schemas/Dockerfile b/distributed_observability/schemas/Dockerfile diff --git a/distributed_observability_in_rust/example_project/schemas/README.md b/distributed_observability/schemas/README.md diff --git a/distributed_observability_in_rust/example_project/schemas/data/Dockerfile b/distributed_observability/schemas/data/Dockerfile diff --git a/distributed_observability/schemas/data/ingest.sh b/distributed_observability/schemas/data/ingest.sh @@ -0,0 +1,58 @@ +#!/bin/sh +# ============================================================ +# Data Ingestion Script +# ============================================================ +# Loads data into PostgreSQL database + +set -e + +echo "=========================================" +echo "Starting data ingestion..." +echo "=========================================" + +# Database connection parameters +DB_HOST="${DB_HOST:-postgres}" +DB_PORT="${DB_PORT:-5432}" +DB_NAME="${DB_NAME:-opentel_db}" +DB_USER="${DB_USER:-opentel_user}" +DB_PASSWORD="${DB_PASSWORD:-opentel_pass}" +WAIT_TIME="${WAIT_TIME:-10}" + +export PGPASSWORD="$DB_PASSWORD" + +echo "Waiting for database to be ready..." +until pg_isready -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d "$DB_NAME"; do + echo "Database is unavailable - sleeping" + sleep 2 +done + +echo "Database is ready!" +echo "" + +# Wait for products service to complete migrations +echo "Waiting ${WAIT_TIME}s for products service migrations to complete..." +sleep "$WAIT_TIME" +echo "" + +# Load data files in order +echo "Loading products test data..." +if [ -f /data/products_test_data.sql ]; then + psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d "$DB_NAME" -f /data/products_test_data.sql + echo "✓ Products test data loaded successfully" +else + echo "⚠ products_test_data.sql not found, skipping..." +fi + +echo "" +echo "Backfilling inventory schema from product catalog..." +if [ -f /data/inventory_seed.sql ]; then + psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d "$DB_NAME" -f /data/inventory_seed.sql + echo "✓ Inventory seed loaded successfully" +else + echo "⚠ inventory_seed.sql not found, skipping..." +fi + +echo "" +echo "=========================================" +echo "Data ingestion completed!" +echo "=========================================" diff --git a/distributed_observability/schemas/data/inventory_seed.sql b/distributed_observability/schemas/data/inventory_seed.sql @@ -0,0 +1,46 @@ +-- ============================================================ +-- Inventory seed data +-- ============================================================ +-- products_test_data.sql only populates the products schema. The inventory +-- service reads inventory.product_inventory / inventory.product_pricing, so +-- without this backfill every reserve_stock() call returns FALSE ("Insufficient +-- stock available") because the product has no inventory row at all. + +SET search_path TO inventory, public; + +INSERT INTO product_inventory ( + product_uuid, product_asin, stock_quantity, reserved_quantity, + stock_status, last_restocked_at +) +SELECT + p.uuid, + p.asin, + COALESCE(p.stock_quantity, 0), + 0, + CASE + WHEN COALESCE(p.stock_quantity, 0) = 0 THEN 'out_of_stock' + WHEN p.stock_quantity <= 10 THEN 'low_stock' + ELSE 'in_stock' + END, + CURRENT_TIMESTAMP +FROM products.products p +WHERE p.is_active AND p.deleted_at IS NULL +ON CONFLICT (product_uuid) DO NOTHING; + +INSERT INTO product_pricing ( + product_uuid, product_asin, final_price, initial_price, currency, + discount_percentage, discount_amount, is_active +) +SELECT + p.uuid, + p.asin, + p.price, + p.initial_price, + COALESCE(p.currency, 'USD'), + -- products.discount is text like '13%' + NULLIF(regexp_replace(COALESCE(p.discount, ''), '[^0-9.]', '', 'g'), '')::numeric, + CASE WHEN p.initial_price IS NOT NULL THEN ROUND(p.initial_price - p.price, 2) END, + true +FROM products.products p +WHERE p.is_active AND p.deleted_at IS NULL AND p.price IS NOT NULL +ON CONFLICT DO NOTHING; diff --git a/distributed_observability_in_rust/example_project/schemas/data/products_data.sql b/distributed_observability/schemas/data/products_data.sql diff --git a/distributed_observability_in_rust/example_project/schemas/data/products_data_enhanced.sql b/distributed_observability/schemas/data/products_data_enhanced.sql diff --git a/distributed_observability_in_rust/example_project/schemas/data/products_test_data.sql b/distributed_observability/schemas/data/products_test_data.sql diff --git a/distributed_observability_in_rust/example_project/schemas/docker-compose.yml b/distributed_observability/schemas/docker-compose.yml diff --git a/distributed_observability_in_rust/example_project/schemas/generate_products.js b/distributed_observability/schemas/generate_products.js diff --git a/distributed_observability_in_rust/example_project/schemas/generate_products_enhanced.js b/distributed_observability/schemas/generate_products_enhanced.js diff --git a/distributed_observability_in_rust/example_project/schemas/generate_test_data.js b/distributed_observability/schemas/generate_test_data.js diff --git a/distributed_observability_in_rust/example_project/schemas/generate_test_products.js b/distributed_observability/schemas/generate_test_products.js diff --git a/distributed_observability_in_rust/example_project/schemas/init/00_init.sql b/distributed_observability/schemas/init/00_init.sql diff --git a/distributed_observability_in_rust/example_project/schemas/init/inventory_schema_1.sql b/distributed_observability/schemas/init/inventory_schema_1.sql diff --git a/distributed_observability_in_rust/example_project/schemas/init/orders_schema_1.sql b/distributed_observability/schemas/init/orders_schema_1.sql diff --git a/distributed_observability_in_rust/example_project/schemas/init/products_schema_1.sql b/distributed_observability/schemas/init/products_schema_1.sql diff --git a/distributed_observability_in_rust/example_project/schemas/init/users_schema_1.sql b/distributed_observability/schemas/init/users_schema_1.sql diff --git a/distributed_observability_in_rust/example_project/schemas/reset_schema.sh b/distributed_observability/schemas/reset_schema.sh diff --git a/distributed_observability_in_rust/example_project/schemas/test_data.sql b/distributed_observability/schemas/test_data.sql diff --git a/distributed_observability_in_rust/example_project/Cargo.lock b/distributed_observability_in_rust/example_project/Cargo.lock @@ -1,3319 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 4 - -[[package]] -name = "ahash" -version = "0.8.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75" -dependencies = [ - "cfg-if", - "once_cell", - "version_check", - "zerocopy", -] - -[[package]] -name = "allocator-api2" -version = "0.2.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" - -[[package]] -name = "android_system_properties" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" -dependencies = [ - "libc", -] - -[[package]] -name = "anyhow" -version = "1.0.100" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61" - -[[package]] -name = "arraydeque" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d902e3d592a523def97af8f317b08ce16b7ab854c1985a0c671e6f15cebc236" - -[[package]] -name = "async-trait" -version = "0.1.89" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "atoi" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f28d99ec8bfea296261ca1af174f24225171fea9664ba9003cbebee704810528" -dependencies = [ - "num-traits", -] - -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - -[[package]] -name = "autocfg" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" - -[[package]] -name = "axum" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b098575ebe77cb6d14fc7f32749631a6e44edbef6b796f89b020e99ba20d425" -dependencies = [ - "axum-core", - "axum-macros", - "bytes", - "form_urlencoded", - "futures-util", - "http", - "http-body", - "http-body-util", - "hyper", - "hyper-util", - "itoa", - "matchit", - "memchr", - "mime", - "percent-encoding", - "pin-project-lite", - "serde_core", - "serde_json", - "serde_path_to_error", - "serde_urlencoded", - "sync_wrapper", - "tokio", - "tower", - "tower-layer", - "tower-service", - "tracing", -] - -[[package]] -name = "axum-core" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59446ce19cd142f8833f856eb31f3eb097812d1479ab224f54d72428ca21ea22" -dependencies = [ - "bytes", - "futures-core", - "http", - "http-body", - "http-body-util", - "mime", - "pin-project-lite", - "sync_wrapper", - "tower-layer", - "tower-service", - "tracing", -] - -[[package]] -name = "axum-macros" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "604fde5e028fea851ce1d8570bbdc034bec850d157f7569d10f347d06808c05c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "base64" -version = "0.21.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" - -[[package]] -name = "base64" -version = "0.22.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" - -[[package]] -name = "base64ct" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55248b47b0caf0546f7988906588779981c43bb1bc9d0c44087278f80cdb44ba" - -[[package]] -name = "bcrypt" -version = "0.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e65938ed058ef47d92cf8b346cc76ef48984572ade631927e9937b5ffc7662c7" -dependencies = [ - "base64 0.22.1", - "blowfish", - "getrandom 0.2.16", - "subtle", - "zeroize", -] - -[[package]] -name = "bigdecimal" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "560f42649de9fa436b73517378a147ec21f6c997a546581df4b4b31677828934" -dependencies = [ - "autocfg", - "libm", - "num-bigint", - "num-integer", - "num-traits", - "serde", -] - -[[package]] -name = "bitflags" -version = "2.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" -dependencies = [ - "serde_core", -] - -[[package]] -name = "block-buffer" -version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" -dependencies = [ - "generic-array", -] - -[[package]] -name = "blowfish" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e412e2cd0f2b2d93e02543ceae7917b3c70331573df19ee046bcbc35e45e87d7" -dependencies = [ - "byteorder", - "cipher", -] - -[[package]] -name = "bumpalo" -version = "3.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43" - -[[package]] -name = "byteorder" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" - -[[package]] -name = "bytes" -version = "1.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b35204fbdc0b3f4446b89fc1ac2cf84a8a68971995d0bf2e925ec7cd960f9cb3" - -[[package]] -name = "cc" -version = "1.2.46" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97463e1064cb1b1c1384ad0a0b9c8abd0988e2a91f52606c80ef14aadb63e36" -dependencies = [ - "find-msvc-tools", - "shlex", -] - -[[package]] -name = "cfg-if" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" - -[[package]] -name = "chrono" -version = "0.4.42" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "145052bdd345b87320e369255277e3fb5152762ad123a901ef5c262dd38fe8d2" -dependencies = [ - "iana-time-zone", - "js-sys", - "num-traits", - "serde", - "wasm-bindgen", - "windows-link", -] - -[[package]] -name = "cipher" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" -dependencies = [ - "crypto-common", - "inout", -] - -[[package]] -name = "concurrent-queue" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" -dependencies = [ - "crossbeam-utils", -] - -[[package]] -name = "config" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68578f196d2a33ff61b27fae256c3164f65e36382648e30666dde05b8cc9dfdf" -dependencies = [ - "async-trait", - "convert_case", - "json5", - "nom", - "pathdiff", - "ron", - "rust-ini", - "serde", - "serde_json", - "toml", - "yaml-rust2", -] - -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - -[[package]] -name = "const-random" -version = "0.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87e00182fe74b066627d63b85fd550ac2998d4b0bd86bfed477a0ae4c7c71359" -dependencies = [ - "const-random-macro", -] - -[[package]] -name = "const-random-macro" -version = "0.1.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9d839f2a20b0aee515dc581a6172f2321f96cab76c1a38a4c584a194955390e" -dependencies = [ - "getrandom 0.2.16", - "once_cell", - "tiny-keccak", -] - -[[package]] -name = "convert_case" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" -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.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - -[[package]] -name = "cpufeatures" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" -dependencies = [ - "libc", -] - -[[package]] -name = "crc" -version = "3.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9710d3b3739c2e349eb44fe848ad0b7c8cb1e42bd87ee49371df2f7acaf3e675" -dependencies = [ - "crc-catalog", -] - -[[package]] -name = "crc-catalog" -version = "2.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" - -[[package]] -name = "crossbeam-queue" -version = "0.3.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f58bbc28f91df819d0aa2a2c00cd19754769c2fad90579b3592b1c9ba7a3115" -dependencies = [ - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-utils" -version = "0.8.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" - -[[package]] -name = "crunchy" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" - -[[package]] -name = "crypto-common" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" -dependencies = [ - "generic-array", - "typenum", -] - -[[package]] -name = "der" -version = "0.7.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb" -dependencies = [ - "const-oid", - "pem-rfc7468", - "zeroize", -] - -[[package]] -name = "deranged" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ececcb659e7ba858fb4f10388c250a7252eb0a27373f1a72b8748afdd248e587" -dependencies = [ - "powerfmt", -] - -[[package]] -name = "digest" -version = "0.10.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" -dependencies = [ - "block-buffer", - "const-oid", - "crypto-common", - "subtle", -] - -[[package]] -name = "displaydoc" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "dlv-list" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "442039f5147480ba31067cb00ada1adae6892028e40e45fc5de7b7df6dcc1b5f" -dependencies = [ - "const-random", -] - -[[package]] -name = "dotenvy" -version = "0.15.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" - -[[package]] -name = "either" -version = "1.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" -dependencies = [ - "serde", -] - -[[package]] -name = "encoding_rs" -version = "0.8.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "equivalent" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" - -[[package]] -name = "errno" -version = "0.3.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" -dependencies = [ - "libc", - "windows-sys 0.61.2", -] - -[[package]] -name = "etcetera" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "136d1b5283a1ab77bd9257427ffd09d8667ced0570b6f938942bc7568ed5b943" -dependencies = [ - "cfg-if", - "home", - "windows-sys 0.48.0", -] - -[[package]] -name = "event-listener" -version = "5.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e13b66accf52311f30a0db42147dadea9850cb48cd070028831ae5f5d4b856ab" -dependencies = [ - "concurrent-queue", - "parking", - "pin-project-lite", -] - -[[package]] -name = "fastrand" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" - -[[package]] -name = "find-msvc-tools" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a3076410a55c90011c298b04d0cfa770b00fa04e1e3c97d3f6c9de105a03844" - -[[package]] -name = "flume" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0e4dd2a88388a1f4ccc7c9ce104604dab68d9f408dc34cd45823d5a9069095" -dependencies = [ - "futures-core", - "futures-sink", - "spin", -] - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "foldhash" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" - -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - -[[package]] -name = "form_urlencoded" -version = "1.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" -dependencies = [ - "percent-encoding", -] - -[[package]] -name = "futures-channel" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" - -[[package]] -name = "futures-executor" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-intrusive" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d930c203dd0b6ff06e0201a4a2fe9149b43c684fd4420555b26d21b1a02956f" -dependencies = [ - "futures-core", - "lock_api", - "parking_lot", -] - -[[package]] -name = "futures-io" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" - -[[package]] -name = "futures-sink" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" - -[[package]] -name = "futures-task" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" - -[[package]] -name = "futures-util" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" -dependencies = [ - "futures-core", - "futures-io", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", -] - -[[package]] -name = "getrandom" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" -dependencies = [ - "cfg-if", - "js-sys", - "libc", - "wasi", - "wasm-bindgen", -] - -[[package]] -name = "getrandom" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" -dependencies = [ - "cfg-if", - "libc", - "r-efi", - "wasip2", -] - -[[package]] -name = "h2" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3c0b69cfcb4e1b9f1bf2f53f95f766e4661169728ec61cd3fe5a0166f2d1386" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" -dependencies = [ - "ahash", - "allocator-api2", -] - -[[package]] -name = "hashbrown" -version = "0.15.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" -dependencies = [ - "allocator-api2", - "equivalent", - "foldhash", -] - -[[package]] -name = "hashbrown" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5419bdc4f6a9207fbeba6d11b604d481addf78ecd10c11ad51e76c2f6482748d" - -[[package]] -name = "hashlink" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8094feaf31ff591f651a2664fb9cfd92bba7a60ce3197265e9482ebe753c8f7" -dependencies = [ - "hashbrown 0.14.5", -] - -[[package]] -name = "hashlink" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7382cf6263419f2d8df38c55d7da83da5c18aef87fc7a7fc1fb1e344edfe14c1" -dependencies = [ - "hashbrown 0.15.5", -] - -[[package]] -name = "heck" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" - -[[package]] -name = "hex" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" - -[[package]] -name = "hkdf" -version = "0.12.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" -dependencies = [ - "hmac", -] - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - -[[package]] -name = "home" -version = "0.5.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc627f471c528ff0c4a49e1d5e60450c8f6461dd6d10ba9dcd3a61d3dff7728d" -dependencies = [ - "windows-sys 0.61.2", -] - -[[package]] -name = "http" -version = "1.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4a85d31aea989eead29a3aaf9e1115a180df8282431156e533de47660892565" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "http-body" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" -dependencies = [ - "bytes", - "http", -] - -[[package]] -name = "http-body-util" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a" -dependencies = [ - "bytes", - "futures-core", - "http", - "http-body", - "pin-project-lite", -] - -[[package]] -name = "http-range-header" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9171a2ea8a68358193d15dd5d70c1c10a2afc3e7e4c5bc92bc9f025cebd7359c" - -[[package]] -name = "httparse" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" - -[[package]] -name = "httpdate" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" - -[[package]] -name = "hyper" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ab2d4f250c3d7b1c9fcdff1cece94ea4e2dfbec68614f7b87cb205f24ca9d11" -dependencies = [ - "atomic-waker", - "bytes", - "futures-channel", - "futures-core", - "h2", - "http", - "http-body", - "httparse", - "httpdate", - "itoa", - "pin-project-lite", - "pin-utils", - "smallvec", - "tokio", - "want", -] - -[[package]] -name = "hyper-rustls" -version = "0.27.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3c93eb611681b207e1fe55d5a71ecf91572ec8a6705cdb6857f7d8d5242cf58" -dependencies = [ - "http", - "hyper", - "hyper-util", - "rustls", - "rustls-pki-types", - "tokio", - "tokio-rustls", - "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", -] - -[[package]] -name = "hyper-util" -version = "0.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52e9a2a24dc5c6821e71a7030e1e14b7b632acac55c40e9d2e082c621261bb56" -dependencies = [ - "base64 0.22.1", - "bytes", - "futures-channel", - "futures-core", - "futures-util", - "http", - "http-body", - "hyper", - "ipnet", - "libc", - "percent-encoding", - "pin-project-lite", - "socket2", - "system-configuration", - "tokio", - "tower-service", - "tracing", - "windows-registry", -] - -[[package]] -name = "iana-time-zone" -version = "0.1.64" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33e57f83510bb73707521ebaffa789ec8caf86f9657cad665b092b581d40e9fb" -dependencies = [ - "android_system_properties", - "core-foundation-sys", - "iana-time-zone-haiku", - "js-sys", - "log", - "wasm-bindgen", - "windows-core", -] - -[[package]] -name = "iana-time-zone-haiku" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" -dependencies = [ - "cc", -] - -[[package]] -name = "icu_collections" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c6b649701667bbe825c3b7e6388cb521c23d88644678e83c0c4d0a621a34b43" -dependencies = [ - "displaydoc", - "potential_utf", - "yoke", - "zerofrom", - "zerovec", -] - -[[package]] -name = "icu_locale_core" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edba7861004dd3714265b4db54a3c390e880ab658fec5f7db895fae2046b5bb6" -dependencies = [ - "displaydoc", - "litemap", - "tinystr", - "writeable", - "zerovec", -] - -[[package]] -name = "icu_normalizer" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f6c8828b67bf8908d82127b2054ea1b4427ff0230ee9141c54251934ab1b599" -dependencies = [ - "icu_collections", - "icu_normalizer_data", - "icu_properties", - "icu_provider", - "smallvec", - "zerovec", -] - -[[package]] -name = "icu_normalizer_data" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7aedcccd01fc5fe81e6b489c15b247b8b0690feb23304303a9e560f37efc560a" - -[[package]] -name = "icu_properties" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e93fcd3157766c0c8da2f8cff6ce651a31f0810eaa1c51ec363ef790bbb5fb99" -dependencies = [ - "icu_collections", - "icu_locale_core", - "icu_properties_data", - "icu_provider", - "zerotrie", - "zerovec", -] - -[[package]] -name = "icu_properties_data" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02845b3647bb045f1100ecd6480ff52f34c35f82d9880e029d329c21d1054899" - -[[package]] -name = "icu_provider" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85962cf0ce02e1e0a629cc34e7ca3e373ce20dda4c4d7294bbd0bf1fdb59e614" -dependencies = [ - "displaydoc", - "icu_locale_core", - "writeable", - "yoke", - "zerofrom", - "zerotrie", - "zerovec", -] - -[[package]] -name = "idna" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" -dependencies = [ - "idna_adapter", - "smallvec", - "utf8_iter", -] - -[[package]] -name = "idna_adapter" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3acae9609540aa318d1bc588455225fb2085b9ed0c4f6bd0d9d5bcd86f1a0344" -dependencies = [ - "icu_normalizer", - "icu_properties", -] - -[[package]] -name = "indexmap" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6717a8d2a5a929a1a2eb43a12812498ed141a0bcfb7e8f7844fbdbe4303bba9f" -dependencies = [ - "equivalent", - "hashbrown 0.16.0", -] - -[[package]] -name = "inout" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01" -dependencies = [ - "generic-array", -] - -[[package]] -name = "inventory" -version = "0.1.0" -dependencies = [ - "anyhow", - "axum", - "bigdecimal", - "chrono", - "config", - "dotenvy", - "serde", - "serde_json", - "sqlx", - "thiserror", - "tokio", - "tower", - "tower-http", - "uuid", -] - -[[package]] -name = "ipnet" -version = "2.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130" - -[[package]] -name = "iri-string" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f867b9d1d896b67beb18518eda36fdb77a32ea590de864f1325b294a6d14397" -dependencies = [ - "memchr", - "serde", -] - -[[package]] -name = "itoa" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" - -[[package]] -name = "js-sys" -version = "0.3.82" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b011eec8cc36da2aab2d5cff675ec18454fad408585853910a202391cf9f8e65" -dependencies = [ - "once_cell", - "wasm-bindgen", -] - -[[package]] -name = "json5" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96b0db21af676c1ce64250b5f40f3ce2cf27e4e47cb91ed91eb6fe9350b430c1" -dependencies = [ - "pest", - "pest_derive", - "serde", -] - -[[package]] -name = "jsonwebtoken" -version = "9.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a87cc7a48537badeae96744432de36f4be2b4a34a05a5ef32e9dd8a1c169dde" -dependencies = [ - "base64 0.22.1", - "js-sys", - "pem", - "ring", - "serde", - "serde_json", - "simple_asn1", -] - -[[package]] -name = "lazy_static" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" -dependencies = [ - "spin", -] - -[[package]] -name = "libc" -version = "0.2.177" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976" - -[[package]] -name = "libm" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de" - -[[package]] -name = "libredox" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "416f7e718bdb06000964960ffa43b4335ad4012ae8b99060261aa4a8088d5ccb" -dependencies = [ - "bitflags", - "libc", - "redox_syscall", -] - -[[package]] -name = "libsqlite3-sys" -version = "0.30.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e99fb7a497b1e3339bc746195567ed8d3e24945ecd636e3619d20b9de9e9149" -dependencies = [ - "pkg-config", - "vcpkg", -] - -[[package]] -name = "linux-raw-sys" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039" - -[[package]] -name = "litemap" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6373607a59f0be73a39b6fe456b8192fcc3585f602af20751600e974dd455e77" - -[[package]] -name = "lock_api" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" -dependencies = [ - "scopeguard", -] - -[[package]] -name = "log" -version = "0.4.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432" - -[[package]] -name = "matchit" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3" - -[[package]] -name = "md-5" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" -dependencies = [ - "cfg-if", - "digest", -] - -[[package]] -name = "memchr" -version = "2.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" - -[[package]] -name = "mime" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" - -[[package]] -name = "mime_guess" -version = "2.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e" -dependencies = [ - "mime", - "unicase", -] - -[[package]] -name = "minimal-lexical" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" - -[[package]] -name = "mio" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69d83b0086dc8ecf3ce9ae2874b2d1290252e2a30720bea58a5c6639b0092873" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.61.2", -] - -[[package]] -name = "native-tls" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87de3442987e9dbec73158d5c715e7ad9072fda936bb03d19d7fa10e00520f0e" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - -[[package]] -name = "nom" -version = "7.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" -dependencies = [ - "memchr", - "minimal-lexical", -] - -[[package]] -name = "num-bigint" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" -dependencies = [ - "num-integer", - "num-traits", -] - -[[package]] -name = "num-bigint-dig" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e661dda6640fad38e827a6d4a310ff4763082116fe217f279885c97f511bb0b7" -dependencies = [ - "lazy_static", - "libm", - "num-integer", - "num-iter", - "num-traits", - "rand", - "smallvec", - "zeroize", -] - -[[package]] -name = "num-conv" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" - -[[package]] -name = "num-integer" -version = "0.1.46" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" -dependencies = [ - "num-traits", -] - -[[package]] -name = "num-iter" -version = "0.1.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", -] - -[[package]] -name = "num-traits" -version = "0.2.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" -dependencies = [ - "autocfg", - "libm", -] - -[[package]] -name = "once_cell" -version = "1.21.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" - -[[package]] -name = "openssl" -version = "0.10.75" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08838db121398ad17ab8531ce9de97b244589089e290a384c900cb9ff7434328" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e" - -[[package]] -name = "openssl-sys" -version = "0.9.111" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82cab2d520aa75e3c58898289429321eb788c3106963d0dc886ec7a5f4adc321" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - -[[package]] -name = "ordered-multimap" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49203cdcae0030493bad186b28da2fa25645fa276a51b6fec8010d281e02ef79" -dependencies = [ - "dlv-list", - "hashbrown 0.14.5", -] - -[[package]] -name = "orders" -version = "0.1.0" -dependencies = [ - "anyhow", - "axum", - "bigdecimal", - "chrono", - "config", - "dotenvy", - "reqwest", - "serde", - "serde_json", - "sqlx", - "thiserror", - "tokio", - "tower", - "tower-http", - "uuid", -] - -[[package]] -name = "otelmart" -version = "0.1.0" -dependencies = [ - "anyhow", - "axum", - "bcrypt", - "chrono", - "config", - "dotenvy", - "jsonwebtoken", - "reqwest", - "serde", - "serde_json", - "sqlx", - "thiserror", - "tokio", - "tower", - "tower-http", - "urlencoding", - "uuid", -] - -[[package]] -name = "parking" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" - -[[package]] -name = "parking_lot" -version = "0.12.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-link", -] - -[[package]] -name = "pathdiff" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df94ce210e5bc13cb6651479fa48d14f601d9858cfe0467f43ae157023b938d3" - -[[package]] -name = "pem" -version = "3.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d30c53c26bc5b31a98cd02d20f25a7c8567146caf63ed593a9d87b2775291be" -dependencies = [ - "base64 0.22.1", - "serde_core", -] - -[[package]] -name = "pem-rfc7468" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" -dependencies = [ - "base64ct", -] - -[[package]] -name = "percent-encoding" -version = "2.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" - -[[package]] -name = "pest" -version = "2.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "989e7521a040efde50c3ab6bbadafbe15ab6dc042686926be59ac35d74607df4" -dependencies = [ - "memchr", - "ucd-trie", -] - -[[package]] -name = "pest_derive" -version = "2.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "187da9a3030dbafabbbfb20cb323b976dc7b7ce91fcd84f2f74d6e31d378e2de" -dependencies = [ - "pest", - "pest_generator", -] - -[[package]] -name = "pest_generator" -version = "2.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49b401d98f5757ebe97a26085998d6c0eecec4995cad6ab7fc30ffdf4b052843" -dependencies = [ - "pest", - "pest_meta", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "pest_meta" -version = "2.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72f27a2cfee9f9039c4d86faa5af122a0ac3851441a34865b8a043b46be0065a" -dependencies = [ - "pest", - "sha2", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "pkcs1" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8ffb9f10fa047879315e6625af03c164b16962a5368d724ed16323b68ace47f" -dependencies = [ - "der", - "pkcs8", - "spki", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - -[[package]] -name = "pkg-config" -version = "0.3.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" - -[[package]] -name = "potential_utf" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b73949432f5e2a09657003c25bca5e19a0e9c84f8058ca374f49e0ebe605af77" -dependencies = [ - "zerovec", -] - -[[package]] -name = "powerfmt" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" - -[[package]] -name = "ppv-lite86" -version = "0.2.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" -dependencies = [ - "zerocopy", -] - -[[package]] -name = "proc-macro2" -version = "1.0.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "products" -version = "0.1.0" -dependencies = [ - "anyhow", - "axum", - "bigdecimal", - "chrono", - "config", - "dotenvy", - "serde", - "serde_json", - "sqlx", - "thiserror", - "tokio", - "tower", - "tower-http", - "uuid", -] - -[[package]] -name = "quote" -version = "1.0.42" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "r-efi" -version = "5.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" - -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom 0.2.16", -] - -[[package]] -name = "redox_syscall" -version = "0.5.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" -dependencies = [ - "bitflags", -] - -[[package]] -name = "reqwest" -version = "0.12.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d0946410b9f7b082a427e4ef5c8ff541a88b357bc6c637c40db3a68ac70a36f" -dependencies = [ - "base64 0.22.1", - "bytes", - "encoding_rs", - "futures-core", - "h2", - "http", - "http-body", - "http-body-util", - "hyper", - "hyper-rustls", - "hyper-tls", - "hyper-util", - "js-sys", - "log", - "mime", - "native-tls", - "percent-encoding", - "pin-project-lite", - "rustls-pki-types", - "serde", - "serde_json", - "serde_urlencoded", - "sync_wrapper", - "tokio", - "tokio-native-tls", - "tower", - "tower-http", - "tower-service", - "url", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", -] - -[[package]] -name = "ring" -version = "0.17.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" -dependencies = [ - "cc", - "cfg-if", - "getrandom 0.2.16", - "libc", - "untrusted", - "windows-sys 0.52.0", -] - -[[package]] -name = "ron" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b91f7eff05f748767f183df4320a63d6936e9c6107d97c9e6bdd9784f4289c94" -dependencies = [ - "base64 0.21.7", - "bitflags", - "serde", - "serde_derive", -] - -[[package]] -name = "rsa" -version = "0.9.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40a0376c50d0358279d9d643e4bf7b7be212f1f4ff1da9070a7b54d22ef75c88" -dependencies = [ - "const-oid", - "digest", - "num-bigint-dig", - "num-integer", - "num-traits", - "pkcs1", - "pkcs8", - "rand_core", - "signature", - "spki", - "subtle", - "zeroize", -] - -[[package]] -name = "rust-ini" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e0698206bcb8882bf2a9ecb4c1e7785db57ff052297085a6efd4fe42302068a" -dependencies = [ - "cfg-if", - "ordered-multimap", -] - -[[package]] -name = "rustix" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd15f8a2c5551a84d56efdc1cd049089e409ac19a3072d5037a17fd70719ff3e" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.61.2", -] - -[[package]] -name = "rustls" -version = "0.23.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "533f54bc6a7d4f647e46ad909549eda97bf5afc1585190ef692b4286b198bd8f" -dependencies = [ - "once_cell", - "ring", - "rustls-pki-types", - "rustls-webpki", - "subtle", - "zeroize", -] - -[[package]] -name = "rustls-pki-types" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94182ad936a0c91c324cd46c6511b9510ed16af436d7b5bab34beab0afd55f7a" -dependencies = [ - "zeroize", -] - -[[package]] -name = "rustls-webpki" -version = "0.103.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ffdfa2f5286e2247234e03f680868ac2815974dc39e00ea15adc445d0aafe52" -dependencies = [ - "ring", - "rustls-pki-types", - "untrusted", -] - -[[package]] -name = "rustversion" -version = "1.0.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" - -[[package]] -name = "ryu" -version = "1.0.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" - -[[package]] -name = "schannel" -version = "0.1.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "891d81b926048e76efe18581bf793546b4c0eaf8448d72be8de2bbee5fd166e1" -dependencies = [ - "windows-sys 0.61.2", -] - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc1f0cbffaac4852523ce30d8bd3c5cdc873501d96ff467ca09b6767bb8cd5c0" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "serde" -version = "1.0.228" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" -dependencies = [ - "serde_core", - "serde_derive", -] - -[[package]] -name = "serde_core" -version = "1.0.228" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.228" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "serde_json" -version = "1.0.145" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "402a6f66d8c709116cf22f558eab210f5a50187f702eb4d7e5ef38d9a7f1c79c" -dependencies = [ - "itoa", - "memchr", - "ryu", - "serde", - "serde_core", -] - -[[package]] -name = "serde_path_to_error" -version = "0.1.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10a9ff822e371bb5403e391ecd83e182e0e77ba7f6fe0160b795797109d1b457" -dependencies = [ - "itoa", - "serde", - "serde_core", -] - -[[package]] -name = "serde_spanned" -version = "0.6.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf41e0cfaf7226dca15e8197172c295a782857fcb97fad1808a166870dee75a3" -dependencies = [ - "serde", -] - -[[package]] -name = "serde_urlencoded" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" -dependencies = [ - "form_urlencoded", - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "sha1" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "sha2" -version = "0.10.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "shlex" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" - -[[package]] -name = "signal-hook-registry" -version = "1.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2a4719bff48cee6b39d12c020eeb490953ad2443b7055bd0b21fca26bd8c28b" -dependencies = [ - "libc", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "simple_asn1" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "297f631f50729c8c99b84667867963997ec0b50f32b2a7dbcab828ef0541e8bb" -dependencies = [ - "num-bigint", - "num-traits", - "thiserror", - "time", -] - -[[package]] -name = "slab" -version = "0.4.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a2ae44ef20feb57a68b23d846850f861394c2e02dc425a50098ae8c90267589" - -[[package]] -name = "smallvec" -version = "1.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" -dependencies = [ - "serde", -] - -[[package]] -name = "socket2" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17129e116933cf371d018bb80ae557e889637989d8638274fb25622827b03881" -dependencies = [ - "libc", - "windows-sys 0.60.2", -] - -[[package]] -name = "spin" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" -dependencies = [ - "lock_api", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", -] - -[[package]] -name = "sqlx" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fefb893899429669dcdd979aff487bd78f4064e5e7907e4269081e0ef7d97dc" -dependencies = [ - "sqlx-core", - "sqlx-macros", - "sqlx-mysql", - "sqlx-postgres", - "sqlx-sqlite", -] - -[[package]] -name = "sqlx-core" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee6798b1838b6a0f69c007c133b8df5866302197e404e8b6ee8ed3e3a5e68dc6" -dependencies = [ - "base64 0.22.1", - "bigdecimal", - "bytes", - "chrono", - "crc", - "crossbeam-queue", - "either", - "event-listener", - "futures-core", - "futures-intrusive", - "futures-io", - "futures-util", - "hashbrown 0.15.5", - "hashlink 0.10.0", - "indexmap", - "log", - "memchr", - "once_cell", - "percent-encoding", - "rustls", - "serde", - "serde_json", - "sha2", - "smallvec", - "thiserror", - "tokio", - "tokio-stream", - "tracing", - "url", - "uuid", - "webpki-roots 0.26.11", -] - -[[package]] -name = "sqlx-macros" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2d452988ccaacfbf5e0bdbc348fb91d7c8af5bee192173ac3636b5fb6e6715d" -dependencies = [ - "proc-macro2", - "quote", - "sqlx-core", - "sqlx-macros-core", - "syn", -] - -[[package]] -name = "sqlx-macros-core" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19a9c1841124ac5a61741f96e1d9e2ec77424bf323962dd894bdb93f37d5219b" -dependencies = [ - "dotenvy", - "either", - "heck", - "hex", - "once_cell", - "proc-macro2", - "quote", - "serde", - "serde_json", - "sha2", - "sqlx-core", - "sqlx-mysql", - "sqlx-postgres", - "sqlx-sqlite", - "syn", - "tokio", - "url", -] - -[[package]] -name = "sqlx-mysql" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa003f0038df784eb8fecbbac13affe3da23b45194bd57dba231c8f48199c526" -dependencies = [ - "atoi", - "base64 0.22.1", - "bigdecimal", - "bitflags", - "byteorder", - "bytes", - "chrono", - "crc", - "digest", - "dotenvy", - "either", - "futures-channel", - "futures-core", - "futures-io", - "futures-util", - "generic-array", - "hex", - "hkdf", - "hmac", - "itoa", - "log", - "md-5", - "memchr", - "once_cell", - "percent-encoding", - "rand", - "rsa", - "serde", - "sha1", - "sha2", - "smallvec", - "sqlx-core", - "stringprep", - "thiserror", - "tracing", - "uuid", - "whoami", -] - -[[package]] -name = "sqlx-postgres" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db58fcd5a53cf07c184b154801ff91347e4c30d17a3562a635ff028ad5deda46" -dependencies = [ - "atoi", - "base64 0.22.1", - "bigdecimal", - "bitflags", - "byteorder", - "chrono", - "crc", - "dotenvy", - "etcetera", - "futures-channel", - "futures-core", - "futures-util", - "hex", - "hkdf", - "hmac", - "home", - "itoa", - "log", - "md-5", - "memchr", - "num-bigint", - "once_cell", - "rand", - "serde", - "serde_json", - "sha2", - "smallvec", - "sqlx-core", - "stringprep", - "thiserror", - "tracing", - "uuid", - "whoami", -] - -[[package]] -name = "sqlx-sqlite" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2d12fe70b2c1b4401038055f90f151b78208de1f9f89a7dbfd41587a10c3eea" -dependencies = [ - "atoi", - "chrono", - "flume", - "futures-channel", - "futures-core", - "futures-executor", - "futures-intrusive", - "futures-util", - "libsqlite3-sys", - "log", - "percent-encoding", - "serde", - "serde_urlencoded", - "sqlx-core", - "thiserror", - "tracing", - "url", - "uuid", -] - -[[package]] -name = "stable_deref_trait" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" - -[[package]] -name = "stringprep" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b4df3d392d81bd458a8a621b8bffbd2302a12ffe288a9d931670948749463b1" -dependencies = [ - "unicode-bidi", - "unicode-normalization", - "unicode-properties", -] - -[[package]] -name = "subtle" -version = "2.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" - -[[package]] -name = "syn" -version = "2.0.110" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a99801b5bd34ede4cf3fc688c5919368fea4e4814a4664359503e6015b280aea" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "sync_wrapper" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" -dependencies = [ - "futures-core", -] - -[[package]] -name = "synstructure" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "tempfile" -version = "3.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d31c77bdf42a745371d260a26ca7163f1e0924b64afa0b688e61b5a9fa02f16" -dependencies = [ - "fastrand", - "getrandom 0.3.4", - "once_cell", - "rustix", - "windows-sys 0.61.2", -] - -[[package]] -name = "thiserror" -version = "2.0.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f63587ca0f12b72a0600bcba1d40081f830876000bb46dd2337a3051618f4fc8" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "2.0.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "time" -version = "0.3.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e7d9e3bb61134e77bde20dd4825b97c010155709965fedf0f49bb138e52a9d" -dependencies = [ - "deranged", - "itoa", - "num-conv", - "powerfmt", - "serde", - "time-core", - "time-macros", -] - -[[package]] -name = "time-core" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40868e7c1d2f0b8d73e4a8c7f0ff63af4f6d19be117e90bd73eb1d62cf831c6b" - -[[package]] -name = "time-macros" -version = "0.2.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30cfb0125f12d9c277f35663a0a33f8c30190f4e4574868a330595412d34ebf3" -dependencies = [ - "num-conv", - "time-core", -] - -[[package]] -name = "tiny-keccak" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" -dependencies = [ - "crunchy", -] - -[[package]] -name = "tinystr" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42d3e9c45c09de15d06dd8acf5f4e0e399e85927b7f00711024eb7ae10fa4869" -dependencies = [ - "displaydoc", - "zerovec", -] - -[[package]] -name = "tinyvec" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa5fdc3bce6191a1dbc8c02d5c8bffcf557bafa17c124c5264a458f1b0613fa" -dependencies = [ - "tinyvec_macros", -] - -[[package]] -name = "tinyvec_macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" - -[[package]] -name = "tokio" -version = "1.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff360e02eab121e0bc37a2d3b4d4dc622e6eda3a8e5253d5435ecf5bd4c68408" -dependencies = [ - "bytes", - "libc", - "mio", - "parking_lot", - "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.61.2", -] - -[[package]] -name = "tokio-macros" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af407857209536a95c8e56f8231ef2c2e2aff839b22e07a1ffcbc617e9db9fa5" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - -[[package]] -name = "tokio-rustls" -version = "0.26.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1729aa945f29d91ba541258c8df89027d5792d85a8841fb65e8bf0f4ede4ef61" -dependencies = [ - "rustls", - "tokio", -] - -[[package]] -name = "tokio-stream" -version = "0.1.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eca58d7bba4a75707817a2c44174253f9236b2d5fbd055602e9d5c07c139a047" -dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", -] - -[[package]] -name = "tokio-util" -version = "0.7.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2efa149fe76073d6e8fd97ef4f4eca7b67f599660115591483572e406e165594" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - -[[package]] -name = "toml" -version = "0.8.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc1beb996b9d83529a9e75c17a1686767d148d70663143c7854d8b4a09ced362" -dependencies = [ - "serde", - "serde_spanned", - "toml_datetime", - "toml_edit", -] - -[[package]] -name = "toml_datetime" -version = "0.6.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c" -dependencies = [ - "serde", -] - -[[package]] -name = "toml_edit" -version = "0.22.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a" -dependencies = [ - "indexmap", - "serde", - "serde_spanned", - "toml_datetime", - "toml_write", - "winnow", -] - -[[package]] -name = "toml_write" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801" - -[[package]] -name = "tower" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d039ad9159c98b70ecfd540b2573b97f7f52c3e8d9f8ad57a24b916a536975f9" -dependencies = [ - "futures-core", - "futures-util", - "pin-project-lite", - "sync_wrapper", - "tokio", - "tower-layer", - "tower-service", - "tracing", -] - -[[package]] -name = "tower-http" -version = "0.6.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adc82fd73de2a9722ac5da747f12383d2bfdb93591ee6c58486e0097890f05f2" -dependencies = [ - "bitflags", - "bytes", - "futures-core", - "futures-util", - "http", - "http-body", - "http-body-util", - "http-range-header", - "httpdate", - "iri-string", - "mime", - "mime_guess", - "percent-encoding", - "pin-project-lite", - "tokio", - "tokio-util", - "tower", - "tower-layer", - "tower-service", - "tracing", -] - -[[package]] -name = "tower-layer" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" - -[[package]] -name = "tower-service" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" - -[[package]] -name = "tracing" -version = "0.1.41" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" -dependencies = [ - "log", - "pin-project-lite", - "tracing-attributes", - "tracing-core", -] - -[[package]] -name = "tracing-attributes" -version = "0.1.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81383ab64e72a7a8b8e13130c49e3dab29def6d0c7d76a03087b3cf71c5c6903" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "tracing-core" -version = "0.1.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9d12581f227e93f094d3af2ae690a574abb8a2b9b7a96e7cfe9647b2b617678" -dependencies = [ - "once_cell", -] - -[[package]] -name = "try-lock" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" - -[[package]] -name = "typenum" -version = "1.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" - -[[package]] -name = "ucd-trie" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971" - -[[package]] -name = "unicase" -version = "2.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75b844d17643ee918803943289730bec8aac480150456169e647ed0b576ba539" - -[[package]] -name = "unicode-bidi" -version = "0.3.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c1cb5db39152898a79168971543b1cb5020dff7fe43c8dc468b0885f5e29df5" - -[[package]] -name = "unicode-ident" -version = "1.0.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" - -[[package]] -name = "unicode-normalization" -version = "0.1.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fd4f6878c9cb28d874b009da9e8d183b5abc80117c40bbd187a1fde336be6e8" -dependencies = [ - "tinyvec", -] - -[[package]] -name = "unicode-properties" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7df058c713841ad818f1dc5d3fd88063241cc61f49f5fbea4b951e8cf5a8d71d" - -[[package]] -name = "unicode-segmentation" -version = "1.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" - -[[package]] -name = "untrusted" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" - -[[package]] -name = "url" -version = "2.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08bc136a29a3d1758e07a9cca267be308aeebf5cfd5a10f3f67ab2097683ef5b" -dependencies = [ - "form_urlencoded", - "idna", - "percent-encoding", - "serde", -] - -[[package]] -name = "urlencoding" -version = "2.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" - -[[package]] -name = "utf8_iter" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" - -[[package]] -name = "uuid" -version = "1.18.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f87b8aa10b915a06587d0dec516c282ff295b475d94abf425d62b57710070a2" -dependencies = [ - "getrandom 0.3.4", - "js-sys", - "serde", - "wasm-bindgen", -] - -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - -[[package]] -name = "version_check" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - -[[package]] -name = "want" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" -dependencies = [ - "try-lock", -] - -[[package]] -name = "wasi" -version = "0.11.1+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" - -[[package]] -name = "wasip2" -version = "1.0.1+wasi-0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7" -dependencies = [ - "wit-bindgen", -] - -[[package]] -name = "wasite" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b" - -[[package]] -name = "wasm-bindgen" -version = "0.2.105" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da95793dfc411fbbd93f5be7715b0578ec61fe87cb1a42b12eb625caa5c5ea60" -dependencies = [ - "cfg-if", - "once_cell", - "rustversion", - "wasm-bindgen-macro", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-futures" -version = "0.4.55" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "551f88106c6d5e7ccc7cd9a16f312dd3b5d36ea8b4954304657d5dfba115d4a0" -dependencies = [ - "cfg-if", - "js-sys", - "once_cell", - "wasm-bindgen", - "web-sys", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.105" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04264334509e04a7bf8690f2384ef5265f05143a4bff3889ab7a3269adab59c2" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.105" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "420bc339d9f322e562942d52e115d57e950d12d88983a14c79b86859ee6c7ebc" -dependencies = [ - "bumpalo", - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.105" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76f218a38c84bcb33c25ec7059b07847d465ce0e0a76b995e134a45adcb6af76" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "web-sys" -version = "0.3.82" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a1f95c0d03a47f4ae1f7a64643a6bb97465d9b740f0fa8f90ea33915c99a9a1" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - -[[package]] -name = "webpki-roots" -version = "0.26.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "521bc38abb08001b01866da9f51eb7c5d647a19260e00054a8c7fd5f9e57f7a9" -dependencies = [ - "webpki-roots 1.0.4", -] - -[[package]] -name = "webpki-roots" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2878ef029c47c6e8cf779119f20fcf52bde7ad42a731b2a304bc221df17571e" -dependencies = [ - "rustls-pki-types", -] - -[[package]] -name = "whoami" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d4a4db5077702ca3015d3d02d74974948aba2ad9e12ab7df718ee64ccd7e97d" -dependencies = [ - "libredox", - "wasite", -] - -[[package]] -name = "windows-core" -version = "0.62.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" -dependencies = [ - "windows-implement", - "windows-interface", - "windows-link", - "windows-result", - "windows-strings", -] - -[[package]] -name = "windows-implement" -version = "0.60.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "windows-interface" -version = "0.59.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "windows-link" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" - -[[package]] -name = "windows-registry" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02752bf7fbdcce7f2a27a742f798510f3e5ad88dbe84871e5168e2120c3d5720" -dependencies = [ - "windows-link", - "windows-result", - "windows-strings", -] - -[[package]] -name = "windows-result" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" -dependencies = [ - "windows-link", -] - -[[package]] -name = "windows-strings" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" -dependencies = [ - "windows-link", -] - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.6", -] - -[[package]] -name = "windows-sys" -version = "0.60.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" -dependencies = [ - "windows-targets 0.53.5", -] - -[[package]] -name = "windows-sys" -version = "0.61.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" -dependencies = [ - "windows-link", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" -dependencies = [ - "windows_aarch64_gnullvm 0.52.6", - "windows_aarch64_msvc 0.52.6", - "windows_i686_gnu 0.52.6", - "windows_i686_gnullvm 0.52.6", - "windows_i686_msvc 0.52.6", - "windows_x86_64_gnu 0.52.6", - "windows_x86_64_gnullvm 0.52.6", - "windows_x86_64_msvc 0.52.6", -] - -[[package]] -name = "windows-targets" -version = "0.53.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" -dependencies = [ - "windows-link", - "windows_aarch64_gnullvm 0.53.1", - "windows_aarch64_msvc 0.53.1", - "windows_i686_gnu 0.53.1", - "windows_i686_gnullvm 0.53.1", - "windows_i686_msvc 0.53.1", - "windows_x86_64_gnu 0.53.1", - "windows_x86_64_gnullvm 0.53.1", - "windows_x86_64_msvc 0.53.1", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" - -[[package]] -name = "windows_i686_gnu" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" - -[[package]] -name = "windows_i686_msvc" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" - -[[package]] -name = "winnow" -version = "0.7.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21a0236b59786fed61e2a80582dd500fe61f18b5dca67a4a067d0bc9039339cf" -dependencies = [ - "memchr", -] - -[[package]] -name = "wit-bindgen" -version = "0.46.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59" - -[[package]] -name = "writeable" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9" - -[[package]] -name = "yaml-rust2" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8902160c4e6f2fb145dbe9d6760a75e3c9522d8bf796ed7047c85919ac7115f8" -dependencies = [ - "arraydeque", - "encoding_rs", - "hashlink 0.8.4", -] - -[[package]] -name = "yoke" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72d6e5c6afb84d73944e5cedb052c4680d5657337201555f9f2a16b7406d4954" -dependencies = [ - "stable_deref_trait", - "yoke-derive", - "zerofrom", -] - -[[package]] -name = "yoke-derive" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b659052874eb698efe5b9e8cf382204678a0086ebf46982b79d6ca3182927e5d" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "synstructure", -] - -[[package]] -name = "zerocopy" -version = "0.8.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0894878a5fa3edfd6da3f88c4805f4c8558e2b996227a3d864f47fe11e38282c" -dependencies = [ - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.8.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88d2b8d9c68ad2b9e4340d7832716a4d21a22a1154777ad56ea55c51a9cf3831" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "zerofrom" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50cc42e0333e05660c3587f3bf9d0478688e15d870fab3346451ce7f8c9fbea5" -dependencies = [ - "zerofrom-derive", -] - -[[package]] -name = "zerofrom-derive" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "synstructure", -] - -[[package]] -name = "zeroize" -version = "1.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0" - -[[package]] -name = "zerotrie" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a59c17a5562d507e4b54960e8569ebee33bee890c70aa3fe7b97e85a9fd7851" -dependencies = [ - "displaydoc", - "yoke", - "zerofrom", -] - -[[package]] -name = "zerovec" -version = "0.11.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c28719294829477f525be0186d13efa9a3c602f7ec202ca9e353d310fb9a002" -dependencies = [ - "yoke", - "zerofrom", - "zerovec-derive", -] - -[[package]] -name = "zerovec-derive" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eadce39539ca5cb3985590102671f2567e659fca9666581ad3411d59207951f3" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] diff --git a/distributed_observability_in_rust/example_project/Cargo.toml b/distributed_observability_in_rust/example_project/Cargo.toml @@ -1,85 +0,0 @@ -[workspace] -resolver = "2" -members = [ - "otelmart", - "products", - "inventory", - "orders", -] - -[workspace.package] -version = "0.1.0" -edition = "2021" -authors = ["OpenTel Book Team"] -license = "MIT OR Apache-2.0" - -[workspace.lints.clippy] -# Pedantic lints for better code quality -pedantic = { level = "warn", priority = -1 } -# Allow some pedantic lints that are too noisy -module_name_repetitions = "allow" -missing_errors_doc = "allow" -missing_panics_doc = "allow" -must_use_candidate = "allow" - -# Style preferences -enum_glob_use = "warn" -unwrap_used = "warn" -expect_used = "warn" - -# Correctness -semicolon_if_nothing_returned = "warn" -inconsistent_struct_constructor = "warn" - -[workspace.dependencies] -# Web framework -axum = "0.8.7" -tokio = { version = "1.48.0", features = ["full"] } -tower = "0.5.2" -tower-http = { version = "0.6.6", features = ["cors"] } - -# Database -sqlx = { version = "0.8.6", features = ["runtime-tokio-rustls", "postgres", "chrono", "uuid", "json", "migrate", "bigdecimal"] } - -# Redis -redis = { version = "0.32.7", features = ["tokio-comp", "connection-manager"] } - -# Serialization -serde = { version = "1.0.228", features = ["derive"] } -serde_json = "1.0.145" - -# Utilities -chrono = { version = "0.4.42", features = ["serde"] } -uuid = { version = "1.18.1", features = ["v4", "serde"] } -rust_decimal = { version = "1.39.0", features = ["serde"] } -bigdecimal = { version = "0.4.9", features = ["serde"] } -anyhow = "1.0.100" -thiserror = "2.0.17" - -# Configuration -toml = "0.9.8" -config = "0.14" -dotenvy = "0.15" - -# HTTP client -reqwest = { version = "0.12.24", features = ["json"] } - -# Security -bcrypt = "0.15" -jsonwebtoken = "9" - -# URL encoding -urlencoding = "2" - -# Random number generation -rand = "0.9.2" - -[profile.release] -opt-level = 3 -lto = true -codegen-units = 1 -strip = true - -[profile.dev] -opt-level = 0 -debug = true diff --git a/distributed_observability_in_rust/example_project/docker-compose.yml b/distributed_observability_in_rust/example_project/docker-compose.yml @@ -1,165 +0,0 @@ -services: - # ============================================================ - # Database Service - # ============================================================ - # PostgreSQL with automatic schema initialization - postgres: - image: postgres:17-alpine - container_name: opentel-postgres - environment: - - POSTGRES_USER=opentel_user - - POSTGRES_PASSWORD=opentel_pass - - POSTGRES_DB=opentel_db - ports: - - "5433:5432" - volumes: - - postgres_data:/var/lib/postgresql/data - # Schema initialization scripts run automatically on first startup - - ./schemas/init:/docker-entrypoint-initdb.d - healthcheck: - test: ["CMD-SHELL", "pg_isready -U opentel_user -d opentel_db"] - interval: 10s - timeout: 5s - retries: 5 - start_period: 30s - networks: - - app-network - restart: unless-stopped - - # ============================================================ - # Products Service - # ============================================================ - # RESTful API for product catalog (runs migrations on startup) - products: - build: - context: . - dockerfile: products/Dockerfile - container_name: products-service - ports: - - "3001:3001" - environment: - - APP_DATABASE_URL=postgres://opentel_user:opentel_pass@postgres:5432/opentel_db - depends_on: - postgres: - condition: service_healthy - networks: - - app-network - restart: unless-stopped - - # ============================================================ - # Inventory Service - # ============================================================ - # RESTful API for inventory and pricing management (runs migrations on startup) - inventory: - build: - context: . - dockerfile: inventory/Dockerfile - container_name: inventory-service - ports: - - "3002:3002" - environment: - - APP_DATABASE_URL=postgres://opentel_user:opentel_pass@postgres:5432/opentel_db - depends_on: - postgres: - condition: service_healthy - networks: - - app-network - restart: unless-stopped - - # ============================================================ - # Orders Service - # ============================================================ - # RESTful API for order management, checkout, and shipment tracking (runs migrations on startup) - orders: - build: - context: . - dockerfile: orders/Dockerfile - container_name: orders-service - ports: - - "3003:3003" - environment: - - APP_DATABASE_URL=postgres://opentel_user:opentel_pass@postgres:5432/opentel_db - depends_on: - postgres: - condition: service_healthy - networks: - - app-network - restart: unless-stopped - - # ============================================================ - # Data Ingestion Service - # ============================================================ - # Loads initial data after products service runs migrations - # Note: Waits 10s after products starts to ensure migrations complete - data-ingestion: - build: - context: ./schemas - dockerfile: data/Dockerfile - container_name: data-ingestion - environment: - - DB_HOST=postgres - - DB_PORT=5432 - - DB_NAME=opentel_db - - DB_USER=opentel_user - - DB_PASSWORD=opentel_pass - - WAIT_TIME=10 - depends_on: - postgres: - condition: service_healthy - products: - condition: service_started - networks: - - app-network - restart: "no" # Run once and exit - - # ============================================================ - # OtelMart Service - # ============================================================ - # Main e-commerce application (Rust backend + Angular frontend) - otelmart: - build: - context: . - dockerfile: otelmart/Dockerfile - container_name: otelmart - ports: - - "4200:4200" - environment: - - APP_DATABASE__URL=postgres://opentel_user:opentel_pass@postgres:5432/opentel_db - - APP_SERVICES__PRODUCTS_HOST=products - - APP_SERVICES__PRODUCTS_PORT=3001 - - APP_SERVICES__INVENTORY_HOST=inventory - - APP_SERVICES__INVENTORY_PORT=3002 - - APP_SERVICES__ORDERS_HOST=orders - - APP_SERVICES__ORDERS_PORT=3003 - - APP_SERVICES__INVENTORY_SERVICE_URL=http://inventory:3002 - - APP_SERVICES__ORDERS_SERVICE_URL=http://orders:3003 - extra_hosts: - - "host.docker.internal:host-gateway" - depends_on: - postgres: - condition: service_healthy - data-ingestion: - condition: service_completed_successfully - products: - condition: service_started - inventory: - condition: service_started - orders: - condition: service_started - networks: - - app-network - restart: unless-stopped - -# ============================================================ -# Networks -# ============================================================ -networks: - app-network: - driver: bridge - -# ============================================================ -# Volumes -# ============================================================ -volumes: - postgres_data: - name: opentel_postgres_data diff --git a/distributed_observability_in_rust/example_project/inventory/Cargo.toml b/distributed_observability_in_rust/example_project/inventory/Cargo.toml @@ -1,35 +0,0 @@ -[package] -name = "inventory" -version.workspace = true -edition.workspace = true -authors.workspace = true - -[lints] -workspace = true - -[dependencies] -# Async runtime -tokio = { workspace = true } - -# Web framework -axum = { workspace = true } -tower = { workspace = true } -tower-http = { workspace = true } - -# Database -sqlx = { workspace = true } - -# Serialization -serde = { workspace = true } -serde_json = { workspace = true } - -# Utilities -uuid = { workspace = true } -chrono = { workspace = true } -anyhow = { workspace = true } -thiserror = { workspace = true } -bigdecimal = { workspace = true } - -# Configuration -config = { workspace = true } -dotenvy = { workspace = true } diff --git a/distributed_observability_in_rust/example_project/inventory/src/handlers/inventory.rs b/distributed_observability_in_rust/example_project/inventory/src/handlers/inventory.rs @@ -1,319 +0,0 @@ -//! Inventory/stock management API handlers -//! -//! This module contains the HTTP request handlers for inventory-related endpoints. - -use axum::{ - extract::{Path, Query, State}, - http::StatusCode, - response::{IntoResponse, Json}, -}; -use sqlx::{PgPool, Postgres, QueryBuilder, Row}; -use uuid::Uuid; - -use crate::models::{ - ConfirmSaleRequest, InventoryQueryParams, InventoryResponse, InventoryWithPricing, - ReleaseStockRequest, ReserveStockRequest, StockOperationResponse, UpdateStockRequest, -}; -use crate::utils::{calculate_pagination, calculate_total_pages, internal_error, not_found_error}; - -/// List inventory with pagination and filtering -/// -/// # Endpoint -/// `GET /inventory` -/// -/// # Query Parameters -/// - `page` (default: 1) - Page number (1-indexed) -/// - `page_size` (default: 20, max: 100) - Items per page -/// - `stock_status` - Filter by status ('in_stock', 'low_stock', 'out_of_stock') -/// - `product_uuid` - Filter by specific product -/// - `min_stock` / `max_stock` - Filter by available quantity range -pub async fn list_inventory( - State(pool): State<PgPool>, - Query(params): Query<InventoryQueryParams>, -) -> impl IntoResponse { - // Apply pagination defaults and constraints - let (page, page_size, offset) = calculate_pagination(params.page, params.page_size); - - // Build count query with QueryBuilder for safe parameter binding - let mut count_builder: QueryBuilder<Postgres> = - QueryBuilder::new("SELECT COUNT(*) FROM v_product_inventory_pricing"); - - let mut has_filters = false; - - // Apply filters to count query - if let Some(ref status) = params.stock_status { - count_builder.push(if has_filters { " AND " } else { " WHERE " }); - has_filters = true; - count_builder.push("stock_status = "); - count_builder.push_bind(status); - } - - if let Some(product_uuid) = params.product_uuid { - count_builder.push(if has_filters { " AND " } else { " WHERE " }); - has_filters = true; - count_builder.push("product_uuid = "); - count_builder.push_bind(product_uuid); - } - - if let Some(min_stock) = params.min_stock { - count_builder.push(if has_filters { " AND " } else { " WHERE " }); - has_filters = true; - count_builder.push("available_quantity >= "); - count_builder.push_bind(min_stock); - } - - if let Some(max_stock) = params.max_stock { - count_builder.push(if has_filters { " AND " } else { " WHERE " }); - count_builder.push("available_quantity <= "); - count_builder.push_bind(max_stock); - } - - // Execute count query - let total_count: i64 = match count_builder.build_query_scalar().fetch_one(&pool).await { - Ok(count) => count, - Err(e) => { - return internal_error("Failed to count inventory", e.to_string()); - } - }; - - // Build main query with same filters - let mut query_builder: QueryBuilder<Postgres> = - QueryBuilder::new("SELECT * FROM v_product_inventory_pricing"); - - let mut has_filters = false; - - // Apply same filters to main query - if let Some(ref status) = params.stock_status { - query_builder.push(if has_filters { " AND " } else { " WHERE " }); - has_filters = true; - query_builder.push("stock_status = "); - query_builder.push_bind(status); - } - - if let Some(product_uuid) = params.product_uuid { - query_builder.push(if has_filters { " AND " } else { " WHERE " }); - has_filters = true; - query_builder.push("product_uuid = "); - query_builder.push_bind(product_uuid); - } - - if let Some(min_stock) = params.min_stock { - query_builder.push(if has_filters { " AND " } else { " WHERE " }); - has_filters = true; - query_builder.push("available_quantity >= "); - query_builder.push_bind(min_stock); - } - - if let Some(max_stock) = params.max_stock { - query_builder.push(if has_filters { " AND " } else { " WHERE " }); - query_builder.push("available_quantity <= "); - query_builder.push_bind(max_stock); - } - - // Add ordering and pagination - query_builder.push(" ORDER BY stock_status DESC, available_quantity ASC LIMIT "); - query_builder.push_bind(page_size); - query_builder.push(" OFFSET "); - query_builder.push_bind(offset); - - // Execute main query - let inventory: Vec<InventoryWithPricing> = - match query_builder.build_query_as().fetch_all(&pool).await { - Ok(inventory) => inventory, - Err(e) => { - return internal_error("Failed to fetch inventory", e.to_string()); - } - }; - - let total_pages = calculate_total_pages(total_count, page_size); - - let response = InventoryResponse { - inventory, - total_count, - page, - page_size, - total_pages, - }; - - (StatusCode::OK, Json(response)).into_response() -} - -/// Get inventory for a specific product by UUID -/// -/// # Endpoint -/// `GET /inventory/{product_uuid}` -pub async fn get_inventory_by_product( - State(pool): State<PgPool>, - Path(product_uuid): Path<Uuid>, -) -> impl IntoResponse { - let result = sqlx::query_as::<_, InventoryWithPricing>( - r#" - SELECT * FROM v_product_inventory_pricing - WHERE product_uuid = $1 - "#, - ) - .bind(product_uuid) - .fetch_optional(&pool) - .await; - - match result { - Ok(Some(inventory)) => (StatusCode::OK, Json(inventory)).into_response(), - Ok(None) => not_found_error( - "Inventory not found for product", - serde_json::json!({"product_uuid": product_uuid.to_string()}), - ), - Err(e) => internal_error("Failed to fetch inventory", e.to_string()), - } -} - -/// Update stock quantity for a product -/// -/// # Endpoint -/// `PUT /inventory/{product_uuid}` -pub async fn update_stock( - State(pool): State<PgPool>, - Path(product_uuid): Path<Uuid>, - Json(request): Json<UpdateStockRequest>, -) -> impl IntoResponse { - let result = sqlx::query( - r#" - UPDATE product_inventory - SET stock_quantity = $1, - reorder_level = COALESCE($2, reorder_level), - reorder_quantity = COALESCE($3, reorder_quantity), - last_restocked_at = CURRENT_TIMESTAMP - WHERE product_uuid = $4 - RETURNING available_quantity - "#, - ) - .bind(request.quantity) - .bind(request.reorder_level) - .bind(request.reorder_quantity) - .bind(product_uuid) - .fetch_optional(&pool) - .await; - - match result { - Ok(Some(row)) => { - let available_quantity: Option<i32> = row.get("available_quantity"); - ( - StatusCode::OK, - Json(StockOperationResponse { - success: true, - message: "Stock updated successfully".to_string(), - product_uuid, - available_quantity, - }), - ) - .into_response() - } - Ok(None) => not_found_error( - "Product not found in inventory", - serde_json::json!({"product_uuid": product_uuid.to_string()}), - ), - Err(e) => internal_error("Failed to update stock", e.to_string()), - } -} - -/// Reserve stock for an order -/// -/// # Endpoint -/// `POST /inventory/reserve` -pub async fn reserve_stock( - State(pool): State<PgPool>, - Json(request): Json<ReserveStockRequest>, -) -> impl IntoResponse { - let result = sqlx::query_scalar::<_, bool>(r#"SELECT reserve_stock($1, $2)"#) - .bind(request.product_uuid) - .bind(request.quantity) - .fetch_one(&pool) - .await; - - match result { - Ok(success) => { - if success { - ( - StatusCode::OK, - Json(StockOperationResponse { - success: true, - message: format!("Reserved {} units", request.quantity), - product_uuid: request.product_uuid, - available_quantity: None, - }), - ) - .into_response() - } else { - ( - StatusCode::CONFLICT, - Json(StockOperationResponse { - success: false, - message: "Insufficient stock available".to_string(), - product_uuid: request.product_uuid, - available_quantity: None, - }), - ) - .into_response() - } - } - Err(e) => internal_error("Failed to reserve stock", e.to_string()), - } -} - -/// Release reserved stock -/// -/// # Endpoint -/// `POST /inventory/release` -pub async fn release_stock( - State(pool): State<PgPool>, - Json(request): Json<ReleaseStockRequest>, -) -> impl IntoResponse { - let result = sqlx::query(r#"SELECT release_stock($1, $2)"#) - .bind(request.product_uuid) - .bind(request.quantity) - .execute(&pool) - .await; - - match result { - Ok(_) => ( - StatusCode::OK, - Json(StockOperationResponse { - success: true, - message: format!("Released {} units", request.quantity), - product_uuid: request.product_uuid, - available_quantity: None, - }), - ) - .into_response(), - Err(e) => internal_error("Failed to release stock", e.to_string()), - } -} - -/// Confirm a sale and decrease stock -/// -/// # Endpoint -/// `POST /inventory/confirm-sale` -pub async fn confirm_sale( - State(pool): State<PgPool>, - Json(request): Json<ConfirmSaleRequest>, -) -> impl IntoResponse { - let result = sqlx::query(r#"SELECT confirm_stock_sale($1, $2, $3)"#) - .bind(request.product_uuid) - .bind(request.quantity) - .bind(request.order_uuid) - .execute(&pool) - .await; - - match result { - Ok(_) => ( - StatusCode::OK, - Json(StockOperationResponse { - success: true, - message: format!("Confirmed sale of {} units", request.quantity), - product_uuid: request.product_uuid, - available_quantity: None, - }), - ) - .into_response(), - Err(e) => internal_error("Failed to confirm sale", e.to_string()), - } -} diff --git a/distributed_observability_in_rust/example_project/inventory/src/handlers/pricing.rs b/distributed_observability_in_rust/example_project/inventory/src/handlers/pricing.rs @@ -1,214 +0,0 @@ -//! Pricing API handlers -//! -//! This module contains the HTTP request handlers for pricing-related endpoints. - -use axum::{ - extract::{Path, Query, State}, - http::StatusCode, - response::{IntoResponse, Json}, -}; -use sqlx::{PgPool, QueryBuilder, Postgres}; -use uuid::Uuid; - -use crate::models::{ - PricingQueryParams, PricingResponse, ProductPricing, UpdatePricingRequest, -}; -use crate::utils::{calculate_pagination, calculate_total_pages, internal_error, not_found_error}; - -/// List pricing with pagination and filtering -/// -/// # Endpoint -/// `GET /pricing` -/// -/// # Query Parameters -/// - `page` (default: 1) - Page number (1-indexed) -/// - `page_size` (default: 20, max: 100) - Items per page -/// - `product_uuid` - Filter by specific product -/// - `min_price` / `max_price` - Filter by price range -/// - `has_discount` - Filter by discount presence -pub async fn list_pricing( - State(pool): State<PgPool>, - Query(params): Query<PricingQueryParams>, -) -> impl IntoResponse { - // Apply pagination defaults and constraints - let (page, page_size, offset) = calculate_pagination(params.page, params.page_size); - - // Build count query with QueryBuilder for safe parameter binding - let mut count_builder: QueryBuilder<Postgres> = QueryBuilder::new( - "SELECT COUNT(*) FROM product_pricing WHERE is_active = true" - ); - - // Apply filters to count query (all use AND since WHERE is_active is already present) - if let Some(product_uuid) = params.product_uuid { - count_builder.push(" AND product_uuid = "); - count_builder.push_bind(product_uuid); - } - - if let Some(ref min_price) = params.min_price { - count_builder.push(" AND final_price >= "); - count_builder.push_bind(min_price); - } - - if let Some(ref max_price) = params.max_price { - count_builder.push(" AND final_price <= "); - count_builder.push_bind(max_price); - } - - if let Some(has_discount) = params.has_discount { - if has_discount { - count_builder.push(" AND discount_percentage > 0"); - } else { - count_builder.push(" AND (discount_percentage IS NULL OR discount_percentage = 0)"); - } - } - - // Execute count query - let total_count: i64 = match count_builder.build_query_scalar().fetch_one(&pool).await { - Ok(count) => count, - Err(e) => { - return internal_error("Failed to count pricing", e.to_string()); - } - }; - - // Build main query with same filters - let mut query_builder: QueryBuilder<Postgres> = QueryBuilder::new( - "SELECT * FROM product_pricing WHERE is_active = true" - ); - - // Apply same filters to main query (all use AND since WHERE is_active is already present) - if let Some(product_uuid) = params.product_uuid { - query_builder.push(" AND product_uuid = "); - query_builder.push_bind(product_uuid); - } - - if let Some(ref min_price) = params.min_price { - query_builder.push(" AND final_price >= "); - query_builder.push_bind(min_price); - } - - if let Some(ref max_price) = params.max_price { - query_builder.push(" AND final_price <= "); - query_builder.push_bind(max_price); - } - - if let Some(has_discount) = params.has_discount { - if has_discount { - query_builder.push(" AND discount_percentage > 0"); - } else { - query_builder.push(" AND (discount_percentage IS NULL OR discount_percentage = 0)"); - } - } - - // Add ordering and pagination - query_builder.push(" ORDER BY updated_at DESC LIMIT "); - query_builder.push_bind(page_size); - query_builder.push(" OFFSET "); - query_builder.push_bind(offset); - - // Execute main query - let pricing: Vec<ProductPricing> = match query_builder - .build_query_as() - .fetch_all(&pool) - .await - { - Ok(pricing) => pricing, - Err(e) => { - return internal_error("Failed to fetch pricing", e.to_string()); - } - }; - - let total_pages = calculate_total_pages(total_count, page_size); - - let response = PricingResponse { - pricing, - total_count, - page, - page_size, - total_pages, - }; - - (StatusCode::OK, Json(response)).into_response() -} - -/// Get pricing for a specific product by UUID -/// -/// # Endpoint -/// `GET /pricing/{product_uuid}` -pub async fn get_pricing_by_product( - State(pool): State<PgPool>, - Path(product_uuid): Path<Uuid>, -) -> impl IntoResponse { - let result = sqlx::query_as::<_, ProductPricing>( - r#" - SELECT * FROM product_pricing - WHERE product_uuid = $1 AND is_active = true - "#, - ) - .bind(product_uuid) - .fetch_optional(&pool) - .await; - - match result { - Ok(Some(pricing)) => (StatusCode::OK, Json(pricing)).into_response(), - Ok(None) => not_found_error( - "Pricing not found for product", - serde_json::json!({"product_uuid": product_uuid.to_string()}), - ), - Err(e) => internal_error("Failed to fetch pricing", e.to_string()), - } -} - -/// Create or update pricing for a product -/// -/// # Endpoint -/// `PUT /pricing/{product_uuid}` -pub async fn upsert_pricing( - State(pool): State<PgPool>, - Path(product_uuid): Path<Uuid>, - Json(request): Json<UpdatePricingRequest>, -) -> impl IntoResponse { - // First, deactivate existing active pricing - if let Err(e) = sqlx::query( - r#" - UPDATE product_pricing - SET is_active = false - WHERE product_uuid = $1 AND is_active = true - "#, - ) - .bind(product_uuid) - .execute(&pool) - .await - { - eprintln!("Error deactivating old pricing: {}", e); - } - - // Insert new pricing - let result = sqlx::query_as::<_, ProductPricing>( - r#" - INSERT INTO product_pricing ( - product_uuid, - final_price, - initial_price, - currency, - price_valid_from, - price_valid_until, - is_active - ) - VALUES ($1, $2, $3, $4, $5, $6, true) - RETURNING * - "#, - ) - .bind(product_uuid) - .bind(request.final_price) - .bind(request.initial_price) - .bind(request.currency.unwrap_or_else(|| "USD".to_string())) - .bind(request.price_valid_from) - .bind(request.price_valid_until) - .fetch_one(&pool) - .await; - - match result { - Ok(pricing) => (StatusCode::OK, Json(pricing)).into_response(), - Err(e) => internal_error("Failed to update pricing", e.to_string()), - } -} diff --git a/distributed_observability_in_rust/example_project/inventory/src/main.rs b/distributed_observability_in_rust/example_project/inventory/src/main.rs @@ -1,110 +0,0 @@ -//! Inventory Service -//! -//! A microservice for managing product inventory, stock levels, and pricing. -//! -//! # Features -//! - Product inventory management (stock levels, reservations) -//! - Pricing management with discounts -//! - Stock reservation for orders -//! - Inventory transaction audit trail -//! - PostgreSQL database with inventory schema -//! - CORS enabled for web client access -//! -//! # API Endpoints -//! ## Inventory -//! - `GET /inventory` - List inventory with filters and pagination -//! - `GET /inventory/{product_uuid}` - Get inventory for a specific product -//! - `PUT /inventory/{product_uuid}` - Update stock quantity -//! - `POST /inventory/reserve` - Reserve stock for an order -//! - `POST /inventory/release` - Release reserved stock -//! - `POST /inventory/confirm-sale` - Confirm sale and decrease stock -//! -//! ## Pricing -//! - `GET /pricing` - List pricing with filters and pagination -//! - `GET /pricing/{product_uuid}` - Get pricing for a specific product -//! - `PUT /pricing/{product_uuid}` - Create or update pricing -//! -//! # Configuration -//! The service is configured via: -//! - Environment variables (loaded from .env if present) -//! - config.toml file -//! -//! # Database -//! Uses the `inventory` schema in PostgreSQL with automatic search path configuration. -//! Migrations are run automatically on startup. - -mod config; -mod db; -mod handlers; -mod models; -mod utils; - -use anyhow::Result; -use axum::{ - routing::{get, post, put}, - Router, -}; -use std::net::SocketAddr; -use tower_http::cors::CorsLayer; - -use config::Config; -use db::Database; - -#[tokio::main] -async fn main() -> Result<()> { - // Load environment variables from .env file if present - dotenvy::dotenv().ok(); - - // Load configuration from config.toml - let config = Config::load()?; - - // Print startup information - println!("Starting Inventory Service..."); - println!("Server port: {}", config.server.port); - println!("Database URL: {}", config.database.url); - - // Initialize database connection pool - let db = Database::new(&config.database.url, config.database.max_connections).await?; - - // Build the application router with all endpoints - let app = Router::new() - // Inventory endpoints - .route("/inventory", get(handlers::list_inventory)) - .route("/inventory/{product_uuid}", get(handlers::get_inventory_by_product)) - .route("/inventory/{product_uuid}", put(handlers::update_stock)) - .route("/inventory/reserve", post(handlers::reserve_stock)) - .route("/inventory/release", post(handlers::release_stock)) - .route("/inventory/confirm-sale", post(handlers::confirm_sale)) - // Pricing endpoints - .route("/pricing", get(handlers::list_pricing)) - .route("/pricing/{product_uuid}", get(handlers::get_pricing_by_product)) - .route("/pricing/{product_uuid}", put(handlers::upsert_pricing)) - // Enable CORS for all routes - .layer(CorsLayer::permissive()) - // Add database pool to application state - .with_state(db.pool().clone()); - - // Create socket address from configuration - let addr = SocketAddr::from(([0, 0, 0, 0], config.server.port)); - - // Print API documentation - println!("\nInventory Service listening on {}", addr); - println!("\nAvailable endpoints:"); - println!(" Inventory:"); - println!(" GET /inventory - List inventory (with pagination & filters)"); - println!(" GET /inventory/{{product_uuid}} - Get inventory for product"); - println!(" PUT /inventory/{{product_uuid}} - Update stock quantity"); - println!(" POST /inventory/reserve - Reserve stock for order"); - println!(" POST /inventory/release - Release reserved stock"); - println!(" POST /inventory/confirm-sale - Confirm sale and decrease stock"); - println!(" Pricing:"); - println!(" GET /pricing - List pricing (with pagination & filters)"); - println!(" GET /pricing/{{product_uuid}} - Get pricing for product"); - println!(" PUT /pricing/{{product_uuid}} - Create or update pricing"); - - // Start the HTTP server - let listener = tokio::net::TcpListener::bind(addr).await?; - axum::serve(listener, app).await?; - - Ok(()) -} diff --git a/distributed_observability_in_rust/example_project/orders/Cargo.toml b/distributed_observability_in_rust/example_project/orders/Cargo.toml @@ -1,38 +0,0 @@ -[package] -name = "orders" -version.workspace = true -edition.workspace = true -authors.workspace = true - -[lints] -workspace = true - -[dependencies] -# Async runtime -tokio = { workspace = true } - -# Web framework -axum = { workspace = true } -tower = { workspace = true } -tower-http = { workspace = true } - -# Database -sqlx = { workspace = true } - -# Serialization -serde = { workspace = true } -serde_json = { workspace = true } - -# Utilities -uuid = { workspace = true } -chrono = { workspace = true } -anyhow = { workspace = true } -thiserror = { workspace = true } -bigdecimal = { workspace = true } - -# Configuration -config = { workspace = true } -dotenvy = { workspace = true } - -# HTTP client -reqwest = { workspace = true } diff --git a/distributed_observability_in_rust/example_project/orders/src/handlers/orders.rs b/distributed_observability_in_rust/example_project/orders/src/handlers/orders.rs @@ -1,913 +0,0 @@ -//! Order management API handlers - -use axum::{ - extract::{Path, Query, State}, - http::StatusCode, - response::{IntoResponse, Json}, -}; -use bigdecimal::BigDecimal; -use sqlx::{PgPool, Row}; -use uuid::Uuid; - -use crate::models::{CreateOrderRequest, OrderComplete, OrderQueryParams, OrdersResponse}; -use crate::AppState; - -/// Product detail response from products service -#[derive(Debug, serde::Deserialize)] -struct ProductDetail { - product_name: String, - final_price: BigDecimal, - is_active: bool, -} - -/// Request to reserve stock in inventory service -#[derive(Debug, serde::Serialize)] -struct ReserveStockRequest { - product_uuid: Uuid, - quantity: i32, -} - -/// Request to release reserved stock in inventory service -#[derive(Debug, serde::Serialize)] -struct ReleaseStockRequest { - product_uuid: Uuid, - quantity: i32, -} - -/// Request to confirm sale in inventory service -#[derive(Debug, serde::Serialize)] -struct ConfirmSaleRequest { - product_uuid: Uuid, - quantity: i32, - order_uuid: Uuid, -} - -/// Response from inventory stock operations -#[derive(Debug, serde::Deserialize)] -struct StockOperationResponse { - success: bool, - message: String, - available_quantity: Option<i32>, -} - -/// Release reserved stock for a product in the inventory service -/// -/// Calls the inventory service to release previously reserved stock. -/// Used for rollback when order creation fails. -async fn release_stock(state: &AppState, product_uuid: Uuid, quantity: i32) { - let url = format!("{}/inventory/release", state.inventory_service_url()); - - let request_body = ReleaseStockRequest { - product_uuid, - quantity, - }; - - let response = state - .http_client() - .post(&url) - .json(&request_body) - .send() - .await; - - match response { - Ok(resp) => { - if resp.status().is_success() { - eprintln!( - "Successfully released {} units of stock for product {}", - quantity, product_uuid - ); - } else { - eprintln!( - "Failed to release stock for product {}: status {}", - product_uuid, - resp.status() - ); - } - } - Err(e) => { - eprintln!( - "Error calling inventory service to release stock for product {}: {}", - product_uuid, e - ); - } - } -} - -/// Release all reserved stock (for rollback scenarios) -/// -/// Iterates through all reserved items and releases their stock. -/// Logs errors but doesn't fail - this is a best-effort cleanup. -async fn release_all_reserved_stock(state: &AppState, reserved_items: &[(Uuid, i32)]) { - if reserved_items.is_empty() { - return; - } - - eprintln!( - "Rolling back stock reservations for {} items", - reserved_items.len() - ); - - for (product_uuid, quantity) in reserved_items { - release_stock(state, *product_uuid, *quantity).await; - } -} - -/// Confirm a sale with the inventory service -/// -/// Calls the inventory service to confirm the sale and convert reserved stock to sold. -/// This is called after an order is successfully created and committed. -async fn confirm_sale( - state: &AppState, - product_uuid: Uuid, - quantity: i32, - order_uuid: Uuid, -) -> Result<(), String> { - let url = format!("{}/inventory/confirm-sale", state.inventory_service_url()); - - let request_body = ConfirmSaleRequest { - product_uuid, - quantity, - order_uuid, - }; - - let response = state - .http_client() - .post(&url) - .json(&request_body) - .send() - .await - .map_err(|e| format!("Failed to call inventory service: {}", e))?; - - if response.status().is_success() { - Ok(()) - } else { - Err(format!( - "Inventory service returned error status: {}", - response.status() - )) - } -} - -/// Confirm all sales for order items -/// -/// Iterates through all order items and confirms the sale with inventory service. -/// Logs errors but doesn't fail the order since it's already committed. -async fn confirm_all_sales(state: &AppState, order_uuid: Uuid, items: &[(Uuid, i32)]) { - if items.is_empty() { - return; - } - - println!( - "Confirming sales with inventory service for {} items in order {}", - items.len(), - order_uuid - ); - - for (product_uuid, quantity) in items { - match confirm_sale(state, *product_uuid, *quantity, order_uuid).await { - Ok(_) => { - println!( - "Successfully confirmed sale of {} units for product {} in order {}", - quantity, product_uuid, order_uuid - ); - } - Err(e) => { - // Log error but don't fail - order is already committed - eprintln!( - "Failed to confirm sale for product {} in order {}: {}", - product_uuid, order_uuid, e - ); - eprintln!("WARNING: Stock reservation remains in place. Manual intervention may be required."); - } - } - } -} - -/// Reserve stock for a product in the inventory service -/// -/// Calls the inventory service to reserve stock for an order. -/// Returns error if insufficient stock is available. -async fn reserve_stock( - state: &AppState, - product_uuid: Uuid, - quantity: i32, -) -> Result<StockOperationResponse, axum::response::Response> { - let url = format!("{}/inventory/reserve", state.inventory_service_url()); - - let request_body = ReserveStockRequest { - product_uuid, - quantity, - }; - - let response = match state - .http_client() - .post(&url) - .json(&request_body) - .send() - .await - { - Ok(resp) => resp, - Err(e) => { - eprintln!("Failed to call inventory service: {}", e); - return Err(( - StatusCode::SERVICE_UNAVAILABLE, - Json(serde_json::json!({ - "error": "Inventory service unavailable", - "details": e.to_string() - })), - ) - .into_response()); - } - }; - - match response.status() { - reqwest::StatusCode::OK => { - let stock_response: StockOperationResponse = match response.json().await { - Ok(r) => r, - Err(e) => { - eprintln!("Failed to parse inventory response: {}", e); - return Err(( - StatusCode::INTERNAL_SERVER_ERROR, - Json(serde_json::json!({ - "error": "Failed to parse inventory response", - "details": e.to_string() - })), - ) - .into_response()); - } - }; - - if !stock_response.success { - return Err(( - StatusCode::CONFLICT, - Json(serde_json::json!({ - "error": "Insufficient stock", - "product_uuid": product_uuid.to_string(), - "requested_quantity": quantity, - "available_quantity": stock_response.available_quantity, - "message": stock_response.message - })), - ) - .into_response()); - } - - Ok(stock_response) - } - reqwest::StatusCode::CONFLICT => { - // Inventory service returned 409 - insufficient stock - let error_response: serde_json::Value = response.json().await.unwrap_or_else(|_| { - serde_json::json!({ - "error": "Insufficient stock", - "product_uuid": product_uuid.to_string() - }) - }); - - Err((StatusCode::CONFLICT, Json(error_response)).into_response()) - } - status => { - eprintln!("Inventory service returned status: {}", status); - Err(( - StatusCode::INTERNAL_SERVER_ERROR, - Json(serde_json::json!({ - "error": "Failed to reserve stock", - "status": status.as_u16() - })), - ) - .into_response()) - } - } -} - -/// Validate that a product exists and is available -/// -/// Calls the products service to verify the product exists and is active. -/// Returns the product details for further validation (price, stock, etc.) -async fn validate_product( - state: &AppState, - product_uuid: Uuid, -) -> Result<ProductDetail, axum::response::Response> { - let url = format!("{}/products/{}", state.products_service_url(), product_uuid); - - let response = match state.http_client().get(&url).send().await { - Ok(resp) => resp, - Err(e) => { - eprintln!("Failed to call products service: {}", e); - return Err(( - StatusCode::SERVICE_UNAVAILABLE, - Json(serde_json::json!({ - "error": "Products service unavailable", - "details": e.to_string() - })), - ) - .into_response()); - } - }; - - match response.status() { - reqwest::StatusCode::OK => { - let product: ProductDetail = match response.json().await { - Ok(p) => p, - Err(e) => { - eprintln!("Failed to parse product response: {}", e); - return Err(( - StatusCode::INTERNAL_SERVER_ERROR, - Json(serde_json::json!({ - "error": "Failed to parse product data", - "details": e.to_string() - })), - ) - .into_response()); - } - }; - - // Verify product is active - if !product.is_active { - return Err(( - StatusCode::BAD_REQUEST, - Json(serde_json::json!({ - "error": "Product is not available", - "product_uuid": product_uuid.to_string(), - "product_name": product.product_name - })), - ) - .into_response()); - } - - Ok(product) - } - reqwest::StatusCode::NOT_FOUND => Err(( - StatusCode::BAD_REQUEST, - Json(serde_json::json!({ - "error": "Product not found", - "product_uuid": product_uuid.to_string() - })), - ) - .into_response()), - status => { - eprintln!("Products service returned status: {}", status); - Err(( - StatusCode::INTERNAL_SERVER_ERROR, - Json(serde_json::json!({ - "error": "Failed to validate product", - "status": status.as_u16() - })), - ) - .into_response()) - } - } -} - -/// Create a new order -/// -/// # Endpoint -/// `POST /orders` -/// -/// Creates a new order with items, shipping address, and payment info. -/// Automatically generates order number and calculates totals. -pub async fn create_order( - State(state): State<AppState>, - Json(request): Json<CreateOrderRequest>, -) -> impl IntoResponse { - // Validate all products exist, are available, and have correct prices - for item in &request.items { - let product = match validate_product(&state, item.product_uuid).await { - Ok(product) => product, - Err(response) => { - // Product validation failed - return error immediately - return response; - } - }; - - // Validate price matches actual product price (prevent price manipulation) - if item.unit_price != product.final_price { - return ( - StatusCode::BAD_REQUEST, - Json(serde_json::json!({ - "error": "Price mismatch", - "product_uuid": item.product_uuid.to_string(), - "product_name": product.product_name, - "submitted_price": item.unit_price.to_string(), - "actual_price": product.final_price.to_string(), - "message": "The submitted price does not match the current product price" - })), - ) - .into_response(); - } - } - - // Reserve stock for all items - // Track reserved items so we can release them if something fails - let mut reserved_items: Vec<(Uuid, i32)> = Vec::new(); - - for item in &request.items { - match reserve_stock(&state, item.product_uuid, item.quantity).await { - Ok(_) => { - reserved_items.push((item.product_uuid, item.quantity)); - } - Err(response) => { - // Stock reservation failed - release any already reserved stock - release_all_reserved_stock(&state, &reserved_items).await; - return response; - } - } - } - - // Start a transaction - let mut tx = match state.pool().begin().await { - Ok(tx) => tx, - Err(e) => { - eprintln!("Failed to start transaction: {}", e); - // Release reserved stock before returning error - release_all_reserved_stock(&state, &reserved_items).await; - return ( - StatusCode::INTERNAL_SERVER_ERROR, - Json(serde_json::json!({ - "error": "Failed to start transaction", - "details": e.to_string() - })), - ) - .into_response(); - } - }; - - // Calculate subtotal from items - let subtotal: BigDecimal = request - .items - .iter() - .map(|item| &item.unit_price * BigDecimal::from(item.quantity)) - .sum(); - - // Simple tax calculation (8% for demo) - let tax_amount = &subtotal * BigDecimal::from(8) / BigDecimal::from(100); - - // Flat shipping rate for demo - let shipping_amount = BigDecimal::from(10); - - let total = &subtotal + &tax_amount + &shipping_amount; - - // Generate order number - let order_number: String = match sqlx::query_scalar("SELECT generate_order_number()") - .fetch_one(&mut *tx) - .await - { - Ok(num) => num, - Err(e) => { - eprintln!("Failed to generate order number: {}", e); - // Release reserved stock before returning error - release_all_reserved_stock(&state, &reserved_items).await; - return ( - StatusCode::INTERNAL_SERVER_ERROR, - Json(serde_json::json!({ - "error": "Failed to generate order number", - "details": e.to_string() - })), - ) - .into_response(); - } - }; - - // Insert order - let order_result = sqlx::query( - r#" - INSERT INTO orders ( - order_number, customer_email, customer_phone, - subtotal, tax_amount, shipping_amount, total, - status, payment_status - ) - VALUES ($1, $2, $3, $4, $5, $6, $7, 'pending', 'pending') - RETURNING id, uuid - "#, - ) - .bind(&order_number) - .bind(&request.customer_email) - .bind(&request.customer_phone) - .bind(&subtotal) - .bind(&tax_amount) - .bind(&shipping_amount) - .bind(&total) - .fetch_one(&mut *tx) - .await; - - let (order_id, order_uuid): (i32, Uuid) = match order_result { - Ok(row) => (row.get("id"), row.get("uuid")), - Err(e) => { - eprintln!("Failed to create order: {}", e); - let _ = tx.rollback().await; - // Release reserved stock before returning error - release_all_reserved_stock(&state, &reserved_items).await; - return ( - StatusCode::INTERNAL_SERVER_ERROR, - Json(serde_json::json!({ - "error": "Failed to create order", - "details": e.to_string() - })), - ) - .into_response(); - } - }; - - // Insert order items - for item in &request.items { - let total_price = &item.unit_price * BigDecimal::from(item.quantity); - if let Err(e) = sqlx::query( - r#" - INSERT INTO order_items ( - order_id, product_uuid, product_name, product_sku, - quantity, unit_price, total_price - ) - VALUES ($1, $2, $3, $4, $5, $6, $7) - "#, - ) - .bind(order_id) - .bind(item.product_uuid) - .bind(&item.product_name) - .bind(&item.product_sku) - .bind(item.quantity) - .bind(&item.unit_price) - .bind(&total_price) - .execute(&mut *tx) - .await - { - eprintln!("Failed to insert order item: {}", e); - let _ = tx.rollback().await; - // Release reserved stock before returning error - release_all_reserved_stock(&state, &reserved_items).await; - return ( - StatusCode::INTERNAL_SERVER_ERROR, - Json(serde_json::json!({ - "error": "Failed to insert order item", - "details": e.to_string() - })), - ) - .into_response(); - } - } - - // Insert shipping address - if let Err(e) = sqlx::query( - r#" - INSERT INTO shipping_addresses ( - order_id, first_name, last_name, address_line1, address_line2, - city, state, postal_code, country, phone - ) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) - "#, - ) - .bind(order_id) - .bind(&request.shipping_address.first_name) - .bind(&request.shipping_address.last_name) - .bind(&request.shipping_address.address_line1) - .bind(&request.shipping_address.address_line2) - .bind(&request.shipping_address.city) - .bind(&request.shipping_address.state) - .bind(&request.shipping_address.postal_code) - .bind(&request.shipping_address.country) - .bind(&request.shipping_address.phone) - .execute(&mut *tx) - .await - { - eprintln!("Failed to insert shipping address: {}", e); - let _ = tx.rollback().await; - // Release reserved stock before returning error - release_all_reserved_stock(&state, &reserved_items).await; - return ( - StatusCode::INTERNAL_SERVER_ERROR, - Json(serde_json::json!({ - "error": "Failed to insert shipping address", - "details": e.to_string() - })), - ) - .into_response(); - } - - // Generate payment reference - let payment_reference: String = match sqlx::query_scalar("SELECT generate_payment_reference()") - .fetch_one(&mut *tx) - .await - { - Ok(ref_id) => ref_id, - Err(e) => { - eprintln!("Failed to generate payment reference: {}", e); - let _ = tx.rollback().await; - // Release reserved stock before returning error - release_all_reserved_stock(&state, &reserved_items).await; - return ( - StatusCode::INTERNAL_SERVER_ERROR, - Json(serde_json::json!({ - "error": "Failed to generate payment reference", - "details": e.to_string() - })), - ) - .into_response(); - } - }; - - // Insert payment - // NOTE: Payment is simulated - in production, this would call a payment gateway - // If payment fails, we need to release reserved stock - if let Err(e) = sqlx::query( - r#" - INSERT INTO payments ( - order_id, payment_method, amount, status, - payment_reference, card_last4, card_brand, processed_at - ) - VALUES ($1, $2, $3, 'paid', $4, $5, $6, CURRENT_TIMESTAMP) - "#, - ) - .bind(order_id) - .bind(&request.payment.payment_method) - .bind(&total) - .bind(&payment_reference) - .bind(&request.payment.card_last4) - .bind(&request.payment.card_brand) - .execute(&mut *tx) - .await - { - eprintln!("Failed to insert payment: {}", e); - let _ = tx.rollback().await; - // Payment failed - release reserved stock - release_all_reserved_stock(&state, &reserved_items).await; - return ( - StatusCode::INTERNAL_SERVER_ERROR, - Json(serde_json::json!({ - "error": "Failed to process payment", - "details": e.to_string() - })), - ) - .into_response(); - } - - // Update order payment status - if let Err(e) = sqlx::query( - r#" - UPDATE orders - SET payment_status = 'paid', status = 'processing' - WHERE id = $1 - "#, - ) - .bind(order_id) - .execute(&mut *tx) - .await - { - eprintln!("Failed to update order status: {}", e); - let _ = tx.rollback().await; - // Release reserved stock before returning error - release_all_reserved_stock(&state, &reserved_items).await; - return ( - StatusCode::INTERNAL_SERVER_ERROR, - Json(serde_json::json!({ - "error": "Failed to update order status", - "details": e.to_string() - })), - ) - .into_response(); - } - - // Commit transaction - if let Err(e) = tx.commit().await { - eprintln!("Failed to commit transaction: {}", e); - // Transaction commit failed - release reserved stock - release_all_reserved_stock(&state, &reserved_items).await; - return ( - StatusCode::INTERNAL_SERVER_ERROR, - Json(serde_json::json!({ - "error": "Failed to commit transaction", - "details": e.to_string() - })), - ) - .into_response(); - } - - // Transaction committed successfully! - // Now confirm the sale with inventory service to convert reserved stock to sold - confirm_all_sales(&state, order_uuid, &reserved_items).await; - - ( - StatusCode::CREATED, - Json(serde_json::json!({ - "success": true, - "order_number": order_number, - "order_uuid": order_uuid, - "message": "Order created successfully" - })), - ) - .into_response() -} - -/// List orders with pagination and filtering -/// -/// # Endpoint -/// `GET /orders` -/// -/// Supports two modes: -/// 1. Authenticated user: Requires X-User-Email header, returns all orders for that user -/// 2. Guest user: Requires both email and order_number query params, returns single order -pub async fn list_orders( - State(state): State<AppState>, - headers: axum::http::HeaderMap, - Query(params): Query<OrderQueryParams>, -) -> impl IntoResponse { - // Check for authenticated user via X-User-Email header - let user_email = headers - .get("X-User-Email") - .and_then(|h| h.to_str().ok()) - .map(String::from); - - if let Some(email) = user_email { - // Authenticated user: return all their orders - return list_user_orders(state.pool(), &email, ¶ms).await; - } - - // Guest user: require both email and order_number - match (¶ms.customer_email, ¶ms.order_number) { - (Some(email), Some(order_number)) => { - get_guest_order(state.pool(), email, order_number).await - } - _ => ( - StatusCode::BAD_REQUEST, - Json(serde_json::json!({ - "error": "Guest users must provide both 'customer_email' and 'order_number' query parameters" - })), - ) - .into_response(), - } -} - -/// List all orders for an authenticated user -async fn list_user_orders( - pool: &PgPool, - user_email: &str, - params: &OrderQueryParams, -) -> axum::response::Response { - let page = params.page.unwrap_or(1).max(1); - let page_size = params.page_size.unwrap_or(20).clamp(1, 100); - let offset = (page - 1) * page_size; - - let mut query = String::from("SELECT * FROM v_orders_complete WHERE customer_email = $1"); - let mut count_query = - String::from("SELECT COUNT(*) FROM v_orders_complete WHERE customer_email = $1"); - - // Apply additional filters if provided - if let Some(ref status) = params.status { - let filter = format!(" AND status = '{}'", status.replace('\'', "''")); - query.push_str(&filter); - count_query.push_str(&filter); - } - - if let Some(ref payment_status) = params.payment_status { - let filter = format!( - " AND payment_status = '{}'", - payment_status.replace('\'', "''") - ); - query.push_str(&filter); - count_query.push_str(&filter); - } - - query.push_str(&format!( - " ORDER BY ordered_at DESC LIMIT {} OFFSET {}", - page_size, offset - )); - - // Execute count query - let total_count: (i64,) = match sqlx::query_as(&count_query) - .bind(user_email) - .fetch_one(pool) - .await - { - Ok(count) => count, - Err(e) => { - eprintln!("Database error counting orders: {}", e); - return ( - StatusCode::INTERNAL_SERVER_ERROR, - Json(serde_json::json!({ - "error": "Failed to count orders", - "details": e.to_string() - })), - ) - .into_response(); - } - }; - - // Execute main query - let orders: Vec<OrderComplete> = match sqlx::query_as(&query) - .bind(user_email) - .fetch_all(pool) - .await - { - Ok(orders) => orders, - Err(e) => { - eprintln!("Database error fetching orders: {}", e); - return ( - StatusCode::INTERNAL_SERVER_ERROR, - Json(serde_json::json!({ - "error": "Failed to fetch orders", - "details": e.to_string() - })), - ) - .into_response(); - } - }; - - let total_pages = ((total_count.0 as f64) / (page_size as f64)).ceil() as i32; - - let response = OrdersResponse { - orders, - total_count: total_count.0, - page, - page_size, - total_pages, - }; - - (StatusCode::OK, Json(response)).into_response() -} - -/// Get a single order for a guest user -async fn get_guest_order( - pool: &PgPool, - email: &str, - order_number: &str, -) -> axum::response::Response { - let result = sqlx::query_as::<_, OrderComplete>( - r#" - SELECT * FROM v_orders_complete - WHERE customer_email = $1 AND order_number = $2 - "#, - ) - .bind(email) - .bind(order_number) - .fetch_optional(pool) - .await; - - match result { - Ok(Some(order)) => { - // Return as single-item list for consistency - let response = OrdersResponse { - orders: vec![order], - total_count: 1, - page: 1, - page_size: 1, - total_pages: 1, - }; - (StatusCode::OK, Json(response)).into_response() - } - Ok(None) => ( - StatusCode::NOT_FOUND, - Json(serde_json::json!({ - "error": "Order not found or email does not match" - })), - ) - .into_response(), - Err(e) => { - eprintln!("Database error fetching order: {}", e); - ( - StatusCode::INTERNAL_SERVER_ERROR, - Json(serde_json::json!({ - "error": "Failed to fetch order", - "details": e.to_string() - })), - ) - .into_response() - } - } -} - -/// Get order details by UUID -/// -/// # Endpoint -/// `GET /orders/{uuid}` -pub async fn get_order_by_id( - State(state): State<AppState>, - Path(uuid): Path<Uuid>, -) -> impl IntoResponse { - let result = sqlx::query_as::<_, OrderComplete>( - r#" - SELECT * FROM v_orders_complete WHERE eid = $1 - "#, - ) - .bind(uuid) - .fetch_optional(state.pool()) - .await; - - match result { - Ok(Some(order)) => (StatusCode::OK, Json(order)).into_response(), - Ok(None) => ( - StatusCode::NOT_FOUND, - Json(serde_json::json!({ - "error": "Order not found", - "uuid": uuid.to_string() - })), - ) - .into_response(), - Err(e) => { - eprintln!("Database error fetching order: {}", e); - ( - StatusCode::INTERNAL_SERVER_ERROR, - Json(serde_json::json!({ - "error": "Failed to fetch order", - "details": e.to_string() - })), - ) - .into_response() - } - } -} diff --git a/distributed_observability_in_rust/example_project/orders/src/handlers/shipments.rs b/distributed_observability_in_rust/example_project/orders/src/handlers/shipments.rs @@ -1,244 +0,0 @@ -//! Shipment tracking API handlers - -use axum::{ - extract::{Path, State}, - http::StatusCode, - response::{IntoResponse, Json}, -}; -use uuid::Uuid; - -use crate::models::{CreateShipmentRequest, Shipment, UpdateShipmentStatusRequest}; -use crate::AppState; - -/// Create a shipment for an order -/// -/// # Endpoint -/// `POST /orders/{order_uuid}/shipment` -pub async fn create_shipment( - State(state): State<AppState>, - Path(order_uuid): Path<Uuid>, - Json(request): Json<CreateShipmentRequest>, -) -> impl IntoResponse { - // Get order_id from UUID - let order_id: Option<i32> = match sqlx::query_scalar("SELECT id FROM orders WHERE uuid = $1") - .bind(order_uuid) - .fetch_optional(state.pool()) - .await - { - Ok(id) => id, - Err(e) => { - eprintln!("Database error fetching order: {}", e); - return ( - StatusCode::INTERNAL_SERVER_ERROR, - Json(serde_json::json!({ - "error": "Failed to fetch order", - "details": e.to_string() - })), - ) - .into_response(); - } - }; - - let order_id = match order_id { - Some(id) => id, - None => { - return ( - StatusCode::NOT_FOUND, - Json(serde_json::json!({ - "error": "Order not found", - "order_uuid": order_uuid.to_string() - })), - ) - .into_response(); - } - }; - - // Create shipment - let result = sqlx::query_as::<_, Shipment>( - r#" - INSERT INTO shipments ( - order_id, carrier, tracking_number, - estimated_delivery_date, status, shipped_at - ) - VALUES ($1, $2, $3, $4, 'shipped', CURRENT_TIMESTAMP) - RETURNING * - "#, - ) - .bind(order_id) - .bind(&request.carrier) - .bind(&request.tracking_number) - .bind(request.estimated_delivery_date) - .fetch_one(state.pool()) - .await; - - match result { - Ok(shipment) => { - // Update order status to shipped - let _ = sqlx::query("UPDATE orders SET status = 'shipped' WHERE id = $1") - .bind(order_id) - .execute(state.pool()) - .await; - - (StatusCode::CREATED, Json(shipment)).into_response() - } - Err(e) => { - eprintln!("Database error creating shipment: {}", e); - ( - StatusCode::INTERNAL_SERVER_ERROR, - Json(serde_json::json!({ - "error": "Failed to create shipment", - "details": e.to_string() - })), - ) - .into_response() - } - } -} - -/// Update shipment status -/// -/// # Endpoint -/// `PUT /orders/{order_uuid}/shipment/status` -pub async fn update_shipment_status( - State(state): State<AppState>, - Path(order_uuid): Path<Uuid>, - Json(request): Json<UpdateShipmentStatusRequest>, -) -> impl IntoResponse { - // Start transaction - let mut tx = match state.pool().begin().await { - Ok(tx) => tx, - Err(e) => { - eprintln!("Failed to start transaction: {}", e); - return ( - StatusCode::INTERNAL_SERVER_ERROR, - Json(serde_json::json!({ - "error": "Failed to start transaction", - "details": e.to_string() - })), - ) - .into_response(); - } - }; - - // Get order_id - let order_id: Option<i32> = - match sqlx::query_scalar("SELECT id FROM orders WHERE uuid = $1") - .bind(order_uuid) - .fetch_optional(&mut *tx) - .await - { - Ok(id) => id, - Err(e) => { - eprintln!("Database error fetching order: {}", e); - let _ = tx.rollback().await; - return ( - StatusCode::INTERNAL_SERVER_ERROR, - Json(serde_json::json!({ - "error": "Failed to fetch order", - "details": e.to_string() - })), - ) - .into_response(); - } - }; - - let order_id = match order_id { - Some(id) => id, - None => { - let _ = tx.rollback().await; - return ( - StatusCode::NOT_FOUND, - Json(serde_json::json!({ - "error": "Order not found", - "order_uuid": order_uuid.to_string() - })), - ) - .into_response(); - } - }; - - // Update shipment - let query = if request.status == "delivered" { - sqlx::query( - r#" - UPDATE shipments - SET status = $1, actual_delivery_date = $2, delivered_at = CURRENT_TIMESTAMP - WHERE order_id = $3 - RETURNING id - "#, - ) - .bind(&request.status) - .bind(request.actual_delivery_date) - .bind(order_id) - } else { - sqlx::query( - r#" - UPDATE shipments - SET status = $1 - WHERE order_id = $2 - RETURNING id - "#, - ) - .bind(&request.status) - .bind(order_id) - }; - - let result = query.fetch_optional(&mut *tx).await; - - match result { - Ok(Some(_)) => { - // Update order status if delivered - if request.status == "delivered" { - let _ = sqlx::query("UPDATE orders SET status = 'delivered' WHERE id = $1") - .bind(order_id) - .execute(&mut *tx) - .await; - } - - if let Err(e) = tx.commit().await { - eprintln!("Failed to commit transaction: {}", e); - return ( - StatusCode::INTERNAL_SERVER_ERROR, - Json(serde_json::json!({ - "error": "Failed to commit transaction", - "details": e.to_string() - })), - ) - .into_response(); - } - - ( - StatusCode::OK, - Json(serde_json::json!({ - "success": true, - "message": "Shipment status updated", - "status": request.status - })), - ) - .into_response() - } - Ok(None) => { - let _ = tx.rollback().await; - ( - StatusCode::NOT_FOUND, - Json(serde_json::json!({ - "error": "Shipment not found for order", - "order_uuid": order_uuid.to_string() - })), - ) - .into_response() - } - Err(e) => { - eprintln!("Database error updating shipment: {}", e); - let _ = tx.rollback().await; - ( - StatusCode::INTERNAL_SERVER_ERROR, - Json(serde_json::json!({ - "error": "Failed to update shipment", - "details": e.to_string() - })), - ) - .into_response() - } - } -} diff --git a/distributed_observability_in_rust/example_project/orders/src/main.rs b/distributed_observability_in_rust/example_project/orders/src/main.rs @@ -1,150 +0,0 @@ -//! Orders Service -//! -//! A microservice for managing customer orders, payments, and shipping. -//! -//! # Features -//! - Order creation with guest checkout -//! - Order management and status tracking -//! - Payment processing (simulated) -//! - Shipping address management -//! - Shipment tracking -//! - PostgreSQL database with orders schema -//! - CORS enabled for web client access -//! -//! # API Endpoints -//! ## Orders -//! - `POST /orders` - Create a new order (payment must succeed or order fails) -//! - `GET /orders` - List orders with filters and pagination -//! - `GET /orders/{uuid}` - Get complete order details (includes payment & shipment) -//! -//! ## Shipments (Internal - used by scheduler) -//! - `POST /orders/{uuid}/shipment` - Create shipment (sets order status to 'shipped') -//! - `PUT /orders/{uuid}/shipment/status` - Update shipment status (sets order status to 'delivered' when complete) -//! -//! # Configuration -//! The service is configured via: -//! - Environment variables (loaded from .env if present) -//! - config.toml file -//! -//! # Database -//! Uses the `orders` schema in PostgreSQL with automatic search path configuration. -//! Migrations are run automatically on startup. - -mod config; -mod db; -mod handlers; -mod models; - -use anyhow::Result; -use axum::{ - routing::{get, post, put}, - Router, -}; -use std::net::SocketAddr; -use tower_http::cors::CorsLayer; - -use config::Config; -use db::Database; - -/// Application state shared across handlers -#[derive(Clone)] -pub struct AppState { - db_pool: sqlx::PgPool, - http_client: reqwest::Client, - products_service_url: String, - inventory_service_url: String, -} - -impl AppState { - /// Get the database pool - pub fn pool(&self) -> &sqlx::PgPool { - &self.db_pool - } - - /// Get the HTTP client - pub fn http_client(&self) -> &reqwest::Client { - &self.http_client - } - - /// Get the products service URL - pub fn products_service_url(&self) -> &str { - &self.products_service_url - } - - /// Get the inventory service URL - pub fn inventory_service_url(&self) -> &str { - &self.inventory_service_url - } -} - -#[tokio::main] -async fn main() -> Result<()> { - // Load environment variables from .env file if present - dotenvy::dotenv().ok(); - - // Load configuration from config.toml - let config = Config::load()?; - - // Print startup information - println!("Starting Orders Service..."); - println!("Server port: {}", config.server.port); - println!("Database URL: {}", config.database.url); - println!("Products Service: {}:{}", config.services.products_host, config.services.products_port); - println!("Inventory Service: {}:{}", config.services.inventory_host, config.services.inventory_port); - - // Initialize database connection pool - let db = Database::new(&config.database.url, config.database.max_connections).await?; - - // Create HTTP client for service-to-service communication - let http_client = reqwest::Client::builder() - .timeout(std::time::Duration::from_secs(config.http_client.timeout_secs)) - .build()?; - - // Create application state - let state = AppState { - db_pool: db.pool().clone(), - http_client, - products_service_url: config.services.products_service_url(), - inventory_service_url: config.services.inventory_service_url(), - }; - - // Build the application router with all endpoints - let app = Router::new() - // Order endpoints - .route("/orders", post(handlers::create_order)) - .route("/orders", get(handlers::list_orders)) - .route("/orders/{uuid}", get(handlers::get_order_by_id)) - // Shipment endpoints (internal - used by scheduler) - .route( - "/orders/{order_uuid}/shipment", - post(handlers::create_shipment), - ) - .route( - "/orders/{order_uuid}/shipment/status", - put(handlers::update_shipment_status), - ) - // Enable CORS for all routes - .layer(CorsLayer::permissive()) - // Add application state - .with_state(state); - - // Create socket address from configuration - let addr = SocketAddr::from(([0, 0, 0, 0], config.server.port)); - - // Print API documentation - println!("\nOrders Service listening on {}", addr); - println!("\nAvailable endpoints:"); - println!(" Orders:"); - println!(" POST /orders - Create new order (payment must succeed)"); - println!(" GET /orders - List orders (with pagination & filters)"); - println!(" GET /orders/{{uuid}} - Get complete order (includes payment & shipment)"); - println!(" Shipments (Internal - used by scheduler):"); - println!(" POST /orders/{{uuid}}/shipment - Create shipment (sets status='shipped')"); - println!(" PUT /orders/{{uuid}}/shipment/status - Update shipment (sets status='delivered' when complete)"); - - // Start the HTTP server - let listener = tokio::net::TcpListener::bind(addr).await?; - axum::serve(listener, app).await?; - - Ok(()) -} diff --git a/distributed_observability_in_rust/example_project/otelmart/Cargo.toml b/distributed_observability_in_rust/example_project/otelmart/Cargo.toml @@ -1,46 +0,0 @@ -[package] -name = "otelmart" -version.workspace = true -edition.workspace = true -authors.workspace = true - -[lints] -workspace = true - -[dependencies] -# Async runtime -tokio = { workspace = true } - -# Web framework -axum = { workspace = true, features = ["macros"] } -tower = { workspace = true } -tower-http = { workspace = true, features = ["fs", "cors"] } - -# Database -sqlx = { workspace = true, features = ["runtime-tokio-rustls", "postgres", "uuid", "chrono", "migrate"] } - -# Serialization -serde = { workspace = true } -serde_json = { workspace = true } - -# HTTP Client (for proxying) -reqwest = { workspace = true } - -# Security -bcrypt = { workspace = true } -jsonwebtoken = { workspace = true } - -# Utilities -uuid = { workspace = true } -chrono = { workspace = true } -anyhow = { workspace = true } -thiserror = { workspace = true } - -# Configuration -config = { workspace = true } -dotenvy = { workspace = true } - -# URL encoding -urlencoding = { workspace = true } - -[dev-dependencies] diff --git a/distributed_observability_in_rust/example_project/otelmart/Dockerfile b/distributed_observability_in_rust/example_project/otelmart/Dockerfile @@ -1,91 +0,0 @@ -# ============================================================ -# Multi-stage Dockerfile for OtelMart Service + Angular Client -# ============================================================ - -# Stage 1: Build Angular Client -FROM node:20-alpine AS client-builder - -WORKDIR /app/client - -# Copy client package files -COPY client/package*.json ./ - -# Install dependencies -RUN npm ci - -# Copy client source -COPY client/ ./ - -# Build Angular app for production -RUN npm run build --configuration=production && \ - ls -la dist/ || echo "No dist directory" && \ - ls -la dist/*/browser || echo "No browser directory found" - -# Stage 2: Build Rust OtelMart Service -FROM rust:latest AS rust-builder - -WORKDIR /app - -# Install build dependencies -RUN apt-get update && \ - apt-get install -y pkg-config libssl-dev && \ - rm -rf /var/lib/apt/lists/* - -# Copy workspace Cargo files -COPY Cargo.toml Cargo.lock ./ - -# Copy otelmart service -COPY otelmart/Cargo.toml ./otelmart/ -COPY otelmart/src ./otelmart/src/ -COPY otelmart/config.toml ./otelmart/ -COPY otelmart/config.docker.toml ./otelmart/ - -# Copy products (required by workspace) -COPY products/Cargo.toml ./products/ -COPY products/src ./products/src/ - -# Copy inventory (required by workspace) -COPY inventory/Cargo.toml ./inventory/ -COPY inventory/src ./inventory/src/ - -# Copy orders (required by workspace) -COPY orders/Cargo.toml ./orders/ -COPY orders/src ./orders/src/ - -# Build the service (release mode) -WORKDIR /app -RUN cargo build --release - -# Stage 3: Runtime image -FROM debian:bookworm-slim - -WORKDIR /app - -# Install runtime dependencies -RUN apt-get update && \ - apt-get install -y ca-certificates libssl3 curl && \ - rm -rf /var/lib/apt/lists/* - -# Copy built binary from rust-builder -COPY --from=rust-builder /app/target/release/otelmart /app/otelmart - -# Copy config file (use docker config) -COPY --from=rust-builder /app/otelmart/config.docker.toml /app/config.toml - -# Copy built Angular app from client-builder -COPY --from=client-builder /app/client/dist /app/dist - -# Create non-root user -RUN useradd -m -u 1000 appuser && \ - chown -R appuser:appuser /app -USER appuser - -# Expose port -EXPOSE 4200 - -# Health check -HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ - CMD ["/usr/bin/curl", "-f", "http://localhost:4200/health"] - -# Run the service -CMD ["/app/otelmart"] diff --git a/distributed_observability_in_rust/example_project/otelmart/src/handlers/auth.rs b/distributed_observability_in_rust/example_project/otelmart/src/handlers/auth.rs @@ -1,127 +0,0 @@ -use axum::{ - extract::State, - http::{StatusCode, header}, - response::IntoResponse, - Json, -}; -use serde::Serialize; - -use crate::{ - auth, - models::{RegisterRequest, LoginRequest, LoginResponse, UserResponse}, - AppState, -}; - -#[derive(Serialize)] -pub struct ErrorResponse { - pub error: String, -} - -pub async fn register( - State(state): State<AppState>, - Json(req): Json<RegisterRequest>, -) -> impl IntoResponse { - match auth::register_user(state.db.pool(), req).await { - Ok(user) => { - let response = UserResponse::from(user); - (StatusCode::CREATED, Json(response)).into_response() - } - Err(e) => { - ( - StatusCode::BAD_REQUEST, - Json(ErrorResponse { - error: e.to_string(), - }), - ).into_response() - } - } -} - -pub async fn login( - State(state): State<AppState>, - Json(req): Json<LoginRequest>, -) -> impl IntoResponse { - match auth::login_user(state.db.pool(), req).await { - Ok((user, session)) => { - let response = LoginResponse { - token: session.session_token.clone(), - user: UserResponse::from(user), - expires_at: session.expires_at, - }; - - ( - StatusCode::OK, - [(header::SET_COOKIE, format!("session_token={}; HttpOnly; SameSite=Lax; Path=/; Max-Age={}", session.session_token, 7 * 24 * 60 * 60))], - Json(response), - ).into_response() - } - Err(e) => { - ( - StatusCode::UNAUTHORIZED, - Json(ErrorResponse { - error: e.to_string(), - }), - ).into_response() - } - } -} - -pub async fn logout( - State(state): State<AppState>, - headers: axum::http::HeaderMap, -) -> impl IntoResponse { - // Extract session token from cookie or Authorization header - let token = extract_token(&headers); - - if let Some(token) = token { - match auth::logout_user(state.db.pool(), &token).await { - Ok(_) => { - ( - StatusCode::OK, - [(header::SET_COOKIE, "session_token=; HttpOnly; SameSite=Lax; Path=/; Max-Age=0")], - Json(serde_json::json!({ "message": "Logged out successfully" })), - ).into_response() - } - Err(e) => { - ( - StatusCode::INTERNAL_SERVER_ERROR, - Json(ErrorResponse { - error: e.to_string(), - }), - ).into_response() - } - } - } else { - ( - StatusCode::UNAUTHORIZED, - Json(ErrorResponse { - error: "No session token provided".to_string(), - }), - ).into_response() - } -} - -fn extract_token(headers: &axum::http::HeaderMap) -> Option<String> { - // Try to get from Authorization header - if let Some(auth_header) = headers.get(header::AUTHORIZATION) { - if let Ok(auth_str) = auth_header.to_str() { - if auth_str.starts_with("Bearer ") { - return Some(auth_str[7..].to_string()); - } - } - } - - // Try to get from Cookie header - if let Some(cookie_header) = headers.get(header::COOKIE) { - if let Ok(cookie_str) = cookie_header.to_str() { - for cookie in cookie_str.split(';') { - let cookie = cookie.trim(); - if cookie.starts_with("session_token=") { - return Some(cookie[14..].to_string()); - } - } - } - } - - None -} diff --git a/distributed_observability_in_rust/example_project/otelmart/src/handlers/users.rs b/distributed_observability_in_rust/example_project/otelmart/src/handlers/users.rs @@ -1,523 +0,0 @@ -use axum::{ - extract::{State, Path}, - http::StatusCode, - response::IntoResponse, - Json, -}; -use uuid::Uuid; - -use crate::{ - auth, - models::{UserAddress, AddAddressRequest, AddressResponse, UpdateProfileRequest}, - AppState, -}; - -use super::auth::ErrorResponse; - -pub async fn get_profile( - State(state): State<AppState>, - headers: axum::http::HeaderMap, -) -> impl IntoResponse { - let token = extract_token(&headers); - - if let Some(token) = token { - match auth::validate_session(state.db.pool(), &token).await { - Ok(Some(user)) => { - // Get user profile (if exists) - let profile = sqlx::query_as::<_, (uuid::Uuid, Option<String>, Option<chrono::NaiveDate>, bool, bool)>( - r#" - SELECT - uuid, - avatar_url, - date_of_birth, - email_notifications, - marketing_emails - FROM user_profiles - WHERE user_id = $1 - "# - ) - .bind(user.id) - .fetch_optional(state.db.pool()) - .await; - - match profile { - Ok(Some((eid, avatar_url, date_of_birth, email_notifications, marketing_emails))) => { - (StatusCode::OK, Json(serde_json::json!({ - "user_id": user.uuid, - "email": user.email, - "first_name": user.first_name, - "last_name": user.last_name, - "phone": user.phone, - "is_verified": user.is_verified, - "profile_eid": eid, - "avatar_url": avatar_url, - "date_of_birth": date_of_birth, - "email_notifications": email_notifications, - "marketing_emails": marketing_emails, - }))).into_response() - } - Ok(None) => { - // Return user data even if profile doesn't exist yet - (StatusCode::OK, Json(serde_json::json!({ - "user_id": user.uuid, - "email": user.email, - "first_name": user.first_name, - "last_name": user.last_name, - "phone": user.phone, - "is_verified": user.is_verified, - "profile_eid": null, - "avatar_url": null, - "date_of_birth": null, - "email_notifications": true, - "marketing_emails": false, - }))).into_response() - } - Err(e) => { - (StatusCode::INTERNAL_SERVER_ERROR, Json(ErrorResponse { - error: e.to_string(), - })).into_response() - } - } - } - Ok(None) => { - (StatusCode::UNAUTHORIZED, Json(ErrorResponse { - error: "Invalid or expired session".to_string(), - })).into_response() - } - Err(e) => { - (StatusCode::INTERNAL_SERVER_ERROR, Json(ErrorResponse { - error: e.to_string(), - })).into_response() - } - } - } else { - (StatusCode::UNAUTHORIZED, Json(ErrorResponse { - error: "No session token provided".to_string(), - })).into_response() - } -} - -pub async fn update_profile( - State(state): State<AppState>, - headers: axum::http::HeaderMap, - Json(req): Json<UpdateProfileRequest>, -) -> impl IntoResponse { - let token = extract_token(&headers); - - if let Some(token) = token { - match auth::validate_session(state.db.pool(), &token).await { - Ok(Some(user)) => { - // Check if profile exists - let profile_exists = sqlx::query_as::<_, (i32,)>( - "SELECT id FROM user_profiles WHERE user_id = $1" - ) - .bind(user.id) - .fetch_optional(state.db.pool()) - .await; - - match profile_exists { - Ok(Some(_)) => { - // Update existing profile - let result = sqlx::query_as::<_, (uuid::Uuid, Option<String>, Option<chrono::NaiveDate>, bool, bool)>( - r#" - UPDATE user_profiles - SET avatar_url = COALESCE($1, avatar_url), - date_of_birth = COALESCE($2, date_of_birth), - email_notifications = COALESCE($3, email_notifications), - marketing_emails = COALESCE($4, marketing_emails), - updated_at = NOW() - WHERE user_id = $5 - RETURNING - uuid, - avatar_url, - date_of_birth, - email_notifications, - marketing_emails - "# - ) - .bind(&req.avatar_url) - .bind(&req.date_of_birth) - .bind(&req.email_notifications) - .bind(&req.marketing_emails) - .bind(user.id) - .fetch_one(state.db.pool()) - .await; - - match result { - Ok((eid, avatar_url, date_of_birth, email_notifications, marketing_emails)) => { - (StatusCode::OK, Json(serde_json::json!({ - "eid": eid, - "avatar_url": avatar_url, - "date_of_birth": date_of_birth, - "email_notifications": email_notifications, - "marketing_emails": marketing_emails, - }))).into_response() - } - Err(e) => { - (StatusCode::INTERNAL_SERVER_ERROR, Json(ErrorResponse { - error: e.to_string(), - })).into_response() - } - } - } - Ok(None) => { - // Create new profile - let result = sqlx::query_as::<_, (uuid::Uuid, Option<String>, Option<chrono::NaiveDate>, bool, bool)>( - r#" - INSERT INTO user_profiles ( - user_id, - avatar_url, - date_of_birth, - email_notifications, - marketing_emails - ) VALUES ($1, $2, $3, $4, $5) - RETURNING - uuid, - avatar_url, - date_of_birth, - email_notifications, - marketing_emails - "# - ) - .bind(user.id) - .bind(&req.avatar_url) - .bind(&req.date_of_birth) - .bind(req.email_notifications.unwrap_or(true)) - .bind(req.marketing_emails.unwrap_or(false)) - .fetch_one(state.db.pool()) - .await; - - match result { - Ok((eid, avatar_url, date_of_birth, email_notifications, marketing_emails)) => { - (StatusCode::CREATED, Json(serde_json::json!({ - "eid": eid, - "avatar_url": avatar_url, - "date_of_birth": date_of_birth, - "email_notifications": email_notifications, - "marketing_emails": marketing_emails, - }))).into_response() - } - Err(e) => { - (StatusCode::INTERNAL_SERVER_ERROR, Json(ErrorResponse { - error: e.to_string(), - })).into_response() - } - } - } - Err(e) => { - (StatusCode::INTERNAL_SERVER_ERROR, Json(ErrorResponse { - error: e.to_string(), - })).into_response() - } - } - } - Ok(None) => { - (StatusCode::UNAUTHORIZED, Json(ErrorResponse { - error: "Invalid or expired session".to_string(), - })).into_response() - } - Err(e) => { - (StatusCode::INTERNAL_SERVER_ERROR, Json(ErrorResponse { - error: e.to_string(), - })).into_response() - } - } - } else { - (StatusCode::UNAUTHORIZED, Json(ErrorResponse { - error: "No session token provided".to_string(), - })).into_response() - } -} - -pub async fn get_addresses( - State(state): State<AppState>, - headers: axum::http::HeaderMap, -) -> impl IntoResponse { - let token = extract_token(&headers); - - if let Some(token) = token { - match auth::validate_session(state.db.pool(), &token).await { - Ok(Some(user)) => { - let addresses = sqlx::query_as::<_, UserAddress>( - r#" - SELECT * FROM user_addresses - WHERE user_id = $1 AND is_active = true - ORDER BY is_default DESC, created_at DESC - "# - ) - .bind(user.id) - .fetch_all(state.db.pool()) - .await; - - match addresses { - Ok(addresses) => { - let response: Vec<AddressResponse> = addresses - .into_iter() - .map(AddressResponse::from) - .collect(); - - (StatusCode::OK, Json(response)).into_response() - } - Err(e) => { - (StatusCode::INTERNAL_SERVER_ERROR, Json(ErrorResponse { - error: e.to_string(), - })).into_response() - } - } - } - Ok(None) => { - (StatusCode::UNAUTHORIZED, Json(ErrorResponse { - error: "Invalid or expired session".to_string(), - })).into_response() - } - Err(e) => { - (StatusCode::INTERNAL_SERVER_ERROR, Json(ErrorResponse { - error: e.to_string(), - })).into_response() - } - } - } else { - (StatusCode::UNAUTHORIZED, Json(ErrorResponse { - error: "No session token provided".to_string(), - })).into_response() - } -} - -pub async fn add_address( - State(state): State<AppState>, - headers: axum::http::HeaderMap, - Json(req): Json<AddAddressRequest>, -) -> impl IntoResponse { - let token = extract_token(&headers); - - if let Some(token) = token { - match auth::validate_session(state.db.pool(), &token).await { - Ok(Some(user)) => { - let address = sqlx::query_as::<_, UserAddress>( - r#" - INSERT INTO user_addresses ( - user_id, address_type, address_label, - first_name, last_name, - address_line1, address_line2, - city, state, postal_code, country, - phone, is_default - ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13) - RETURNING * - "# - ) - .bind(user.id) - .bind(&req.address_type) - .bind(&req.address_label) - .bind(&req.first_name) - .bind(&req.last_name) - .bind(&req.address_line1) - .bind(&req.address_line2) - .bind(&req.city) - .bind(&req.state) - .bind(&req.postal_code) - .bind(&req.country) - .bind(&req.phone) - .bind(req.is_default.unwrap_or(false)) - .fetch_one(state.db.pool()) - .await; - - match address { - Ok(address) => { - let response = AddressResponse::from(address); - (StatusCode::CREATED, Json(response)).into_response() - } - Err(e) => { - (StatusCode::BAD_REQUEST, Json(ErrorResponse { - error: e.to_string(), - })).into_response() - } - } - } - Ok(None) => { - (StatusCode::UNAUTHORIZED, Json(ErrorResponse { - error: "Invalid or expired session".to_string(), - })).into_response() - } - Err(e) => { - (StatusCode::INTERNAL_SERVER_ERROR, Json(ErrorResponse { - error: e.to_string(), - })).into_response() - } - } - } else { - (StatusCode::UNAUTHORIZED, Json(ErrorResponse { - error: "No session token provided".to_string(), - })).into_response() - } -} - -pub async fn update_address( - State(state): State<AppState>, - headers: axum::http::HeaderMap, - Path(id): Path<Uuid>, - Json(req): Json<AddAddressRequest>, -) -> impl IntoResponse { - let token = extract_token(&headers); - - if let Some(token) = token { - match auth::validate_session(state.db.pool(), &token).await { - Ok(Some(user)) => { - // Update address only if it belongs to the user - let address = sqlx::query_as::<_, UserAddress>( - r#" - UPDATE user_addresses - SET address_type = $1, - address_label = $2, - first_name = $3, - last_name = $4, - address_line1 = $5, - address_line2 = $6, - city = $7, - state = $8, - postal_code = $9, - country = $10, - phone = $11, - is_default = $12, - updated_at = NOW() - WHERE uuid = $13 AND user_id = $14 AND is_active = true - RETURNING * - "# - ) - .bind(&req.address_type) - .bind(&req.address_label) - .bind(&req.first_name) - .bind(&req.last_name) - .bind(&req.address_line1) - .bind(&req.address_line2) - .bind(&req.city) - .bind(&req.state) - .bind(&req.postal_code) - .bind(&req.country) - .bind(&req.phone) - .bind(req.is_default.unwrap_or(false)) - .bind(id) - .bind(user.id) - .fetch_optional(state.db.pool()) - .await; - - match address { - Ok(Some(address)) => { - let response = AddressResponse::from(address); - (StatusCode::OK, Json(response)).into_response() - } - Ok(None) => { - (StatusCode::NOT_FOUND, Json(ErrorResponse { - error: "Address not found or access denied".to_string(), - })).into_response() - } - Err(e) => { - (StatusCode::BAD_REQUEST, Json(ErrorResponse { - error: e.to_string(), - })).into_response() - } - } - } - Ok(None) => { - (StatusCode::UNAUTHORIZED, Json(ErrorResponse { - error: "Invalid or expired session".to_string(), - })).into_response() - } - Err(e) => { - (StatusCode::INTERNAL_SERVER_ERROR, Json(ErrorResponse { - error: e.to_string(), - })).into_response() - } - } - } else { - (StatusCode::UNAUTHORIZED, Json(ErrorResponse { - error: "No session token provided".to_string(), - })).into_response() - } -} - -pub async fn delete_address( - State(state): State<AppState>, - headers: axum::http::HeaderMap, - Path(id): Path<Uuid>, -) -> impl IntoResponse { - let token = extract_token(&headers); - - if let Some(token) = token { - match auth::validate_session(state.db.pool(), &token).await { - Ok(Some(user)) => { - // Soft delete: set is_active to false - let result = sqlx::query( - r#" - UPDATE user_addresses - SET is_active = false, updated_at = NOW() - WHERE uuid = $1 AND user_id = $2 AND is_active = true - "# - ) - .bind(id) - .bind(user.id) - .execute(state.db.pool()) - .await; - - match result { - Ok(result) => { - if result.rows_affected() > 0 { - (StatusCode::OK, Json(serde_json::json!({ - "message": "Address deleted successfully" - }))).into_response() - } else { - (StatusCode::NOT_FOUND, Json(ErrorResponse { - error: "Address not found or access denied".to_string(), - })).into_response() - } - } - Err(e) => { - (StatusCode::INTERNAL_SERVER_ERROR, Json(ErrorResponse { - error: e.to_string(), - })).into_response() - } - } - } - Ok(None) => { - (StatusCode::UNAUTHORIZED, Json(ErrorResponse { - error: "Invalid or expired session".to_string(), - })).into_response() - } - Err(e) => { - (StatusCode::INTERNAL_SERVER_ERROR, Json(ErrorResponse { - error: e.to_string(), - })).into_response() - } - } - } else { - (StatusCode::UNAUTHORIZED, Json(ErrorResponse { - error: "No session token provided".to_string(), - })).into_response() - } -} - -fn extract_token(headers: &axum::http::HeaderMap) -> Option<String> { - use axum::http::header; - - // Try to get from Authorization header - if let Some(auth_header) = headers.get(header::AUTHORIZATION) { - if let Ok(auth_str) = auth_header.to_str() { - if auth_str.starts_with("Bearer ") { - return Some(auth_str[7..].to_string()); - } - } - } - - // Try to get from Cookie header - if let Some(cookie_header) = headers.get(header::COOKIE) { - if let Ok(cookie_str) = cookie_header.to_str() { - for cookie in cookie_str.split(';') { - let cookie = cookie.trim(); - if cookie.starts_with("session_token=") { - return Some(cookie[14..].to_string()); - } - } - } - } - - None -} diff --git a/distributed_observability_in_rust/example_project/otelmart/src/main.rs b/distributed_observability_in_rust/example_project/otelmart/src/main.rs @@ -1,182 +0,0 @@ -mod auth; -mod config; -mod db; -mod handlers; -mod models; -mod proxy; - -use anyhow::Result; -use axum::{ - body::Body, - http::{Request, StatusCode, Uri}, - response::{IntoResponse, Response}, - routing::{get, post}, - Router, -}; -use std::net::SocketAddr; -use std::path::PathBuf; -use tower::ServiceExt; -use tower_http::{ - cors::CorsLayer, - services::ServeDir, -}; - -use config::Config; -use db::Database; - -#[derive(Clone)] -pub struct AppState { - db: Database, - http_client: reqwest::Client, - products_service_url: String, - inventory_service_url: String, - orders_service_url: String, - checkout_service_url: String, -} - -/// SPA fallback handler that serves static files or index.html -async fn spa_fallback_handler( - uri: Uri, - req: Request<Body>, - serve_dir: ServeDir, - static_dir: String, -) -> impl IntoResponse { - let path = uri.path(); - - // Check if the request is for an actual file (has an extension) - let has_extension = path.rfind('.').map_or(false, |dot_pos| { - let after_dot = &path[dot_pos + 1..]; - // Check if it looks like a file extension (not empty and no slashes after) - !after_dot.is_empty() && !after_dot.contains('/') - }); - - // If it's a file with an extension, try to serve it - if has_extension { - match serve_dir.oneshot(req).await { - Ok(res) => { - // If file was found (status is not 404), return it - if res.status() != StatusCode::NOT_FOUND { - return res.into_response(); - } - // Otherwise fall through to serve index.html - } - Err(_) => { - // Error serving file, fall through to index.html - } - } - } - - // For all other routes (SPA routes like /products, /checkout, etc.) - // or files that weren't found, serve index.html - let index_path = PathBuf::from(&static_dir).join("index.html"); - - match tokio::fs::read_to_string(&index_path).await { - Ok(contents) => Response::builder() - .status(StatusCode::OK) - .header("content-type", "text/html; charset=utf-8") - .body(Body::from(contents)) - .unwrap() - .into_response(), - Err(_) => Response::builder() - .status(StatusCode::NOT_FOUND) - .header("content-type", "text/html; charset=utf-8") - .body(Body::from("<h1>UI not built</h1><p>Please build the Angular application first.</p>")) - .unwrap() - .into_response(), - } -} - -#[tokio::main] -async fn main() -> Result<()> { - // Load configuration from config.toml - let config = Config::load()?; - - println!("Loading configuration from config.toml..."); - println!("Server port: {}", config.server.port); - println!("Database URL: {}", config.database.url); - println!("Products Service: {}:{}", config.services.products_host, config.services.products_port); - println!("Inventory Service: {}:{}", config.services.inventory_host, config.services.inventory_port); - println!("Orders Service: {}:{}", config.services.orders_host, config.services.orders_port); - println!("Checkout Service: {}:{}", config.services.checkout_host, config.services.checkout_port); - println!("Static files directory: {}", config.server.static_dir); - - // Initialize database connection - let db = Database::new(&config.database.url, config.database.max_connections).await?; - - // Create HTTP client for proxying - let http_client = reqwest::Client::builder() - .timeout(std::time::Duration::from_secs(config.http_client.timeout_secs)) - .build()?; - - // Create application state - let state = AppState { - db, - http_client, - products_service_url: config.services.products_service_url(), - inventory_service_url: config.services.inventory_service_url_computed(), - orders_service_url: config.services.orders_service_url_computed(), - checkout_service_url: config.services.checkout_service_url(), - }; - - // Build API router - let api_router = Router::new() - // Auth routes - .route("/auth/register", post(handlers::auth::register)) - .route("/auth/login", post(handlers::auth::login)) - .route("/auth/logout", post(handlers::auth::logout)) - - // User routes - .route("/users/profile", get(handlers::users::get_profile)) - .route("/users/profile", post(handlers::users::update_profile)) - .route("/users/addresses", get(handlers::users::get_addresses)) - .route("/users/addresses", post(handlers::users::add_address)) - .route("/users/addresses/{id}", post(handlers::users::update_address)) - .route("/users/addresses/{id}", axum::routing::delete(handlers::users::delete_address)) - - // This is a common pattern in API gateways to ensure all request paths are - // properly routed to the backend services - - // Proxy all /products/* requests to products service - .route("/products", axum::routing::any(proxy::products::proxy_products)) - .route("/products/{*path}", axum::routing::any(proxy::products::proxy_products)) - - // Proxy all /inventory/* requests to inventory service - .route("/inventory", axum::routing::any(proxy::inventory::proxy_inventory)) - .route("/inventory/{*path}", axum::routing::any(proxy::inventory::proxy_inventory)) - - // Proxy all /orders/* requests to orders service - .route("/orders", axum::routing::any(proxy::orders::proxy_orders)) - .route("/orders/{*path}", axum::routing::any(proxy::orders::proxy_orders)) - .with_state(state.clone()); - - // Create static file service - let static_dir = config.server.static_dir.clone(); - let serve_dir = ServeDir::new(&static_dir); - - // Build main router - let app = Router::new() - // Health check - .route("/health", get(handlers::health::health_check)) - - // Mount API routes under /api prefix - .nest("/api", api_router) - - // Fallback handler for SPA routing - .fallback(move |uri: Uri, req: Request<Body>| { - let static_dir = static_dir.clone(); - let serve_dir = serve_dir.clone(); - async move { - spa_fallback_handler(uri, req, serve_dir, static_dir).await - } - }) - .layer(CorsLayer::permissive()); - - // Start server - let addr = SocketAddr::from(([0, 0, 0, 0], config.server.port)); - println!("\nOtelMart Service listening on {}", addr); - - let listener = tokio::net::TcpListener::bind(addr).await?; - axum::serve(listener, app).await?; - - Ok(()) -} diff --git a/distributed_observability_in_rust/example_project/otelmart/src/proxy/mod.rs b/distributed_observability_in_rust/example_project/otelmart/src/proxy/mod.rs @@ -1,100 +0,0 @@ -pub mod products; -pub mod inventory; -pub mod orders; - -use axum::{ - body::Body, - extract::Request, - http::{StatusCode, HeaderValue}, - response::{IntoResponse, Response}, -}; - -/// Generic proxy handler that forwards requests to a backend service -/// -/// This function handles: -/// - Path and query string forwarding -/// - Header forwarding (except Host header) -/// - Request body forwarding -/// - Response status, headers, and body forwarding -/// -/// # Arguments -/// * `service_url` - Base URL of the backend service (e.g., "http://products:3001") -/// * `req` - The incoming request to proxy -/// * `http_client` - HTTP client for making the proxy request -pub async fn proxy_request( - service_url: &str, - req: Request, - http_client: &reqwest::Client, -) -> impl IntoResponse { - // Extract the path after /api prefix - let path = req.uri().path(); - let forwarded_path = path.strip_prefix("/api").unwrap_or(path); - let query = req.uri().query().map(|q| format!("?{}", q)).unwrap_or_default(); - - // Build target URL - let target_url = format!("{}{}{}", service_url, forwarded_path, query); - - // Extract method and headers - let method = req.method().clone(); - let headers = req.headers().clone(); - - // Extract body - let body_bytes = match axum::body::to_bytes(req.into_body(), usize::MAX).await { - Ok(bytes) => bytes, - Err(_) => { - return Response::builder() - .status(StatusCode::BAD_REQUEST) - .body(Body::from("Failed to read request body")) - .unwrap(); - } - }; - - // Build request to backend service - let mut client_req = http_client.request(method, &target_url); - - // Forward headers (except Host header) - for (name, value) in headers.iter() { - if name != "host" { - if let Ok(val) = HeaderValue::from_bytes(value.as_bytes()) { - client_req = client_req.header(name.as_str(), val); - } - } - } - - // Add body if present - if !body_bytes.is_empty() { - client_req = client_req.body(body_bytes.to_vec()); - } - - // Send request to backend service - match client_req.send().await { - Ok(response) => { - let status = response.status(); - let mut builder = Response::builder().status(status); - - // Forward response headers - let resp_headers = response.headers().clone(); - for (name, value) in resp_headers.iter() { - if let Ok(val) = HeaderValue::from_bytes(value.as_bytes()) { - builder = builder.header(name.as_str(), val); - } - } - - // Get response body - match response.bytes().await { - Ok(body) => builder.body(Body::from(body)).unwrap(), - Err(_) => Response::builder() - .status(StatusCode::INTERNAL_SERVER_ERROR) - .body(Body::from("Failed to read response body")) - .unwrap(), - } - } - Err(_) => { - Response::builder() - .status(StatusCode::SERVICE_UNAVAILABLE) - .header("content-type", "application/json") - .body(Body::from(r#"{"error":"Service unavailable"}"#)) - .unwrap() - } - } -} diff --git a/distributed_observability_in_rust/example_project/products/Cargo.toml b/distributed_observability_in_rust/example_project/products/Cargo.toml @@ -1,35 +0,0 @@ -[package] -name = "products" -version.workspace = true -edition.workspace = true -authors.workspace = true - -[lints] -workspace = true - -[dependencies] -# Async runtime -tokio = { workspace = true } - -# Web framework -axum = { workspace = true } -tower = { workspace = true } -tower-http = { workspace = true } - -# Database -sqlx = { workspace = true } - -# Serialization -serde = { workspace = true } -serde_json = { workspace = true } - -# Utilities -uuid = { workspace = true } -chrono = { workspace = true } -anyhow = { workspace = true } -thiserror = { workspace = true } -bigdecimal = { workspace = true } - -# Configuration -config = { workspace = true } -dotenvy = { workspace = true } diff --git a/distributed_observability_in_rust/example_project/products/src/handlers/products.rs b/distributed_observability_in_rust/example_project/products/src/handlers/products.rs @@ -1,375 +0,0 @@ -//! Product API handlers -//! -//! This module contains the HTTP request handlers for product-related endpoints. -//! Handlers use sqlx for database queries with the products schema. - -use axum::{ - extract::{Path, Query, State}, - http::StatusCode, - response::{IntoResponse, Json}, -}; -use sqlx::{PgPool, Postgres, QueryBuilder}; -use uuid::Uuid; - -use crate::models::{ProductDetail, ProductQueryParams, ProductWithRating, ProductsResponse}; -use crate::utils::{calculate_pagination, calculate_total_pages, internal_error, not_found_error}; - -/// List products with pagination and filtering -/// -/// # Endpoint -/// `GET /products` -/// -/// # Query Parameters -/// - **Pagination:** -/// - `page` (default: 1) - Page number (1-indexed) -/// - `page_size` (default: 20, max: 100) - Items per page -/// -/// - **Filters:** -/// - `name` - Product name partial match (case-insensitive) -/// - `category_id` - Filter by category ID -/// - `brand` - Brand partial match (case-insensitive) -/// - `start_date` / `end_date` - Filter by update date range -/// - `rating_gt` / `rating_lt` / `rating_eq` - Rating filters -/// - `min_price` / `max_price` - Price range filters -/// -/// # Example -/// ``` -/// GET /products?page=2&page_size=50&brand=TechPro&min_price=100 -/// ``` -/// -/// # Response -/// Returns a `ProductsResponse` with products array and pagination metadata. -pub async fn list_products( - State(pool): State<PgPool>, - Query(params): Query<ProductQueryParams>, -) -> impl IntoResponse { - // Apply pagination defaults and constraints - let (page, page_size, offset) = calculate_pagination(params.page, params.page_size); - - // Check if we have rating filters (determines count query strategy) - let has_rating_filters = - params.rating_gt.is_some() || params.rating_lt.is_some() || params.rating_eq.is_some(); - - // Build count query - optimized based on whether we have rating filters - let total_count = if has_rating_filters { - // Complex count: need to aggregate ratings and apply HAVING clause - match build_count_with_ratings(&pool, ¶ms).await { - Ok(count) => count, - Err(response) => return response, - } - } else { - // Simple count: no need for ratings JOIN or GROUP BY - match build_simple_count(&pool, ¶ms).await { - Ok(count) => count, - Err(response) => return response, - } - }; - - // Build main query with CTE for product data and ratings - let mut main_query = QueryBuilder::<Postgres>::new( - r#" - WITH product_data AS ( - SELECT - p.id, - p.uuid, - p.product_name, - p.brand, - p.description, - p.price, - p.initial_price, - p.discount, - p.stock_quantity, - p.image_url, - p.category_id, - c.name as category_name, - p.created_at, - p.updated_at, - COALESCE(AVG(r.rating)::FLOAT8, NULL) as average_rating, - COUNT(r.id)::BIGINT as rating_count - FROM products p - LEFT JOIN categories c ON p.category_id = c.id - LEFT JOIN ratings r ON p.id = r.product_id - WHERE p.deleted_at IS NULL AND p.is_active = true AND p.stock_quantity > 0 - GROUP BY p.id, p.uuid, p.product_name, p.brand, p.description, p.price, - p.initial_price, p.discount, p.stock_quantity, p.image_url, p.category_id, c.name, - p.created_at, p.updated_at - ) - SELECT * FROM product_data WHERE 1=1 - "#, - ); - - // Apply filters with safe parameter binding - apply_filters(&mut main_query, ¶ms); - - // Add ordering and pagination - main_query.push(" ORDER BY updated_at DESC LIMIT "); - main_query.push_bind(page_size); - main_query.push(" OFFSET "); - main_query.push_bind(offset); - - // Execute main query to fetch products - let products: Vec<ProductWithRating> = match main_query.build_query_as().fetch_all(&pool).await - { - Ok(products) => products, - Err(e) => { - return internal_error("Failed to fetch products", e.to_string()); - } - }; - - // Calculate total pages - let total_pages = calculate_total_pages(total_count, page_size); - - // Build response - let response = ProductsResponse { - products, - total_count, - page, - page_size, - total_pages, - }; - - (StatusCode::OK, Json(response)).into_response() -} - -/// Apply product filters to a query builder -/// -/// This helper function centralizes filter logic to avoid duplication across -/// count queries and main queries. -/// -/// # Arguments -/// * `query` - The QueryBuilder to apply filters to -/// * `params` - Query parameters containing filter values -/// * `column_prefix` - Prefix for column names ("p." for table alias, "" for CTE columns) -/// * `include_ratings` - Whether to include rating filters (only for main query on CTE) -fn apply_product_filters<'a>( - query: &mut QueryBuilder<'a, Postgres>, - params: &'a ProductQueryParams, - column_prefix: &str, - include_ratings: bool, -) { - // Name filter - case-insensitive partial match - if let Some(ref name) = params.name { - query.push(format!(" AND {}product_name ILIKE ", column_prefix).as_str()); - query.push_bind(format!("%{}%", name)); - } - - // Category filter - exact match - if let Some(category_id) = params.category_id { - query.push(format!(" AND {}category_id = ", column_prefix).as_str()); - query.push_bind(category_id); - } - - // Brand filter - case-insensitive partial match - if let Some(ref brand) = params.brand { - query.push(format!(" AND {}brand ILIKE ", column_prefix).as_str()); - query.push_bind(format!("%{}%", brand)); - } - - // Date range filters on updated_at - if let Some(start_date) = params.start_date { - query.push(format!(" AND {}updated_at >= ", column_prefix).as_str()); - query.push_bind(start_date); - } - - if let Some(end_date) = params.end_date { - query.push(format!(" AND {}updated_at <= ", column_prefix).as_str()); - query.push_bind(end_date); - } - - // Price range filters - if let Some(ref min_price) = params.min_price { - query.push(format!(" AND {}price >= ", column_prefix).as_str()); - query.push_bind(min_price); - } - - if let Some(ref max_price) = params.max_price { - query.push(format!(" AND {}price <= ", column_prefix).as_str()); - query.push_bind(max_price); - } - - // Rating filters (only for main query on CTE columns) - if include_ratings { - if let Some(rating_gt) = params.rating_gt { - query.push(" AND average_rating > "); - query.push_bind(rating_gt); - } - - if let Some(rating_lt) = params.rating_lt { - query.push(" AND average_rating < "); - query.push_bind(rating_lt); - } - - if let Some(rating_eq) = params.rating_eq { - query.push(" AND average_rating = "); - query.push_bind(rating_eq); - } - } -} - -/// Build simple count query without rating joins (faster) -async fn build_simple_count( - pool: &PgPool, - params: &ProductQueryParams, -) -> Result<i64, axum::response::Response> { - let mut count_builder = QueryBuilder::<Postgres>::new( - "SELECT COUNT(*) FROM products p WHERE p.deleted_at IS NULL AND p.is_active = true AND p.stock_quantity > 0" - ); - - // Apply non-rating filters using helper - apply_product_filters(&mut count_builder, params, "p.", false); - - match count_builder.build_query_scalar().fetch_one(pool).await { - Ok(count) => Ok(count), - Err(e) => Err(internal_error("Failed to count products", e.to_string())), - } -} - -/// Build count query with rating aggregation (for rating filters) -async fn build_count_with_ratings( - pool: &PgPool, - params: &ProductQueryParams, -) -> Result<i64, axum::response::Response> { - let mut count_builder = QueryBuilder::<Postgres>::new( - r#" - SELECT COUNT(DISTINCT p.id) FROM products p - LEFT JOIN ratings r ON p.id = r.product_id - WHERE p.deleted_at IS NULL AND p.is_active = true AND p.stock_quantity > 0 - "#, - ); - - // Apply non-rating filters to WHERE clause using helper - apply_product_filters(&mut count_builder, params, "p.", false); - - // Add GROUP BY for ratings aggregation - count_builder.push(" GROUP BY p.id"); - - // Apply rating filters with HAVING clause - let mut has_having = false; - - if let Some(rating_gt) = params.rating_gt { - count_builder.push(if has_having { " AND " } else { " HAVING " }); - has_having = true; - count_builder.push("AVG(r.rating) > "); - count_builder.push_bind(rating_gt); - } - - if let Some(rating_lt) = params.rating_lt { - count_builder.push(if has_having { " AND " } else { " HAVING " }); - has_having = true; - count_builder.push("AVG(r.rating) < "); - count_builder.push_bind(rating_lt); - } - - if let Some(rating_eq) = params.rating_eq { - count_builder.push(if has_having { " AND " } else { " HAVING " }); - count_builder.push("AVG(r.rating) = "); - count_builder.push_bind(rating_eq); - } - - // This returns a count of distinct products, but we need to wrap it in another SELECT COUNT(*) - // Actually, COUNT(DISTINCT p.id) already gives us the total count directly - match count_builder.build_query_scalar().fetch_one(pool).await { - Ok(count) => Ok(count), - Err(e) => Err(internal_error("Failed to count products", e.to_string())), - } -} - -/// Apply filters to the main query -fn apply_filters<'a>(query: &mut QueryBuilder<'a, Postgres>, params: &'a ProductQueryParams) { - // Use helper with empty prefix (CTE columns) and include ratings - apply_product_filters(query, params, "", true); -} - -/// Get detailed product information by UUID -/// -/// # Endpoint -/// `GET /products/{uuid}` -/// -/// # Path Parameters -/// - `uuid` - The product UUID -/// -/// # Response -/// Returns a `ProductDetail` with full product information including: -/// - All product fields (name, description, price, stock, etc.) -/// - Category information (name, uuid, slug) -/// - Aggregated rating data (average rating, review count) -/// - Additional metadata (timestamps, availability flags, etc.) -/// -/// # Errors -/// - `404 NOT FOUND` - Product not found or has been deleted -/// - `500 INTERNAL SERVER ERROR` - Database error -/// -/// # Example -/// ``` -/// GET /products/550e8400-e29b-41d4-a716-446655440000 -/// ``` -pub async fn get_product_by_id( - State(pool): State<PgPool>, - Path(uuid): Path<Uuid>, -) -> impl IntoResponse { - // Query product with all details, joined with category and aggregated ratings - // Uses LEFT JOINs to handle products without categories or ratings - let result = sqlx::query_as::<_, ProductDetail>( - r#" - SELECT - p.id, - p.uuid, - p.asin, - p.sku, - p.gtin, - p.product_name, - p.brand, - p.description, - p.url, - p.price, - p.initial_price, - p.discount, - p.currency, - p.stock_quantity, - p.sizes, - p.colors, - p.image_url, - p.available_for_delivery, - p.available_for_pickup, - p.free_returns, - p.is_active, - p.created_at, - p.updated_at, - p.data_timestamp, - p.category_id, - c.name as category_name, - c.uuid as category_uuid, - c.slug as category_slug, - COALESCE(AVG(r.rating)::FLOAT8, NULL) as average_rating, - COUNT(r.id)::BIGINT as rating_count, - CAST(p.id AS TEXT) as product_id_str, - get_root_category_name(p.category_id) as root_category_name, - p.deleted_at - FROM products p - LEFT JOIN categories c ON p.category_id = c.id - LEFT JOIN ratings r ON p.id = r.product_id - WHERE p.uuid = $1 AND p.deleted_at IS NULL - GROUP BY p.id, p.uuid, p.asin, p.sku, p.gtin, p.product_name, p.brand, p.description, - p.url, p.price, p.initial_price, p.discount, p.currency, p.stock_quantity, p.sizes, p.colors, p.image_url, - p.available_for_delivery, p.available_for_pickup, p.free_returns, - p.is_active, p.created_at, p.updated_at, p.data_timestamp, p.category_id, - p.deleted_at, c.name, c.uuid, c.slug - "#, - ) - .bind(uuid) - .fetch_optional(&pool) - .await; - - match result { - Ok(Some(mut product)) => { - // Set the string representation of the product ID - product.set_product_id(); - (StatusCode::OK, Json(product)).into_response() - } - Ok(None) => not_found_error( - "Product not found", - serde_json::json!({"uuid": uuid.to_string()}), - ), - Err(e) => internal_error("Failed to fetch product", e.to_string()), - } -} diff --git a/distributed_observability_in_rust/example_project/products/src/handlers/ratings.rs b/distributed_observability_in_rust/example_project/products/src/handlers/ratings.rs @@ -1,162 +0,0 @@ -//! Product rating API handlers -//! -//! This module handles creating and updating product ratings. -//! Enforces one rating per user per product using database upsert logic. - -use axum::{ - extract::{Path, State}, - http::StatusCode, - response::{IntoResponse, Json}, -}; -use sqlx::PgPool; -use uuid::Uuid; - -use crate::models::{Rating, RatingResponse, UpsertRatingRequest}; - -/// Create or update a user's rating for a product -/// -/// # Endpoint -/// `PUT /products/{id}/ratings` -/// -/// # Path Parameters -/// - `id` - The product ID to rate -/// -/// # Request Body -/// ```json -/// { -/// "user_id": "123e4567-e89b-12d3-a456-426614174000", -/// "rating": 5, -/// "review": "Great product!" -/// } -/// ``` -/// -/// # Behavior -/// - If the user has already rated this product, the existing rating is **updated** -/// - If not, a new rating is **created** -/// - This is enforced by a unique constraint on (product_id, user_id) -/// -/// # Validation -/// - Rating must be between 1-5 -/// - Product must exist and not be deleted -/// - User must exist in the users table -/// -/// # Response -/// Returns the created/updated rating with a message indicating the action taken. -/// -/// # Errors -/// - `400 BAD REQUEST` - Invalid rating value (not 1-5) or user doesn't exist -/// - `404 NOT FOUND` - Product doesn't exist -/// - `500 INTERNAL SERVER ERROR` - Database error -pub async fn upsert_rating( - State(pool): State<PgPool>, - Path(product_id): Path<Uuid>, - Json(payload): Json<UpsertRatingRequest>, -) -> impl IntoResponse { - // Validate rating is within acceptable range (1-5 stars) - if !(1..=5).contains(&payload.rating) { - return ( - StatusCode::BAD_REQUEST, - Json(serde_json::json!({ - "error": "Invalid rating value", - "message": "Rating must be between 1 and 5" - })), - ) - .into_response(); - } - - // Verify the product exists and is not deleted - // Uses EXISTS for efficiency - only checks presence, doesn't fetch data - let product_exists: Option<(bool,)> = sqlx::query_as( - "SELECT EXISTS(SELECT 1 FROM products WHERE uuid = $1 AND deleted_at IS NULL)", - ) - .bind(product_id) - .fetch_optional(&pool) - .await - .ok() - .flatten(); - - if !product_exists.map(|x| x.0).unwrap_or(false) { - return ( - StatusCode::NOT_FOUND, - Json(serde_json::json!({ - "error": "Product not found", - "product_id": product_id - })), - ) - .into_response(); - } - - // Upsert the rating using PostgreSQL's ON CONFLICT clause - // This atomically either: - // 1. Inserts a new rating if none exists for this user-product pair - // 2. Updates the existing rating if one already exists - // - // The unique constraint on (product_id, user_id) ensures one rating per user per product - let result = sqlx::query_as::<_, Rating>( - r#" - INSERT INTO ratings (product_id, user_id, rating, review) - VALUES ($1, $2, $3, $4) - ON CONFLICT (product_id, user_id) - DO UPDATE SET - rating = EXCLUDED.rating, - review = EXCLUDED.review, - updated_at = NOW() - RETURNING id, uuid, product_id, user_id, rating, review, created_at, updated_at - "#, - ) - .bind(product_id) - .bind(payload.user_id) - .bind(payload.rating) - .bind(&payload.review) - .fetch_one(&pool) - .await; - - match result { - Ok(rating) => { - // Determine if this was an update or new insert - // If created_at != updated_at, the record was updated - let was_updated = rating.created_at != rating.updated_at; - let message = if was_updated { - "Rating updated successfully" - } else { - "Rating created successfully" - }; - - ( - StatusCode::OK, - Json(RatingResponse { - rating, - message: message.to_string(), - }), - ) - .into_response() - } - Err(e) => { - eprintln!("Database error upserting rating: {}", e); - - // Check for foreign key constraint violations - // This happens when user_id doesn't exist in the users table - let error_message = e.to_string(); - if error_message.contains("foreign key") || error_message.contains("violates") { - return ( - StatusCode::BAD_REQUEST, - Json(serde_json::json!({ - "error": "Invalid user_id", - "message": "User must be registered before rating products" - })), - ) - .into_response(); - } - - // Generic database error - ( - StatusCode::INTERNAL_SERVER_ERROR, - Json(serde_json::json!({ - "error": "Failed to save rating", - "details": e.to_string() - })), - ) - .into_response() - } - } -} diff --git a/distributed_observability_in_rust/example_project/products/src/main.rs b/distributed_observability_in_rust/example_project/products/src/main.rs @@ -1,93 +0,0 @@ -//! Products Service -//! -//! A microservice for managing product catalog, details, and ratings. -//! -//! # Features -//! - Product listing with pagination and filtering -//! - Product detail retrieval -//! - Product rating/review management -//! - PostgreSQL database with products schema -//! - CORS enabled for web client access -//! -//! # API Endpoints -//! - `GET /products` - List products with filters and pagination -//! - `GET /products/{id}` - Get detailed product information -//! - `PUT /products/{id}/ratings` - Create or update a product rating -//! -//! # Configuration -//! The service is configured via: -//! - Environment variables (loaded from .env if present) -//! - config.toml file -//! -//! # Database -//! Uses the `products` schema in PostgreSQL with automatic search path configuration. -//! Migrations are run automatically on startup. - -mod config; -mod db; -mod handlers; -mod models; -mod utils; - -use anyhow::Result; -use axum::{ - routing::{get, put}, - Router, -}; -use std::net::SocketAddr; -use tower_http::cors::CorsLayer; - -use config::Config; -use db::Database; - -#[tokio::main] -async fn main() -> Result<()> { - // Load environment variables from .env file if present - // This is optional - the service will work without it - dotenvy::dotenv().ok(); - - // Load configuration from config.toml - let config = Config::load()?; - - // Print startup information - println!("Starting Products Service..."); - println!("Server port: {}", config.server.port); - println!("Database URL: {}", config.database.url); - - // Initialize database connection pool - // This sets the search path to the products schema for all connections - let db = Database::new(&config.database.url, config.database.max_connections).await?; - - // Build the application router with all endpoints - let app = Router::new() - // Product endpoints - .route("/products", get(handlers::list_products)) - .route("/products/{id}", get(handlers::get_product_by_id)) - - // Rating endpoints - .route("/products/{id}/ratings", put(handlers::upsert_rating)) - - // Enable CORS for all routes - // This allows the Angular frontend to make API calls - .layer(CorsLayer::permissive()) - - // Add database pool to application state - // All handlers will have access to this via State extractor - .with_state(db.pool().clone()); - - // Create socket address from configuration - let addr = SocketAddr::from(([0, 0, 0, 0], config.server.port)); - - // Print API documentation - println!("\nProducts Service listening on {}", addr); - println!("\nAvailable endpoints:"); - println!(" GET /products - List products (with pagination & filters)"); - println!(" GET /products/{{id}} - Get product details"); - println!(" PUT /products/{{id}}/ratings - Create/update product rating"); - - // Start the HTTP server - let listener = tokio::net::TcpListener::bind(addr).await?; - axum::serve(listener, app).await?; - - Ok(()) -} diff --git a/distributed_observability_in_rust/example_project/schemas/data/ingest.sh b/distributed_observability_in_rust/example_project/schemas/data/ingest.sh @@ -1,49 +0,0 @@ -#!/bin/sh -# ============================================================ -# Data Ingestion Script -# ============================================================ -# Loads data into PostgreSQL database - -set -e - -echo "=========================================" -echo "Starting data ingestion..." -echo "=========================================" - -# Database connection parameters -DB_HOST="${DB_HOST:-postgres}" -DB_PORT="${DB_PORT:-5432}" -DB_NAME="${DB_NAME:-opentel_db}" -DB_USER="${DB_USER:-opentel_user}" -DB_PASSWORD="${DB_PASSWORD:-opentel_pass}" -WAIT_TIME="${WAIT_TIME:-10}" - -export PGPASSWORD="$DB_PASSWORD" - -echo "Waiting for database to be ready..." -until pg_isready -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d "$DB_NAME"; do - echo "Database is unavailable - sleeping" - sleep 2 -done - -echo "Database is ready!" -echo "" - -# Wait for products service to complete migrations -echo "Waiting ${WAIT_TIME}s for products service migrations to complete..." -sleep "$WAIT_TIME" -echo "" - -# Load data files in order -echo "Loading products test data..." -if [ -f /data/products_test_data.sql ]; then - psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d "$DB_NAME" -f /data/products_test_data.sql - echo "✓ Products test data loaded successfully" -else - echo "⚠ products_test_data.sql not found, skipping..." -fi - -echo "" -echo "=========================================" -echo "Data ingestion completed!" -echo "========================================="