-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(new relic): new crate to send logs to New Relic (#4)
- Loading branch information
1 parent
fa6583b
commit 39c3b0c
Showing
10 changed files
with
585 additions
and
5 deletions.
There are no files selected for viewing
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,22 @@ | ||
name: Release DD Tracing Layer | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v*.*.*' | ||
workflow_dispatch: | ||
|
||
jobs: | ||
crates: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Setup Rust | ||
uses: hecrj/setup-rust-action@master | ||
with: | ||
rust-version: stable | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Publish to crates.io | ||
run: | | ||
cargo login ${{secrets.crates_key}} | ||
cargo publish -p dd-tracing-layer |
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,22 @@ | ||
name: Release NR Tracing Layer | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v*.*.*-nr-tracing-layer' | ||
workflow_dispatch: | ||
|
||
jobs: | ||
crates: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Setup Rust | ||
uses: hecrj/setup-rust-action@master | ||
with: | ||
rust-version: stable | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Publish to crates.io | ||
run: | | ||
cargo login ${{secrets.crates_key}} | ||
cargo publish -p nr-tracing-layer |
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,3 +1,3 @@ | ||
[workspace] | ||
resolver = "2" | ||
members = ["log-tracing-layer", "dd-tracing-layer"] | ||
members = ["log-tracing-layer", "dd-tracing-layer", "nr-tracing-layer"] |
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,32 @@ | ||
[package] | ||
name = "nr-tracing-layer" | ||
version = "0.4.0" | ||
authors = ["Roberto Huertas <[email protected]>"] | ||
description = "Send your logs to New Relic" | ||
edition = "2021" | ||
license = "MIT" | ||
repository = "https://github.com/robertohuertasm/log-tracing-layer" | ||
categories = ["development-tools", "asynchronous"] | ||
keywords = ["tracing", "log", "new relic", "layer", "tracing-subscriber"] | ||
|
||
[badges] | ||
maintenance = { status = "actively-developed" } | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
log-tracing-layer = { path = "../log-tracing-layer", version = "0.4.0" } | ||
tracing-subscriber = "0.3" | ||
tracing = "0.1" | ||
reqwest = { version = "0.12", features = ["gzip"] } | ||
tokio = { version = "1", features = ["sync", "rt-multi-thread", "time"] } | ||
serde_json = "1" | ||
chrono = "0.4" | ||
async-trait = "0.1" | ||
async-recursion = "1.0" | ||
libflate = "2.0" | ||
|
||
[dev-dependencies] | ||
dotenvy = "0.15.7" | ||
tracing-subscriber = { version = "0.3", features = ["json", "registry"] } | ||
httpmock = "0.7.0" |
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,48 @@ | ||
# nr-tracing-layer | ||
|
||
[![license](https://img.shields.io/crates/l/nr-tracing-layer?style=for-the-badge)](https://github.com/robertohuertasm/log-tracing-layer/blob/master/LICENSE) | ||
[![crates.io](https://img.shields.io/crates/v/nr-tracing-layer?style=for-the-badge)](https://crates.io/crates/nr-tracing-layer) | ||
[![docs.rs](https://img.shields.io/docsrs/nr-tracing-layer?style=for-the-badge)](https://docs.rs/nr-tracing-layer) | ||
|
||
A [tracing layer](https://tokio.rs/tokio/topics/tracing) that sends logs to the [New Relic Log API](https://docs.newrelic.com/docs/logs/get-started/get-started-log-management/). | ||
|
||
|
||
## Requirements | ||
|
||
You'll need a [New Relic API Key](https://docs.newrelic.com/docs/apis/intro-apis/new-relic-api-keys/) for everything to work. | ||
|
||
## Endpoint | ||
|
||
By default, will try to send the logs to the `US1` region. | ||
|
||
You can easily change the region or provide a custom URL if needed. | ||
|
||
## Example | ||
|
||
Here's a simple example of how to set it up and use it: | ||
|
||
```rust | ||
use nr_tracing_layer::NewRelicOptions; | ||
use tracing_subscriber::prelude::*; | ||
use tracing::{instrument, subscriber} | ||
|
||
#[instrument] | ||
fn log(msg: &'static str) { | ||
tracing::info!("your message: {}", msg); | ||
} | ||
|
||
fn main() { | ||
let options = NewRelicOptions::new("my-service", "my-new-relic-api-key") | ||
.with_tags("env:dev"); | ||
let dd = nr_tracing_layer::create(options); | ||
let subscriber = tracing_subscriber::registry() | ||
.with(tracing_subscriber::fmt::Layer::new().json()) | ||
.with(dd); | ||
let _s = subscriber::set_default(subscriber); | ||
log("hello world!"); | ||
} | ||
``` | ||
|
||
## Caveats | ||
|
||
The layer will send the logs either 5 seconds after the last log is received or when the buffer arrives to 1000 logs. This is basically due to a limitation in the Datadog API. |
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,36 @@ | ||
//! A tracing layer that sends logs to [New Relic](https://docs.newrelic.com/docs/logs/get-started/get-started-log-management/). | ||
//! | ||
//! ## Example | ||
//! | ||
//! ```rust | ||
//! use nr_tracing_layer::NewRelicOptions; | ||
//! use tracing_subscriber::prelude::*; | ||
//! use tracing::{instrument, subscriber}; | ||
//! | ||
//! #[instrument] | ||
//! fn log(msg: &'static str) { | ||
//! tracing::info!("your message: {}", msg); | ||
//! } | ||
//! | ||
//! fn main() { | ||
//! let options = NewRelicOptions::new("my-service", "my-new-relic-api-key") | ||
//! .with_tags("env:dev"); | ||
//! let dd = nr_tracing_layer::create(options); | ||
//! let subscriber = tracing_subscriber::registry() | ||
//! .with(tracing_subscriber::fmt::Layer::new().json()) | ||
//! .with(dd); | ||
//! let _s = subscriber::set_default(subscriber); | ||
//! log("hello world!"); | ||
//! } | ||
//!``` | ||
mod new_relic_ingestor; | ||
|
||
pub use log_tracing_layer::LogLayer; | ||
pub use new_relic_ingestor::{NewRelicOptions, Region}; | ||
|
||
/// Creates a log layer that will send logs to New Relic. | ||
#[must_use] | ||
pub fn create(options: NewRelicOptions) -> LogLayer { | ||
let ingestor = new_relic_ingestor::NewRelicLogIngestor::new(options); | ||
LogLayer::new(ingestor) | ||
} |
Oops, something went wrong.