-
Notifications
You must be signed in to change notification settings - Fork 28
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
7 changed files
with
164 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,12 @@ members = [ | |
|
||
[package] | ||
name = "tracing-loki" | ||
description = "A tracing layer for shipping logs to Grafana Loki" | ||
authors = ["hrxi <[email protected]>"] | ||
repository = "https://github.com/hrxi/tracing-loki" | ||
keywords = ["tracing", "loki"] | ||
version = "0.0.1" | ||
license = "MIT/Apache-2.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
|
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,56 @@ | ||
tracing-loki | ||
============ | ||
|
||
A [tracing](https://github.com/tokio-rs/tracing) layer for [Grafana | ||
Loki](https://grafana.com/oss/loki/). | ||
|
||
Documentation | ||
------------- | ||
|
||
https://docs.rs/tracing-loki | ||
|
||
Usage | ||
----- | ||
|
||
Add this to your `Cargo.toml`: | ||
```toml | ||
[dependencies] | ||
tracing-loki = "0.1" | ||
``` | ||
|
||
Example | ||
------- | ||
|
||
```rust | ||
use tracing_subscriber::layer::SubscriberExt; | ||
use tracing_subscriber::util::SubscriberInitExt; | ||
use url::Url; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), tracing_loki::Error> { | ||
let (layer, task) = tracing_loki::layer( | ||
Url::parse("http://127.0.0.1:3100").unwrap(), | ||
vec![("host".into(), "mine".into())].into_iter().collect(), | ||
vec![].into_iter().collect(), | ||
)?; | ||
|
||
// We need to register our layer with `tracing`. | ||
tracing_subscriber::registry() | ||
.with(layer) | ||
// One could add more layers here, for example logging to stdout: | ||
// .with(tracing_subscriber::fmt::Layer::new()) | ||
.init(); | ||
|
||
// The background task needs to be spawned so the logs actually get | ||
// delivered. | ||
tokio::spawn(task); | ||
|
||
tracing::info!( | ||
task = "tracing_setup", | ||
result = "success", | ||
"tracing successfully set up", | ||
); | ||
|
||
Ok(()) | ||
} | ||
``` |
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 |
---|---|---|
@@ -1,6 +1,11 @@ | ||
[package] | ||
name = "loki-api" | ||
description = "Protobuf types used by the Grafana Loki HTTP API" | ||
authors = ["hrxi <[email protected]>"] | ||
repository = "https://github.com/hrxi/tracing-loki" | ||
keywords = ["tracing", "loki"] | ||
version = "0.0.1" | ||
license = "MIT/Apache-2.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
|
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 |
---|---|---|
@@ -1,6 +1,11 @@ | ||
[package] | ||
name = "loki-api-generate" | ||
version = "0.1.0" | ||
description = "Code generation for loki-api" | ||
authors = ["hrxi <[email protected]>"] | ||
repository = "https://github.com/hrxi/tracing-loki" | ||
keywords = ["tracing", "loki"] | ||
version = "0.0.1" | ||
license = "MIT/Apache-2.0" | ||
edition = "2021" | ||
|
||
[build-dependencies] | ||
|
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