|
5 | 5 |
|
6 | 6 | //! # Rust SDK for Pydantic Logfire
|
7 | 7 | //!
|
8 |
| -//! This goal of this SDK is to provide a first-class experience instrumenting Rust code for the Pydantic Logfire platform. |
| 8 | +//! This SDK provides a first-class experience instrumenting Rust code for the Pydantic Logfire platform. |
9 | 9 | //!
|
10 | 10 | //! The most important API is [`logfire::configure()`][configure], which is used to set up
|
11 | 11 | //! integrations with `tracing` and `log`, as well as exporters for `opentelemetry`. Code
|
|
20 | 20 | //! See also:
|
21 | 21 | //! - The [integrations](#integrations) section below for more information on the relationship of
|
22 | 22 | //! this SDK to other libraries.
|
| 23 | +//! - The [examples][usage::examples] subchapter of this documentation. |
23 | 24 | //! - The [Logfire documentation](https://logfire.pydantic.dev/docs/) for more information about Logfire in general.
|
24 | 25 | //! - 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.
|
25 | 26 | //!
|
26 |
| -//! > ***Initial release - feedback wanted!*** |
27 |
| -//! > |
28 |
| -//! > This is an initial release of the Logfire Rust SDK. We've been using it internally to build |
29 |
| -//! > Logfire for some time, and it is serving us well. As we're using it ourselves in production, |
30 |
| -//! > we figured it's ready for everyone else also using Logfire. |
31 |
| -//! > |
32 |
| -//! > We are continually iterating to make this SDK better. We'd love your feedback on all aspects |
33 |
| -//! > of the SDK and are keen to make the design as idiomatic and performant as possible. There are |
34 |
| -//! > also many features currently supported by the Python SDK which are not yet supported by this |
35 |
| -//! > SDK; please open issues to help us prioritize these to close this gap. For example, we have not |
36 |
| -//! > yet implemented scrubbing in this Rust SDK, although we are aware it is important! |
37 |
| -//! > |
38 |
| -//! > In particular, the current coupling to `tracing` is an open design point. By building on top |
39 |
| -//! > of tracing we get widest compatibility and a relatively simple SDK, however to make |
40 |
| -//! > Logfire-specific adjustments we might prefer in future to move `tracing` to be an optional |
41 |
| -//! > integration. |
| 27 | +//! # Usage |
| 28 | +//! |
| 29 | +//! See below for a quick summary of how to use this SDK. The [usage guide][usage] contains more detailed |
| 30 | +//! information about how to use this SDK to its full potential. |
42 | 31 | //!
|
43 | 32 | //! ## Getting Started
|
44 | 33 | //!
|
45 |
| -//! To use Logfire in your Rust project, add the following to your `Cargo.toml`: |
| 34 | +//! To use `logfire` in your Rust project, add the following to your `Cargo.toml`: |
46 | 35 | //!
|
47 | 36 | //! ```toml
|
48 | 37 | //! [dependencies]
|
49 | 38 | #![doc = concat!("logfire = \"", env!("CARGO_PKG_VERSION"), "\"\n")]
|
50 | 39 | //! ```
|
51 | 40 | //!
|
52 |
| -//! Then, in your Rust code, add a call to `logfire::configure()` at the beginning of your program: |
| 41 | +//! Then, in your Rust code, add a call to [`logfire::configure()`][configure] at the beginning of your program: |
53 | 42 | //!
|
54 | 43 | //! ```rust
|
55 |
| -#![doc = include_str!("../examples/basic.rs")] |
| 44 | +//! fn main() -> Result<(), Box<dyn std::error::Error>> { |
| 45 | +//! let shutdown_handler = logfire::configure() |
| 46 | +//! .install_panic_handler() |
| 47 | +//! # .send_to_logfire(logfire::config::SendToLogfire::IfTokenPresent) |
| 48 | +//! .finish()?; |
| 49 | +//! |
| 50 | +//! logfire::info!("Hello world"); |
| 51 | +//! |
| 52 | +//! shutdown_handler.shutdown()?; |
| 53 | +//! Ok(()) |
| 54 | +//! } |
56 | 55 | //! ```
|
57 | 56 | //!
|
58 | 57 | //! ## Configuration
|
59 | 58 | //!
|
60 | 59 | //! After adding basic setup as per above, the most two important environment variables are:
|
61 |
| -//! - `LOGFIRE_TOKEN` - (required) the token to send data to the Logfire platform |
62 |
| -//! - `RUST_LOG` - (optional) the level of verbosity to send to the Logfire platform. By default |
63 |
| -//! logs are captured at `TRACE` level so that all data is available for you to analyze in the |
64 |
| -//! Logfire platform. |
| 60 | +//! - [`LOGFIRE_TOKEN`](https://logfire.pydantic.dev/docs/how-to-guides/create-write-tokens/) (required) - the token to send data to the Logfire platform |
| 61 | +//! - [`RUST_LOG`](https://docs.rs/env_logger/latest/env_logger/#filtering-results) (optional) - the level of verbosity to send to the Logfire platform. By default |
| 62 | +//! data is captured at `TRACE` level so that all data is available for you to analyze in the |
| 63 | +//! Logfire platform. This format should match the format used by the [`env_logger`](https://docs.rs/env_logger/) crate. |
65 | 64 | //!
|
66 | 65 | //! All environment variables supported by the Rust Opentelemetry SDK are also supported by the
|
67 | 66 | //! Logfire SDK.
|
68 | 67 | //!
|
69 |
| -//! ## Integrations |
70 |
| -//! |
71 |
| -//! The following sections describe briefly the interaction which this SDK has with other libraries. |
72 |
| -//! |
73 |
| -//! ### With `tracing` |
74 |
| -//! |
75 |
| -//! This SDK is built upon `tracing` (and `tracing-opentelemtry`) for the [`span!`] macro. This means |
76 |
| -//! that any code instrumented with `tracing` will automatically be captured by Logfire, and also |
77 |
| -//! that [`span!`] produces a `tracing::Span` which is fully compatible with the `tracing` ecosystem. |
78 |
| -//! |
79 |
| -//! If you are an existing `tracing` user, it is fine to continue to use the `tracing` APIs directly |
80 |
| -//! and ignore [`logfire::span!`][span]. The upside of [`span!`] is that it will show the fields |
81 |
| -//! directly in the logfire UI. |
82 |
| -//! |
83 |
| -//! There are many great APIs in `tracing` which we do not yet provide equivalents for, such as the |
84 |
| -//! [`#[tracing::instrument]`][`macro@tracing::instrument`] proc macro, so even if using [`logfire::span!`][span] |
85 |
| -//! you will likely use `tracing` APIs directly too. |
| 68 | +//! # Examples |
86 | 69 | //!
|
87 |
| -//! ### With `opentelemetry` |
88 |
| -//! |
89 |
| -//! This SDK is built upon the `opentelemetry` Rust SDK and will configure the global `opentelemetry` |
90 |
| -//! state as part of a call to [`logfire::configure()`][configure]. |
91 |
| -//! |
92 |
| -//! All calls to [`logfire::info!`][info] and similar macros are directly forwarded to `opentelemetry` |
93 |
| -//! machinery without going through `tracing`, for performance. |
94 |
| -//! |
95 |
| -//! The metrics helpers exported by this SDK, such as [`logfire::u64_counter()`][u64_counter], are |
96 |
| -//! very thin wrappers around the `opentelemetry` SDK. |
97 |
| -//! |
98 |
| -//! ### With `log` |
99 |
| -//! |
100 |
| -//! This SDK configures the global `log` state to use an exporter which forwards logs to opentelemetry. |
101 |
| -//! |
102 |
| -//! All code instrumented with `log` will therefore automatically be captured by Logfire. |
| 70 | +//! See [examples][usage::examples] subchapter of this documentation. |
103 | 71 |
|
104 | 72 | use std::borrow::Cow;
|
105 | 73 | use std::cell::RefCell;
|
@@ -127,6 +95,9 @@ use crate::config::{
|
127 | 95 | };
|
128 | 96 | use crate::internal::exporters::console::{ConsoleWriter, SimpleConsoleSpanProcessor};
|
129 | 97 |
|
| 98 | +#[cfg(any(docsrs, doctest))] |
| 99 | +pub mod usage; |
| 100 | + |
130 | 101 | mod bridges;
|
131 | 102 | pub mod config;
|
132 | 103 | pub mod exporters;
|
|
0 commit comments