-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
1,255 additions
and
62 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[package] | ||
name = "googlelog" | ||
version = "0.1.0" | ||
edition = "2021" | ||
authors = [ | ||
"Rob klein Gunnewiek <[email protected]>" | ||
] | ||
|
||
[features] | ||
shipper = [] | ||
|
||
[dependencies] | ||
google-logging2 = "5.0.5" | ||
serde_json = "1.0.117" | ||
chrono = "0.4.38" | ||
tokio = { version = "1.38.0", features = ["macros", "time", "rt-multi-thread"] } | ||
slog = "2.7.0" | ||
thiserror = "1.0.61" | ||
reqwest = { version = "0.12.5", default-features = false, features = ["rustls-tls", "json"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use thiserror; | ||
|
||
use reqwest::{self, StatusCode}; | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
pub enum Error { | ||
#[error("Failed to read the 'default_labels' object from the JSON file, does it exist by this name?. Parse error: {0}")] | ||
DefaultLabelsError(serde_json::Error), | ||
#[error("Failed to read the 'resource_labels' object from the JSON file, does it exist by this name?. Parse error: {0}")] | ||
ResourceLabelsError(serde_json::Error), | ||
#[error("Serde JSON serialization failed with context '{context}'. Error: {source}")] | ||
ShipperSerializeError { | ||
context: String, | ||
source: serde_json::Error, | ||
}, | ||
#[error("Reqwest error with context '{context}'. Error: {source}")] | ||
ShipperReqwestError { | ||
context: String, | ||
source: reqwest::Error, | ||
}, | ||
#[error("No 'access_token' found in the metadata server response body")] | ||
ShipperTokenNotFound, | ||
#[error("No 'expires_in' found in the metadata server response body")] | ||
ShipperTokenExpiryNotFound, | ||
#[error("unsuccessful HTTP response error with context '{context}'. HTTP status code: '{status}', body: '{body}'")] | ||
HttpResponseError { | ||
context: String, | ||
status: StatusCode, | ||
body: String, | ||
}, | ||
} | ||
|
||
impl From<reqwest::Error> for Error { | ||
fn from(err: reqwest::Error) -> Self { | ||
Self::ShipperReqwestError { | ||
context: "Error sending HTTP request".to_string(), | ||
source: err, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//! An implemention of [`slog::Drain`](https://slog-rs.github.io/slog/slog/trait.Drain.html) for logging to [Google Cloud](https://cloud.google.com/logging). | ||
//! | ||
//! # Usage | ||
//! | ||
//! Warning: Currently, this library only works in the context of [workload identity](https://cloud.google.com/iam/docs/workload-identity-federation). | ||
//! | ||
//! The `googlelog` drain creates log entries compatible with [Google Cloud Logging](https://cloud.google.com/logging). | ||
//! Depending on how you want to ship these logs to the Google Logging API, you can choose from one of the available build methods. | ||
//! | ||
//! Start by configuring the Logger with the builder ([`Builder`](logger::Builder::new)) and selecting the appropriate build method based on your shipping requirements: | ||
//! | ||
//! 1. [`build()`](logger::Builder::build): Receives [`WriteLogEntries`](https://cloud.google.com/logging/docs/reference/v2/rpc/google.logging.v2#google.logging.v2.LoggingServiceV2.WriteLogEntries) over a channel and allows you to handle the transportation manually. | ||
//! 2. [`build_with_async_shipper()`](logger::Builder::build_with_async_shipper): Offloads transportation to the [`Shipper`](shipper::Shipper) and its sync-async Bridge in an async context. (Requires the `shipper` feature.) | ||
//! | ||
//! The [`builder`](struct@logger::Builder) supports several `with_*` methods to customize the log message format, | ||
//! particularly the default labels attached to [log entries](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry). | ||
//! | ||
/// Googlelog Error types | ||
pub mod error; | ||
|
||
/// The [`slog::Drain`](https://slog-rs.github.io/slog/slog/trait.Drain.html) Implementation of the slog Drain for [Google Cloud Logging](https://cloud.google.com/logging) | ||
pub mod logger; | ||
|
||
/// An optional async process to ship the log for you | ||
#[cfg(feature = "shipper")] | ||
pub mod shipper; |
Oops, something went wrong.