|
9 | 9 | //!
|
10 | 10 | //! ## Integrations
|
11 | 11 | //!
|
12 |
| -//! The following sections describe briefly the interaction which this SDK has with other libraries. |
| 12 | +//! This crate has integrations with the following libraries: |
13 | 13 | //!
|
14 | 14 | //! ### With `tracing`
|
15 | 15 | //!
|
|
42 | 42 | //!
|
43 | 43 | //! All code instrumented with `log` will therefore automatically be captured by Logfire.
|
44 | 44 | //!
|
| 45 | +//! # Dynamically adding data to spans |
| 46 | +//! |
| 47 | +//! Occasionally you may want to add data to a span after it has been created. |
| 48 | +//! |
| 49 | +//! This works the same way as with `tracing`, using the `record` method on the span. When creating |
| 50 | +//! the span, you need to initialize the attribute with [`tracing::field::Empty`]. |
| 51 | +//! |
| 52 | +//! ```rust |
| 53 | +//! // 1. create span with placeholder attribute |
| 54 | +//! let span = logfire::span!("My span", my_attr = tracing::field::Empty); |
| 55 | +//! |
| 56 | +//! // 2. record data later |
| 57 | +//! span.record("my_attr", "some value"); |
| 58 | +//! ``` |
| 59 | +//! |
| 60 | +//! # Using `logfire` as a layer in an existing `tracing` application |
| 61 | +//! |
| 62 | +//! If you have an existing application which already has a [`tracing_subscriber`] and you |
| 63 | +//! want to use `logfire` to quickly configure the OpenTelemetry SDK and send traces and logs to Logfire, the |
| 64 | +//! [`LogfireTracingLayer`][crate::LogfireTracingLayer] can be used to achieve this. |
| 65 | +//! |
| 66 | +//! First, configure `logfire` as usual, setting it as a `.local()` instance to avoid configuring |
| 67 | +//! global state: |
| 68 | +//! |
| 69 | +//! ```rust |
| 70 | +//! use tracing_subscriber::prelude::*; |
| 71 | +//! |
| 72 | +//! # fn main() -> Result<(), Box<dyn std::error::Error>> { |
| 73 | +//! // 1. configure logfire as usual, setting it as a `.local()` instance |
| 74 | +//! let shutdown_handler = logfire::configure() |
| 75 | +//! .local() |
| 76 | +//! .install_panic_handler() |
| 77 | +//! .finish()?; |
| 78 | +//! |
| 79 | +//! // 2. create a tracing subscriber |
| 80 | +//! let subscriber = tracing_subscriber::registry() |
| 81 | +//! .with(shutdown_handler.tracing_layer()); |
| 82 | +//! |
| 83 | +//! // 3. set the subscriber as the default (or otherwise set it up for your application) |
| 84 | +//! tracing::subscriber::set_global_default(subscriber)?; |
| 85 | +//! |
| 86 | +//! // 4. now tracing's spans and logs will be sent to Logfire |
| 87 | +//! tracing::info!("This will be sent to Logfire"); |
| 88 | +//! |
| 89 | +//! // 5. when finished, call shutdown_handler.shutdown() to flush and clean up |
| 90 | +//! shutdown_handler.shutdown()?; |
| 91 | +//! # Ok(()) |
| 92 | +//! # } |
| 93 | +//! ``` |
| 94 | +//! |
45 | 95 | //! # Examples
|
46 | 96 | //!
|
47 | 97 | //! See [examples] subchapter of this documentation.
|
|
0 commit comments