Skip to content

Commit f86ff67

Browse files
authored
expand detail in README (#5)
1 parent 2b0be08 commit f86ff67

File tree

2 files changed

+96
-8
lines changed

2 files changed

+96
-8
lines changed

README.md

+82-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,83 @@
1-
# Rust SDK for logfire
1+
# Rust SDK for Pydantic Logfire
22

3-
This is currently a WIP alpha; an initial release is coming soon and we look forward to your feedback!
3+
<p align="center">
4+
<a href="https://github.com/pydantic/logfire-rust/actions?query=event%3Apush+branch%3Amain+workflow%3ACI"><img src="https://github.com/pydantic/logfire-rust/actions/workflows/main.yml/badge.svg?event=push" alt="CI" /></a>
5+
<a href="https://codecov.io/gh/pydantic/logfire-rust"><img src="https://codecov.io/gh/pydantic/logfire-rust/graph/badge.svg?token=735CNGCGFD" alt="codecov" /></a>
6+
<a href="https://crates.io/crates/logfire"><img src="https://img.shields.io/crates/v/logfire.svg?logo=rust" alt="crates.io" /></a>
7+
<a href="https://github.com/pydantic/logfire-rust/blob/main/LICENSE"><img src="https://img.shields.io/github/license/pydantic/logfire-rust.svg" alt="license" /></a>
8+
<a href="https://github.com/pydantic/logfire"><img src="https://img.shields.io/crates/msrv/logfire.svg?logo=rust" alt="MSRV" /></a>
9+
<a href="https://logfire.pydantic.dev/docs/join-slack/"><img src="https://img.shields.io/badge/Slack-Join%20Slack-4A154B?logo=slack" alt="Join Slack" /></a>
10+
</p>
11+
12+
> ***Initial release - feedback wanted!***
13+
>
14+
> This is an initial release of the Logfire Rust SDK. We've been using it internally to build Logfire for some time, and it is serving us well. As we're using it ourselves in production, we figured it's ready for everyone else also using Logfire.
15+
>
16+
> We are continually iterating to make this SDK better. We'd love your feedback on all aspects of the SDK and are keen to make the design as idiomatic and performant as possible.
17+
>
18+
> In particular, the current coupling to `tracing` is an open design point. By building on top of tracing we get widest compatibility and a relatively simple SDK, however to make Logfire-specific adjustments we might prefer in future to move `tracing` to be an optional integration.
19+
20+
From the team behind Pydantic, **Logfire** is an observability platform built on the same belief as our
21+
open source library — that the most powerful tools can be easy to use.
22+
23+
This repository contains the Rust SDK for instrumenting with Logfire.
24+
25+
See also:
26+
- The [SDK documentation on docs.rs](https://docs.rs/logfire) for an API reference for this library.
27+
- The [Logfire documentation](https://logfire.pydantic.dev/docs/) for more information about Logfire in general.
28+
- The [Logfire GitHub repository](https://github.com/pydantic/logfire) for the source of the documentation, the Python SDK and an issue tracker for general questions about Logfire.
29+
30+
The Logfire server application for recording and displaying data is closed source.
31+
32+
## Using Logfire's Rust SDK
33+
34+
First [set up a Logfire project](https://logfire.pydantic.dev/docs/#logfire) and [create a write token](https://logfire.pydantic.dev/docs/how-to-guides/create-write-tokens/). You'll need to set this token as an environment variable (`LOGFIRE_TOKEN`) to export to Logfire.
35+
36+
Here's a simple manual tracing (aka logging) example:
37+
38+
```rust
39+
40+
fn main() -> Result<(), Box<dyn std::error::Error>> {
41+
let shutdown_handler = logfire::configure()
42+
.install_panic_handler()
43+
.send_to_logfire(true)
44+
.console_mode(logfire::ConsoleMode::Fallback)
45+
.finish()?;
46+
47+
logfire::info!("Hello, {name}!", name = "world");
48+
49+
{
50+
let _span = logfire::span!(
51+
"Asking the user their {question}",
52+
question = "age",
53+
).entered();
54+
55+
println!("When were you born [YYYY-mm-dd]?");
56+
let mut dob = String::new();
57+
std::io::stdin().read_line(&mut dob)?;
58+
59+
logfire::debug!("dob={dob}", dob = dob.trim());
60+
}
61+
62+
shutdown_handler.shutdown()?;
63+
Ok(())
64+
}
65+
```
66+
67+
### Integration
68+
69+
Logfire's Rust SDK is currently built directly upon [`tracing`](https://docs.rs/tracing/latest/tracing/) and [`opentelemetry`](https://github.com/open-telemetry/opentelemetry-rust/).
70+
71+
This means that anything instrumented using `tracing` will just work with `logfire` (however this SDK's macros contain some additional customizations on top of `tracing` for best support directly on the Logfire platform).
72+
73+
There is also an integration with `log`, so anything using `log` will also be captured by Logfire.
74+
75+
## Contributing
76+
77+
We'd love anyone interested to contribute to the Logfire SDK!
78+
79+
Please send us all your feedback and ideas about the current design and functionality of this SDK. Code contributions are also very welcome!
80+
81+
## Reporting a Security Vulnerability
82+
83+
See our [security policy](https://github.com/pydantic/logfire-rust/security).

examples/basic.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,27 @@ static BASIC_COUNTER: LazyLock<Counter<u64>> = LazyLock::new(|| {
99
.build()
1010
});
1111

12-
fn main() {
12+
fn main() -> Result<(), Box<dyn std::error::Error>> {
1313
let shutdown_handler = logfire::configure()
1414
.install_panic_handler()
1515
.send_to_logfire(true)
1616
.console_mode(logfire::ConsoleMode::Fallback)
17-
.finish()
18-
.expect("Failed to configure logfire");
17+
.finish()?;
1918

2019
logfire::info!("Hello, world!");
2120

21+
{
22+
let _span = logfire::span!("Asking the user their {question}", question = "age").entered();
23+
24+
println!("When were you born [YYYY-mm-dd]?");
25+
let mut dob = String::new();
26+
std::io::stdin().read_line(&mut dob)?;
27+
28+
logfire::debug!("dob={dob}", dob = dob.trim());
29+
}
30+
2231
BASIC_COUNTER.add(1, &[KeyValue::new("process", "abc123")]);
2332

24-
shutdown_handler
25-
.shutdown()
26-
.expect("Failed to shutdown logfire");
33+
shutdown_handler.shutdown()?;
34+
Ok(())
2735
}

0 commit comments

Comments
 (0)