xtrace-client 0.0.3

Rust client (SDK) for the xtrace HTTP service.
Documentation

xtrace-client

这是 xtrace 服务端(HTTP API)的 Rust SDK。

安装

已发布到 crates.io:

[dependencies]
xtrace-client = "0.0.3"

使用

use xtrace_client::{Client, MetricsQueryParams, MetricPoint, TraceListQuery};
use chrono::Utc;
use std::collections::HashMap;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let client = Client::new("http://127.0.0.1:8742/", "YOUR_TOKEN")?;

    client.healthz().await?;

    let traces = client.list_traces(&TraceListQuery::default()).await?;
    println!("{}", traces.data.len());

    // Nebula metrics: 写入
    let mut labels = HashMap::new();
    labels.insert("service".to_string(), "nebula".to_string());
    client
        .push_metrics(&[MetricPoint {
            name: "nebula.qps".to_string(),
            labels,
            value: 1.0,
            timestamp: Utc::now(),
        }])
        .await?;

    // Nebula metrics: names/query
    let _names = client.metrics_names().await?;
    let _series = client
        .metrics_query(&MetricsQueryParams {
            name: "nebula.qps".to_string(),
            ..Default::default()
        })
        .await?;

    Ok(())
}

目前封装的接口:

  • healthz
  • ingest_batch(POST /v1/l/batch)
  • list_traces(GET /api/public/traces)
  • get_trace(GET /api/public/traces/:traceId)
  • metrics_daily(GET /api/public/metrics/daily)
  • push_metrics(POST /v1/metrics/batch)
  • metrics_names(GET /api/public/metrics/names)
  • metrics_query(GET /api/public/metrics/query)