Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 51 additions & 29 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
name: CI
permissions:
contents: read

on:
pull_request:
Expand All @@ -25,6 +27,7 @@ jobs:
- fmt
- check-features
- test
- build-targets
- minimal-versions
steps:
- run: exit 0
Expand Down Expand Up @@ -66,7 +69,7 @@ jobs:
- name: Check minimal versions
env:
# empty those flags!
RUSTFLAGS:
RUSTFLAGS: ""
run: |
# Remove dev-dependencies from Cargo.toml to prevent the next `cargo update`
# from determining minimal versions based on dev-dependencies.
Expand Down Expand Up @@ -192,8 +195,10 @@ jobs:
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Install cargo-nextest
uses: taiki-e/install-action@cargo-nextest
- name: Test unstable
run: cargo test --all-features
run: cargo nextest run --all-features
env:
RUSTFLAGS: -Dwarnings --cfg tokio_unstable --cfg foundations_unstable
_RJEM_MALLOC_CONF: prof:true
Expand All @@ -211,32 +216,23 @@ jobs:
- name: Run example (dry run)
run: cargo run --example http_server -- --dry-run --config examples/http_server/example_conf.yaml

test:
name: Test
build-targets:
name: Build
runs-on: ${{ matrix.os }}
strategy:
matrix:
thing:
- x86_64-linux
- aarch64-linux
- arm64-android
- arm-android
- aarch64-ios
- x86_64-macos
- x86_64-windows
include:
- apt_packages: ""
- custom_env: {}
- build_only: false
- cargo_args: ""

- thing: x86_64-linux
target: x86_64-unknown-linux-gnu
rust: stable
os: ubuntu-latest

- thing: aarch64-linux
build_only: true
target: aarch64-unknown-linux-gnu
rust: stable
os: ubuntu-latest
Expand All @@ -247,33 +243,24 @@ jobs:
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-g++

- thing: arm64-android
build_only: true
target: aarch64-linux-android
rust: stable
os: ubuntu-latest
cargo_args: --no-default-features --features server-client-common-default

- thing: arm-android
build_only: true
target: armv7-linux-androideabi
rust: stable
os: ubuntu-latest
cargo_args: --no-default-features --features server-client-common-default

- thing: aarch64-ios
build_only: true
target: aarch64-apple-ios
rust: stable
os: macos-latest
cargo_args: --no-default-features --features server-client-common-default

- thing: x86_64-macos
target: x86_64-apple-darwin
rust: stable
os: macos-latest

- thing: x86_64-windows
build_only: true
target: x86_64-pc-windows-msvc
rust: stable
os: windows-latest
Expand All @@ -296,13 +283,48 @@ jobs:
- name: Set Android Linker path
if: endsWith(matrix.thing, '-android')
run: echo "CARGO_TARGET_$(echo ${{ matrix.target }} | tr \\-a-z _A-Z)_LINKER=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/$(echo ${{ matrix.target }} | sed s/armv7/armv7a/)21-clang++" >> "$GITHUB_ENV"
- name: Build tests
# We `build` because we want the linker to verify we are cross-compiling correctly for check-only targets.
run: cargo build --target ${{ matrix.target }} ${{matrix.cargo_args}}
- name: Build
run: cargo build -p foundations --target ${{ matrix.target }} ${{matrix.cargo_args}}
shell: bash
env: ${{ matrix.custom_env }}
- name: Run tests
if: "!matrix.build_only"
run: _RJEM_MALLOC_CONF=prof:true cargo test --target ${{ matrix.target }} ${{matrix.cargo_args}}

test:
name: Test
runs-on: ${{ matrix.os }}
strategy:
matrix:
thing:
- x86_64-linux
- x86_64-macos
include:
- thing: x86_64-linux
target: x86_64-unknown-linux-gnu
rust: stable
os: ubuntu-latest

- thing: x86_64-macos
target: x86_64-apple-darwin
rust: stable
os: macos-latest

steps:
- uses: actions/checkout@v4
with:
submodules: "recursive"
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
- name: Install cargo-nextest
uses: taiki-e/install-action@cargo-nextest
- name: Run foundations tests
run: _RJEM_MALLOC_CONF=prof:true cargo nextest run --target ${{ matrix.target }}
shell: bash
- name: Run panic_hook tests with no default features
run: _RJEM_MALLOC_CONF=prof:true cargo nextest run -p foundations --test panic_hook --no-default-features --target ${{ matrix.target }}
shell: bash
- name: Run sentry_hook tests with no default features
run: _RJEM_MALLOC_CONF=prof:true cargo nextest run -p foundations --test sentry_hook --no-default-features --features sentry --target ${{ matrix.target }}
shell: bash
env: ${{ matrix.custom_env }}
20 changes: 20 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# AGENTS.md

