Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/abrarnitk/tokio-newrelic


https://github.com/abrarnitk/tokio-newrelic

actix-newrelic async-newrelic rust-async-newrelic tokio-newrelic

Last synced: 22 days ago
JSON representation

Awesome Lists containing this project

README

        

# tokio-newrelic

## New Relic SDK for async tasks(tokio and actix)
It is an wrapper over the newrelic SDK.

## Usage

```toml
tokio-newrelic = "*"
```

#### Export variables
```shell script
export ENABLE_NEW_RELIC="true"
export NEW_RELIC_LICENSE_KEY="newrelic_license_key"
export NEW_RELIC_APP_NAME="app_name"
```

```rust
use tokio_newrelic;

// actix api function
#[get("/")]
async fn index(_req: HttpRequest) -> impl Responder {
let t = newrelic_transaction_function().await;
HttpResponse::Ok().body(format!("index_page {:?}", t))
}

pub async fn newrelic_transaction_function1() -> Option {
// Mandatory wrapping, with newrelic for setting task scope
// starting a web transaction and storing it to a tokio::Localtask
let r = tokio_newrelic::execute("web_transaction_name", async move {
self::abc1().await;
db_test();
db_test_pooled_connection();
std::thread::sleep(std::time::Duration::from_secs(2));
Some(2)
})
.await;
r
}

pub fn db_test_pooled_connection() {
println!("pg_db_test_pooled_connection");
let database_url = "postgres://[email protected]/acko";
let pooled_conn = tokio_newrelic::pg_pool::connection_with_url(database_url);
query(&pooled_conn);
}

pub fn db_test() {
println!("pg_db_test");
let database_url = "postgres://[email protected]/acko";
let nr_conn = tokio_newrelic::pg::NConnection::establish(database_url)
.expect(&format!("Error connecting to {}", database_url));
query(&nr_conn);
}
```

#### Testing
```shell script
for ((i=1;i<=100;i++)); do seq 1 200 | xargs -n2 -P20 curl "http://127.0.0.1:3000/"; done
```

- Hope that you got an idea, see the example directory for more information.
- This crate is implemented only for datastore segment.

* [ ] Segments
* [x] Datastore
* [ ] Custom
* [ ] External
* [ ] Nesting Segments
* [ ] Overriding timings

## Need to run c-sdk daemon
This crate requires the newrelic daemon to running as per the docs [Newrelic docs][c-sdk];

[c-sdk]: https://docs.newrelic.com/docs/agents/c-sdk/get-started/introduction-c-sdk#architecture

## Newrelic Transaction trace Images

#### Transaction Overview
![Overview](./images/Overview.png)

#### Web Transaction
![Web Transaction](./images/web%20transaction.png)

#### Transaction details
![Transaction details](./images/transaction%20details.png)

#### Database details
![Database](./images/Database.png)

#### Transaction trace
![Transaction trace](./images/transaction%20trace.png)

#### Db queries trace
![Db queries trace](./images/db%20queries%20traces.png)