npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@untrace/sdk-rust

v0.1.2

Published

LLM observability SDK for Rust

Downloads

6

Readme

Untrace SDK for Rust

LLM observability and tracing SDK for Rust applications.

Features

  • OpenTelemetry-based tracing
  • Automatic instrumentation for LLM providers
  • Custom span creation and management
  • Metrics collection
  • Workflow tracking
  • Error handling and reporting

Installation

Add this to your Cargo.toml:

[dependencies]
untrace-sdk = "0.1.2"

Quick Start

use untrace::{init, Config};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Initialize the SDK
    let config = Config::new("your-api-key".to_string());
    let untrace = init(config).await?;

    // Create a span
    let span = untrace.tracer().start_span("my-operation");
    // ... your code here ...
    span.end();

    // Shutdown
    untrace.shutdown().await?;
    Ok(())
}

Configuration

Basic Configuration

use untrace::Config;

let config = Config::new("your-api-key".to_string())
    .with_service_name("my-app".to_string())
    .with_service_version("1.0.0".to_string())
    .with_environment("production".to_string())
    .with_debug(true);

Environment Variables

You can also configure the SDK using environment variables:

export UNTRACE_API_KEY="your-api-key"
export UNTRACE_SERVICE_NAME="my-app"
export UNTRACE_SERVICE_VERSION="1.0.0"
export UNTRACE_ENVIRONMENT="production"
export UNTRACE_DEBUG="true"
export UNTRACE_SAMPLING_RATE="0.5"

Then initialize with:

use untrace::init_from_env;

let untrace = init_from_env().await?;

Tracing

Basic Spans

let span = untrace.tracer().start_span("my-operation");
// ... your code here ...
span.end();

LLM Spans

use untrace::{LLMSpanOptions, LLMOperationType};

let options = LLMSpanOptions {
    provider: "openai".to_string(),
    model: "gpt-4".to_string(),
    operation: LLMOperationType::Chat,
    prompt_tokens: Some(100),
    completion_tokens: Some(50),
    total_tokens: Some(150),
    temperature: Some(0.7),
    ..Default::default()
};

let span = untrace.tracer().start_llm_span("llm-chat", options);
// ... your LLM code here ...
span.end();

Workflows

use untrace::{WorkflowOptions};
use std::collections::HashMap;

let mut metadata = HashMap::new();
metadata.insert("user_id".to_string(), "user123".to_string());

let options = WorkflowOptions {
    user_id: Some("user123".to_string()),
    session_id: Some("session456".to_string()),
    version: Some("1.0.0".to_string()),
    parent_id: None,
    metadata,
};

let workflow = untrace.context().start_workflow(
    "my-workflow".to_string(),
    untrace.context().generate_run_id(),
    options,
)?;

// Create a workflow span
let span = untrace.tracer().start_workflow_span(&workflow);
// ... your workflow code here ...
span.end();

// End the workflow
untrace.context().end_current_workflow()?;

Metrics

use untrace::{TokenUsage, Cost};

// Record token usage
let usage = TokenUsage {
    prompt_tokens: 100,
    completion_tokens: 50,
    total_tokens: 150,
    model: "gpt-4".to_string(),
    provider: "openai".to_string(),
};
untrace.metrics().record_token_usage(usage)?;

// Record cost
let cost = Cost {
    prompt: 0.01,
    completion: 0.02,
    total: 0.03,
    currency: "USD".to_string(),
    model: "gpt-4".to_string(),
    provider: "openai".to_string(),
};
untrace.metrics().record_cost(cost)?;

// Record latency
let duration = std::time::Duration::from_millis(500);
let mut attributes = HashMap::new();
attributes.insert("operation".to_string(), "llm_call".to_string());
untrace.metrics().record_latency(duration, attributes)?;

Examples

See the examples/ directory for more detailed examples:

  • basic.rs - Basic usage
  • environment.rs - Environment-based configuration
  • instrumentation.rs - Instrumentation and workflows

Run an example:

cargo run --example basic

License

MIT