Skip to content

Commit 368621e

Browse files
committed
chore: update docs
1 parent 28b354b commit 368621e

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

opentelemetry-sdk/src/trace/span_processor.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,11 @@ pub trait SpanProcessor: Send + Sync + std::fmt::Debug {
8686
///
8787
/// # Accessing Context
8888
///
89-
/// If you need to access context information (such as baggage) in `on_end`,
90-
/// note that calling [`Context::current()`] will return the **parent context**,
91-
/// not the span's context (which has already been removed from the context stack).
89+
/// **Important**: Do not rely on [`Context::current()`] in `on_end`. When `on_end`
90+
/// is called during span cleanup, `Context::current()` returns whatever context
91+
/// happens to be active at that moment, which is typically unrelated to the span
92+
/// being ended. Contexts can be activated in any order and are not necessarily
93+
/// hierarchical.
9294
///
9395
/// **Best Practice**: Extract any needed context information in [`on_start`]
9496
/// and store it as span attributes. This ensures the information is available

opentelemetry/src/context.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,12 @@ impl Context {
119119
///
120120
/// When called from within a [`Drop`] implementation that is triggered by
121121
/// a [`ContextGuard`] being dropped (e.g., when a [`Span`] is dropped as part
122-
/// of context cleanup), this function returns the **parent context**, not the
123-
/// context being dropped.
122+
/// of context cleanup), this function returns **whatever context happens to be
123+
/// current after the guard is popped**, not the context being dropped.
124+
///
125+
/// **Important**: The returned context may be completely unrelated to the
126+
/// context being dropped, as contexts can be activated in any order and are
127+
/// not necessarily hierarchical. Do not rely on any relationship between them.
124128
///
125129
/// This behavior is by design and prevents panics that would otherwise occur
126130
/// from attempting to borrow the context while it's being mutably borrowed

0 commit comments

Comments
 (0)