## Build & Test Commands
- Build: `cargo build`
- Test all: `cargo nextest run`
- Test single: `cargo nextest run <test_name>` or `cargo nextest run --test <file> <test_name>`
- Clippy: `cargo clippy --all-targets -- -D warnings -D unreachable_pub -D clippy::await_holding_lock -D clippy::clone_on_ref_ptr`
- Format: `cargo fmt --all`
- Lint fix: `./scripts/lint-fix.sh`
- Feature check: `cargo hack check --feature-powerset --no-dev-deps --depth 1`

## Code Style
- Rust 2021 edition, use `rustfmt` defaults
- Imports: group std, external crates, then internal modules; use `crate::` for internal imports
- Types: prefer `Box<dyn Error + Send + Sync>` for generic errors; use `anyhow::Result` for bootstrap errors
- Naming: snake_case for functions/variables, PascalCase for types, SCREAMING_SNAKE for constants
- Errors: use `BootstrapResult<T>` (anyhow) for initialization, `Result<T>` (boxed error) for runtime
- Docs: add `///` doc comments for public items; `#![warn(missing_docs)]` is enabled
- Feature flags: wrap platform/optional code with `#[cfg(feature = "...")]`
- No `openssl`/`openssl-sys` - use `boring`, `ring`, or `rustls` instead
9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ reqwest = { version = "0.12", default-features = false }
socket2 = { version = "0.5", features = ["all"] }
syn = "2"
serde = "1"
serde_json = "1"
serde_path_to_error = "0.1.17"
serde_yaml = "0.8.26"
serde_with = "3.3"
Expand All @@ -91,6 +92,14 @@ tower-service = "0.3"
tracing-slog = "0.3.0"
tracing-subscriber = "0.3"
yaml-merge-keys = { version = "0.5", features = ["serde_yaml"] }
sentry-core = { version = "0.36", default-features = false }
sentry = { version = "0.36", default-features = false, features = [
"backtrace",
"contexts",
"panic",
"ureq",
"rustls",
] }

# needed for minver
async-stream = "0.3"
Expand Down
7 changes: 7 additions & 0 deletions foundations/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@ platform-common-default = [
"testing",
"settings_deny_unknown_fields_by_default",
"panic_on_too_much_logger_nesting",
"sentry",
]

# Sentry integration for fatal error tracking
sentry = ["dep:sentry-core"]

# A subset of features that can be used both on server and client sides. Useful for libraries
# that can be used either way.
server-client-common-default = ["settings", "client-telemetry", "testing"]
Expand Down Expand Up @@ -209,6 +213,7 @@ prometheus-client = { workspace = true, optional = true }
prometools = { workspace = true, optional = true, features = ["serde"] }
rand = { workspace = true, optional = true }
serde = { workspace = true, optional = true, features = ["derive", "rc"] }
serde_json = { workspace = true }
serde_path_to_error = { workspace = true, optional = true }
serde_yaml = { workspace = true, optional = true }
serde_with = { workspace = true, optional = true }
Expand All @@ -231,6 +236,7 @@ tikv-jemallocator = { workspace = true, optional = true, features = [
yaml-merge-keys = { workspace = true, optional = true, features = [
"serde_yaml",
] }
sentry-core = { workspace = true, optional = true }

# needed for minver purposes
async-stream = { workspace = true, optional = true }
Expand Down Expand Up @@ -261,6 +267,7 @@ tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
ipnetwork = { workspace = true }
nix = { workspace = true , features = ["fs"] }
tracing-subscriber = { workspace = true }
sentry = { workspace = true }

[build-dependencies]
bindgen = { workspace = true, features = ["runtime"], optional = true }
Expand Down
18 changes: 18 additions & 0 deletions foundations/src/alerts/metrics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//! Panic and sentry event related metrics.

use super::Level;
use crate::telemetry::metrics::Counter;

/// Panic metrics.
#[crate::telemetry::metrics::metrics(crate_path = "crate", unprefixed)]
pub mod panics {
/// Total number of panics observed.
pub fn total() -> Counter;
}

/// Sentry metrics.
#[crate::telemetry::metrics::metrics(crate_path = "crate", unprefixed)]
pub mod sentry_events {
/// Total number of sentry events observed.
pub fn total(level: Level) -> Counter;
}
Loading
Loading