You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> 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. There are also many features currently supported by the Python SDK which are not yet supported by this SDK; please open issues to help us prioritize these to close this gap.
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
12
From the team behind Pydantic, **Logfire** is an observability platform built on the same belief as our
21
13
open source library — that the most powerful tools can be easy to use.
22
14
15
+
What sets Logfire apart:
16
+
17
+
-**Simple and Powerful:** Logfire's dashboard is simple relative to the power it provides, ensuring your entire engineering team will actually use it.
18
+
-**SQL:** Query your data using standard SQL — all the control and (for many) nothing new to learn. Using SQL also means you can query your data with existing BI tools and database querying libraries.
19
+
-**OpenTelemetry:** Logfire is an opinionated wrapper around OpenTelemetry, allowing you to leverage existing tooling, infrastructure, and instrumentation for many common Python packages, and enabling support for virtually any language. We offer full support for all OpenTelemetry signals (traces, metrics and logs).
20
+
23
21
This repository contains the Rust SDK for instrumenting with Logfire.
24
22
25
23
See also:
@@ -33,35 +31,74 @@ The Logfire server application for recording and displaying data is closed sourc
33
31
34
32
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
33
36
-
Here's a simple manual tracing (aka logging) example:
With a logfire project set up, start by adding the `logfire` crate to your `Cargo.toml`:
44
35
45
-
logfire::info!("Hello, {name}!", name="world");
36
+
```toml
37
+
[dependencies]
38
+
logfire = "0.6"
39
+
```
46
40
47
-
{
48
-
let_span=logfire::span!(
49
-
"Asking the user their {question}",
50
-
question="age",
51
-
).entered();
41
+
Then, you can use the SDK to instrument the code. Here's a simple example which counts the size of files in the current directory, creating spans for the full operation and each file read:
logfire::span!("counting size of {cwd}", cwd=cwd.display().to_string()).in_scope(|| {
60
+
letentries=fs::read_dir(&cwd)?;
61
+
forentryinentries {
62
+
letentry=entry?;
63
+
letpath=entry.path();
64
+
65
+
let_span=logfire::span!(
66
+
"reading {path}",
67
+
path=path
68
+
.strip_prefix(&cwd)
69
+
.unwrap_or(&path)
70
+
.display()
71
+
.to_string()
72
+
)
73
+
.entered();
74
+
75
+
letmetadata=entry.metadata()?;
76
+
ifmetadata.is_file() {
77
+
total_size+=metadata.len();
78
+
}
79
+
}
80
+
Result::Ok(())
81
+
})?;
82
+
83
+
logfire::info!(
84
+
"total size of {cwd} is {size} bytes",
85
+
cwd=cwd.display().to_string(),
86
+
size=total_sizeasi64
87
+
);
59
88
60
89
shutdown_handler.shutdown()?;
61
90
Ok(())
62
91
}
63
92
```
64
93
94
+
(Read the [Logfire concepts documentation](https://logfire.pydantic.dev/docs/concepts/) for additional detail on spans, events, and further Logfire concepts.)
95
+
96
+
See additional examples in the [examples directory](https://github.com/pydantic/logfire-rust/tree/main/examples):
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/).
0 commit comments