Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust #741

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Rust #741

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
91 changes: 91 additions & 0 deletions docs/shipping/Code/rustsdk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
---
id: Rust
title: Rust
overview: Deploy this integration to collect logs from your Rust application.
product: ['logs']
os: ['windows', 'linux']
filters: ['Code']
logo: https://logzbucket.s3.eu-west-1.amazonaws.com/logz-docs/shipper-logos/rust-logo-blk.svg
logs_dashboards: []
logs_alerts: []
logs2metrics: []
metrics_dashboards: []
metrics_alerts: []
drop_filter: []
---

:::note
If you need an example aplication to test this integration, please refer to our [Rust OpenTelemetry repository](https://github.com/logzio/opentelemetry-examples/tree/main/rust/logs).
:::

This guide explains how to configure your Rust application to send logs to Logz.io via OpenTelemetry.

## Prerequisites

* A Rust application with logging capabilities.
* An active Logz.io account
* Your log shipping token
* Port `8071` available on your host system


## Add Dependencies

To send logs to Logz.io via OpenTelemetry, add the required dependencies to your `Cargo.toml` file:

```toml
[dependencies]
log = "0.4"
opentelemetry = "0.27"
opentelemetry-appender-log = "0.27"
opentelemetry_sdk = { version = "*", features = ["rt-tokio"] }
opentelemetry-otlp = { version = "*", features = ["http-proto", "reqwest-client", "reqwest-rustls"] }
rand = "0.8"
tokio = { version = "1", features = ["full"] }
```

## Configure Logging and Implement OTLP Communication

Import the following modules into your existing app:

```rust
use rand::Rng;
use opentelemetry_appender_log::OpenTelemetryLogBridge;
use opentelemetry_otlp::{WithExportConfig, WithHttpConfig};
use std::collections::HashMap;
```

Add the exporters and logger provider section to your code:

```rust
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {

let endpoint = "https://otlp-listener.logz.io/v1/logs";
let api_token = "LOGZ_IO_TOKEN";
cycode-security[bot] marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cycode: Secret of type: 'Generic Password' was found.
Severity: Medium
Confidence Score: 92%

Description

A generic secret or password is an authentication token used to access a computer or application and is assigned to a password variable.

Cycode Remediation Guideline

❗ How to revoke


  • Change the password or secret in the system or application where it is used.
  • Update any services, applications, or scripts that use the old password or secret with the new one.
  • Invalidate any sessions or tokens that were authenticated using the old password or secret.

Tell us what how you wish to proceed using one of the following commands:

Tag Short Description
#cycode_secret_ignore_here Applies to this request only
#cycode_secret_revoked Applies to this secret value for all repos in your organization
#cycode_secret_false_positive Applies to this secret value for all repos in your organization

⚠️ When commenting on Github, you may need to refresh the page to see the latest updates.


let logger_provider = opentelemetry_sdk::logs::LoggerProvider::builder()
.with_batch_exporter(
opentelemetry_otlp::LogExporter::builder()
.with_http()
.with_endpoint(endpoint)
.with_headers(HashMap::from([
("Authorization".to_string(), format!("Bearer {}", api_token), ),
("User-Agent".to_string(), format!("logzio-rust-logs-otlp"), ),
]))
.build()?,
opentelemetry_sdk::runtime::Tokio,
)
.build();

let log_bridge = OpenTelemetryLogBridge::new(&logger_provider);

```

Replace `LOGZ_IO_TOKEN` with the shipping token of the account.

If needed, update the `https://otlp-listener.logz.io/v1/logs` with the URL of [your hosting region](https://docs.logz.io/docs/user-guide/admin/hosting-regions/account-region/#opentelemetry-protocol-otlp-regions).

## Run the application and check Logz.io for logs

Run your application with `cargo run`. Give your logs some time to get from your system to ours.

Encounter an issue? See our [log shipping troubleshooting](https://docs.logz.io/docs/user-guide/log-management/troubleshooting/log-shipping-troubleshooting/) guide.
2 changes: 1 addition & 1 deletion static/manifest.json

Large diffs are not rendered by default.

Loading