about summary refs log tree commit diff
path: root/ops/yandex-cloud-rs/examples/log-write.rs
blob: 84d183421ae9ca3db164372e4c490b51116e0253 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//! This example uses the Yandex Cloud Logging API to write a log entry.

use prost_types::Timestamp;
use tonic::transport::channel::Endpoint;
use yandex_cloud::yandex::cloud::logging::v1::destination::Destination;
use yandex_cloud::yandex::cloud::logging::v1::log_ingestion_service_client::LogIngestionServiceClient;
use yandex_cloud::yandex::cloud::logging::v1::Destination as OuterDestination;
use yandex_cloud::yandex::cloud::logging::v1::IncomingLogEntry;
use yandex_cloud::yandex::cloud::logging::v1::WriteRequest;
use yandex_cloud::AuthInterceptor;

#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let channel = Endpoint::from_static("https://ingester.logging.yandexcloud.net")
        .connect()
        .await?;

    let mut client = LogIngestionServiceClient::with_interceptor(
        channel,
        AuthInterceptor::new("YOUR_TOKEN_HERE"),
    );

    let request = WriteRequest {
        destination: Some(OuterDestination {
            destination: Some(Destination::LogGroupId("YOUR_LOG_GROUP_ID".into())),
        }),
        entries: vec![IncomingLogEntry {
            timestamp: Some(Timestamp::date_time(2023, 04, 24, 23, 44, 30).unwrap()),
            message: "test log message".into(),
            ..Default::default()
        }],
        ..Default::default()
    };

    client.write(request).await.unwrap();
    Ok(())
}